Native messaging doesn't work with popups

Hello.

I’m trying to build a firefox extension that displays a popup when you click the button on the toolbar and also runs a batch script (that subsequently runs a python script) on my local machine using native messaging.

I was able to get native messaging to work on the click of the button (without the popup). However, once the popup is set, the popup runs but native messaging fails to work i.e. the batch script does not execute. This is for both connection based and connection-less messaging.

Here’s what I’ve tried and the results: note that in all cases, the popup is opened in the click listener for the toolbar button

Setting popup in manifest.json: in this case, batch script doesn’t execute at all.
Setting popup in the listener for the toolbar button: batch script runs once, native messasging fails on subsequent runs in connection based messaging; batch script fails to execute on connection-less messaging. Basically, native messaging executes once.
Setting popup on window onload listener: batch script doesn’t execute at all.

Native messaging is executed through a background.js file that is set as background script in manifest.json. Popup is also set in this file if not set in manifest.json.

I’ve tried calling the functions like this;

browser.runtime.sendNativeMessage();

and like this;

browser.extension.getBackgroundPage().browser.runtime.connectNative();

Wasn’t able to find a solution on google either. Would really appreciate assistance on this.

I’m not quite clear what exactly your setup is. Are you trying to do native messaging directly from the popup or do you use internal messaging from the popup to the background page and then send it to native messaging?

I’ve only done the second version myself, so not experienced with trying to do native messaging in a popup directly.

At the moment, the background.js file detects the click of the toolbar button and in response, opens the popup and runs the native messaging code.

It doesn’t matter how it works, I just need a popup to show and a python script on my local machine to run on the click of a toolbar button. Not able to get this to happen.

I hope that removes some ambiguity.