I'm working on a Firefox extension with a Node.js script as a native messaging host. Messages sent to the extension from the script are recieved as expected, but every method I have tried to listen for messages from the extension have failed.
I have tried using stdin:
process.stdin.on('readable', function() {
let message = JSON.stringify("hello");
sendMessage(`{"test": "${message}"}`);
});
This works fine if I run the script from the command line but it will never pick up messages sent from the extension itself.
I have also tried the npm native-messaging host protocol, based closely on the example:
var sendMessage = require('native-messaging')(handleMessage)
function handleMessage (req) {
fs.writeFile('test.txt', req.message, err => {
if (err) {
console.error(err);
}
// file written successfully
});
sendMessage({message: "pong", body: 'hello from nodejs app'});
}
This also yields no result.
I have tested both methods and neither of these functions seem to ever be called, no matter how many times I send a message from the extension, and no errors are thrown.
I don't believe this is a problem with the manifest or the registry keys, because messaging seems to work fine one way.
Why are my messages not being received by the script?