Firefox prevents the native application from running

My native messaging add-on is a component of a shareware program, the add-on’s native application (a Windows console program) is wrapped/protected by a software protector that is ofen used by shareware developers.

When I run the Firefox->about:debugging->Load Temporary Add-on…, load the manifest file to use the local version of the add-on, the native application works as expected.

Now the add-on has been published on Mozillar add-on, I download and install the public released add-on from Mozillar, and the same native application can not be started by Firefox, here is the error message showed in the debugging console window:

Unchecked lastError value: Error: port is null

Using the local version add-on, and the native application works as expected, but using the public released add-on, it looks like the firefox prevents the native application from running, the port is null.

The firefox version is 94.0.2 64 bit, the Windows 10 version is 2004. Is it because firefox does not work compatibly with native application that is wrapped/protected using a software protector?

Thanks for help!

Here is the example code snippet in the background page:

function connectToNativeHost()
{
var nativeHostName = “com.some-company.test”;
port = chrome.runtime.connectNative(nativeHostName);
console.log(port)

port.onMessage.addListener(onNativeMessage);  
port.onDisconnect.addListener(onDisconnected);  

}

function onDisconnected()
{
console.log(chrome.runtime.lastError);
console.log(‘disconnected from native app.’);
port = null;
}

Sounds like your code is trying to access port after onDisconnected is called.

Is the native app registered for the signed version of the extension?

Thank you for your message!

I read the Mozillar documents again, there is no information about registering a native app for the signed add-on.

If you means registry key for firefox to find the native app, the registry keys have been set correctly under
HKEY_CURRENT_USER\Software\Mozilla\NativeMessagingHosts
HKEY_LOCAL_MACHINE\Software\Mozilla\NativeMessagingHosts\

When I load the local version add-on ( Firefox->about:debugging->Load Temporary Add-on… ), the native app works as expected. But switch to using the public released add-on, the same native app failed to run.

I mostly meant making sure that you’re registering for the correct ID, in case that changed after signing. Either way, you’ll most likely want to look at the errors or debug your code:

Thank you Martin Giger for the clarification!

I checked again, the extension IDs for the local add-on and the public released( signed) add-on are same, it is also same as the one in the native app’s manifest file field “allowed_extensions”.

I guess maybe Firefox works in developer mode when I load the local version via Firefox->about:debugging->Load Temporary Add-on… , the developer mode allow the native app to run. But when firefox works in normal mode with public released add-on installed, it blocks the native app which was protected/wrapped by a software protector.

I test on two Windows 10 computers, both show following failures.

The signed public released add-on only works one time just after downloading it from Mozilla and installing it on firefox, the add-on and existing native app (installed before the signed add-on installation) can run as expected, and it looks like all is OK, during this period, the firefox does not restart.

However when I restart firefox, the add-on fails to work, i.e., the native app can not run, it starts then ends. the console windows shows “port is null”.

This firefox behavior is really strange, maybe it blocks the native app?

Thank you for your help!

Are you maybe using some events that only happen on install, like onInstalled?

I read the Firefox add-ons blocking procss at: https://extensionworkshop.com/documentation/publish/add-ons-blocking-process/
Maybe Firefox has blocked the native app.

Is it possible to submit this topic to Firefox developer team? They should know the reasons for this error.

In a short, this question should be:

The Windows console program ( native messaging host ) failed to start when signed add-on is installed on Firefox.

Thanks!

I found what caused the problem.

There is a extension-related data iStartNativeApp, this data is removed in
chrome.runtime.onInstalled.addListener(function () {
chrome.storage.local.remove(“iStartNativeApp”);
});

It should also be removed when Firefox restarts, I forgot the onStartup event.
Now when I add following code snippet, the error disappears.
chrome.runtime.onStartup.addListener(function () {
chrome.storage.local.remove(“iStartNativeApp”);

});

When Firefox restarts, it detects that the iStartNativeApp is undefined, it starts the native app, and set value for the data: chrome.storage.local.set({“iStartNativeApp”: “1”}

Otherwise, it will not start the native app, that’s the reason of the problem.

2 Likes