Skip to content

Allow different host executable file extension, not only .exe #13

Open

Description

@tansautn

I'm developing small extension with NHM. I used .bat file for NHM entry point.

Here is log from NMD:

18:12:56:7651 - I am [z2dlp_host.proxy.bat.exe:16772], launched by [cmd:20152].
18:12:56:7661 - GetStartupInfo() says dwFlags=0x0, excludes STARTF_USESTDHANDLES; stdin=0xffffffffffffffff; stdout=0xffffffffffffffff; stderr=0xffffffffffffffff.
18:12:56:7671 - GetStdHandle() says stdin=(0x8, FileTypePipe); stdout=(0xc, FileTypePipe); stderr=(0x0, FileTypeUnknownHandleInvalid).
18:12:56:7671 - extension: chrome-extension://pedcomindcpbnadoenfgnjandcieiani/
18:12:56:7671 - parent-window: 001213bc 
18:12:56:7671 - Listening for messages...
18:12:56:7981 - Checking for D:\Z-Data\git\qt-apps\yt-2dlp-ext\native_host\z2dlp_host.bat.exe...
18:12:56:7981 - Did not find any likely nativeHost for pedcomindcpbnadoenfgnjandcieiani. If you are using this tool as a mock,
the Injector tab allows sending messages to the browser.
18:12:56:7981 - GetStdHandle() says stdin=(0x8, FileTypePipe); stdout=(0xc, FileTypePipe); stderr=(0x0, FileTypeUnknownHandleInvalid).
18:12:56:8091 - {"action":"ping"}
18:13:06:2561 - Injecting message to extension '{"example_1": "to browser", "field_2": 2, "field_3":false}'
18:13:13:5834 - Got EOF while trying to read message size from (Extension); got only 0 bytes. Disconnecting.

Here is host manifest (proxied)

{
  "name": "z2dlp_host",
  "description": "z2dlp Native Messaging Host",
  "path": "D:\\Z-Data\\git\\qt-apps\\yt-2dlp-ext\\native_host\\z2dlp_host.proxy.bat.exe",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extension://pedcomindcpbnadoenfgnjandcieiani/",
    "chrome-extension://edcocgnlkdijkkiebalenphmfakmmoif/"
  ],
  "allowed_extensions": ["z2dlp_ext@zuko.pro"]
}

The real path of NHM is D:\\Z-Data\\git\\qt-apps\\yt-2dlp-ext\\native_host\\z2dlp_host.bat

I also tried "path": "D:\\Z-Data\\git\\qt-apps\\yt-2dlp-ext\\native_host\\z2dlp_host.bat.proxy.exe",

but chrome give

[296:15180:0115/182248.856:WARNING:launch_context.cc(195)] Found manifest, but not the binary for native messaging host z2dlp_host. Host path specified in the manifest: D:\Z-Data\git\qt-apps\yt-2dlp-ext\native_host\z2dlp_host.bat.proxy.exe
[296:17800:0115/182248.856:INFO:CONSOLE(554)] "Native host test error: Error: Specified native messaging host not found.", source: chrome-extension://pedcomindcpbnadoenfgnjandcieiani/options/options.js (554)

Then i rename NMD to z2dlp_host.bat.proxy.exe, doing test again. We back to Did not find any likely nativeHost for situation

Activity

  1. ericlaw1979 commented on Jan 15, 2025

    @ericlaw1979
    Owner

    Thanks for reporting!

    I used .bat file for NHM entry point.

    Fascinating. I'm a bit shocked that ever works, and it will not work with this extension, which I wrote with the expectation that it be used with a .exe backed native host. I'd love to see what your batch file looks like to understand how this scenario is implemented.

    There are definitely configurations where I wouldn't expect a batch file to work in the real-world (e.g. if the system has CMD disabled) even without the debugger.

  2. tansautn commented on Jan 16, 2025

    @tansautn
    Author

    Thank you, I just hope that more people can access this useful debugging tool.

    For me, compiling the host into a .exe file isn't too difficult or time-consuming. However, using a .bat launcher is a much more time- and effort-saving approach for me. That's why I chose to use it.
    And if I remember correctly, on MDN (Mozilla), their guide on NHM also uses a .bat file as the entry point.

    Below is my .bat script. It's simply a Python launcher—nothing mysterious here.

    @echo off
    setlocal DisableDelayedExpansion
    set "SCRIPT_PATH=%~f0"
    set "START_DIR=%~dp0"
    for %%I in ("%SCRIPT_PATH%") do set "PROJECT_DIR=%%~dpI..\"
    
    :: Check if .git exists in the parent directory
    if not exist "%PROJECT_DIR%.git" (
        echo This file is only for development purposes.
        echo It should not be used in production.
        pause
        exit /b 1
    )
    
    :: Check if the virtual environment exists
    if not exist "%PROJECT_DIR%venv\Scripts\activate.bat" (
        echo Virtual environment not found. Make sure it's named "venv".
        pause
        exit /b 1
    )
    
    :: Activate the virtual environment
    call "%PROJECT_DIR%venv\Scripts\activate.bat"
    timeout /t 2 /nobreak > nul
    
    :: Run the Python script
    python "z2dlp_host.py" %*
    exit /b
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions