Firefox Native Messaging runtime.LastError not giving any errors in case of no Native application installed on Connectnative

Hi,

I am trying to check the whether the Native app is installed or not , If it is not I have to prompt the user to download it from the webpage. For chrome this I used to achieve by checking the error messages from runtime.LastError. However in case of Firefox it gives error only in console No such native application extension_name and not in the runtime.LastError.

Is there any way that we can identify whether corresponding Native app is installed or not ?
we are facing issue when Native app is not installed and browser.runtime.lastError is not giving any error.

Can you please suggest if there is any way in Firefox Webextension that we can catch such errors and identify it in code whether the corresponding Native app is installed or not on the user machine.

It will really helpful if someone can provide some info on this.

For e.g :

startNativeApp: function(force){
		// note that when the native app is opened and ready, it will call "_ABC_onAgentReady"
		ABC.log('Starting native app.');
		if (!ABC.appConnected) {
			try {
				ABC.nativeAppPort = browser.runtime.connectNative(_ABC_native_app_id);
				ABC.nativeAppPort.onMessage.addListener(ABC.onNativeMessageReceived);
				ABC.nativeAppPort.onDisconnect.addListener(ABC.onNativeAppDisconnected);
				ABC.appInstalled = true;
				ABC.appConnected = true;
			} catch(e) {
				ABC.log('Error starting native app: ' + e.message, 'ERR');
			}
		} else if (force === true) {
			ABC.log('Native app is already running; attempting to stop and will restart in 750ms.');
			ABC.stopNativeApp();
			setTimeout(function() { ABC.startNativeApp(true); }, 750);
		}
},


onNativeAppDisconnected: function(message) {
		console.log("ABC LastError : "+browser.runtime.lastError);
		console.log("ABC LastError : "+ABC.nativeAppPort.error);
		console.log("ABC LastError : "+JSON.stringify(message));
		ABC.appConnected = false;
		ABC.nativeAppPort = null;
		ABC.appInstalled = false;
		if (browser.runtime.lastError && (browser.runtime.lastError.message.indexOf("No such native application") !== -1 )) {
			ABC.appInstalled = false;
		}
		// cleanup: reset the sig data so that it is re-requested on the next scan
		_ABC_sa_data = "";
		_ABC_sigs = "";
		if (browser.storage && browser.storage.local) {
			browser.storage.local.set({ uid: _ABC_be_uid }, null);
		}

		ABC.log('Send message to page to stop.');
		ABC.sendMessageToPage({ onNativeAppDisconnected: '' });
		ABC.log('Native app disconnected.');
	},

@jorgev , @noitidart : Can you please suggest on this ? Is there any way by which I can get the same error messages using browser.runtime.lastError or some other methods which we get in webconsole .

1 Like

When doing nativeConnect you can try this:

function failedConnect(reason) {
	console.error('failed to connect port to native!, error:', reason.error);
}

let port = chrome.runtime.connectNative(aAppName);
port.onDisconnect.removeListener(failedConnect);

The reason has a error getter property.

If the reason is “This extension does not have permission to use native application trigger (or the application is not installed)” then it’s probably there. I’m guessing. I only see that error if it’s installed and connecting fails. Might not be the case, I didn’t dig into it.

If you post this in the development forum others can reply. :slight_smile:

Thanks @noitidart for responding :slight_smile:

No still no luck , onDisconnect , it comes to the listeners , However the port argument message in onNativeAppDisconnected method doesn’t contain any error :frowning:

If I print the message as it is it gives following info :
{“name”:“com.abc.firefox”,“onDisconnect”:{},“onMessage”:{}}
But no error message.

However in console I can see the error message : No such native application com.abc.firefox

I have already asked it in forum , but didn’t got any response , I was checking for the answers on stackoverflow and found your answer for one question .
So thought to ask you , If you can help on this as I am not getting anything helpful related to this.

I suggest you file a bug report with a minimal testcase demonstrating the problem.

Yes it seems Google Chrome gives us a error response that tells us it’s not installed. I think the webext team missed that. Only solution here is to file a bug to fix it to work like the Chrome API. :frowning:

I’ve exactly the same problem. Does the error report already created? Or any other solution found?

Yes, Error was already reported earlier : https://bugzilla.mozilla.org/show_bug.cgi?id=1299411
And it will be resolved in Firefox 52.

I have tested it in Firefox 52 Developer edition and it is working fine.

However , I have to support Firefox 50 also , so the alternate I am using is to call native application in starting to find out whether it is installed or not.

If I got back response than it is installed otherwise it is not.
However specific error messages will be available from Firefox52.