I've read almost everything I could find about the topic "Native Messaging" from a Firefox AddOn together with a NodeJS application on Windows.
Bottom line: I couldn't get it to work
I've setup the following (and also checked it again a minute ago)
- The Firefox AddOn has a custom extension ID and the necessary permission in its manifest
"permissions": [
"nativeMessaging"
],
"browser_specific_settings": {
"gecko": {
"id": "[email protected]",
"strict_min_version": "50.0"
}
}
- The manifest file for the Native Messaging Host I want to create with NodeJS has the following entries
{
"name": "org.theiner.vlcconvert",
"description": "Convert m3u8 into mp4",
"path": "D:\\Project Folders\\NodeProjects\\NativeMessagingHost\\index.js",
"type": "stdio",
"allowed_extensions": ["[email protected]"]
}
- it is called
org.theiner.vlcconvert.json - I've made sure that
.jsfiles are associated with nodejs, so that starting (or doubleclicking) a.jsfile will start node together with this file - I've set the default value of both desired registry keys
HKCU\SOFTWARE\Mozilla\NativeMessagingHosts\org.theiner.vlcconvert
HKLM\SOFTWARE\Mozilla\NativeMessagingHosts\org.theiner.vlcconvert
to point to the full path of the Native Messaging Hosts manifest file
D:\Project Folders\NodeProjects\NativeMessagingHost\org.theiner.vlcconvert.json
- The Firefox AddOn uses
let port = browser.runtime.connectNative("org.theiner.vlcconvert");to connect to the host, which seems to be successful, because the port is open (and no error or disconnection appears) - The Firefox AddOn later uses
port.postMessage('{"message": "This is a message"}');to post a message to the host - The NodeJS host uses
process.stdin.on("data", (chunk) => {...})to receive messages on stdin and in the end create a file in its path which contains the message data - I've installed the Firefox AddOn in
about:debugging
But: The file is never created, even though I see no errors anywhere. Running the NodeJS app with start index.js works perfectly and writes the stdin input to the file
Did I miss something?
EDIT: I tried using CHROME.EXE from the native messaging host manifest, and it worked. But I want to use a NodeJS app, if possible.
EDIT2: When I use this path in the app's manifest as suggested by another blog article
"path": "C:\\Program Files\\nodejs\\node.exe D:\\Project Folders\\NodeProjects\\NativeMessagingHost\\index.js",
the port immediately disconnects with this error:
Error: An unexpected error occurred
EDIT3: When I use yet another suggestion:
"path": "C:\\Program Files\\nodejs\\node.exe",
"args": [" D:\\Project Folders\\NodeProjects\\NativeMessagingHost\\index.js"],
it fails with
Error: No such native application org.theiner.vlcconvert