Firefox Native Messaging runtime.LastError 在 Connectnative 上未安装本机应用程序的情况下不会出现任何错误
Firefox Native Messaging runtime.LastError not giving any errors in case of no Native application installed on Connectnative
我正在尝试检查是否安装了本机应用程序,如果没有,我必须提示用户从网页下载它。对于 chrome 我曾经通过检查来自 runtime.LastError 的错误消息来实现。但是,对于 Firefox,它仅在控制台 No such native application extension_name 中给出错误,并且没有在 runtime.LastError 方法中捕获它。
有什么方法可以判断是否安装了相应的Native app?
当未安装本机应用程序并且 browser.runtime.lastError 没有给出任何错误时,我遇到了问题。
能否请您建议在 Firefox Webextension 中是否有任何方法可以捕获此类错误并在代码中识别用户计算机上是否安装了相应的本机应用程序。
如果有人能提供一些这方面的信息,那将非常有帮助。
例如:
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.');
},
在 Firefox 中没有 runtime.lastError
。
您传递给 runtime.Port.onDisconnect
的侦听器函数没有传递消息,它传递了端口本身。
然后你想要port.error
.
请在此处查看有关 onDisconnect 的文档 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/Port
这里的问题是 port.error 在低于 52 的 Firefox 版本中没有给出任何错误响应,因此我在识别是否安装了本机应用程序时遇到了问题。
经过 Mozilla 社区的讨论 (https://discourse.mozilla-community.org/t/firefox-native-messaging-runtime-lasterror-not-giving-any-errors-in-case-of-no-native-application-installed-on-connectnative/12880/4) , we found that it is actually missed and a bug is already reported : https://bugzilla.mozilla.org/show_bug.cgi?id=12994116
这将在 Firefox 52 中得到解决。
但是,我还需要支持 Firefox 50,所以我使用的替代方法是在启动时调用本机应用程序以查看它是否已安装。
如果我收到回复而不是安装,否则不是。
但是,Firefox52 将提供特定的错误消息。
我正在尝试检查是否安装了本机应用程序,如果没有,我必须提示用户从网页下载它。对于 chrome 我曾经通过检查来自 runtime.LastError 的错误消息来实现。但是,对于 Firefox,它仅在控制台 No such native application extension_name 中给出错误,并且没有在 runtime.LastError 方法中捕获它。
有什么方法可以判断是否安装了相应的Native app? 当未安装本机应用程序并且 browser.runtime.lastError 没有给出任何错误时,我遇到了问题。
能否请您建议在 Firefox Webextension 中是否有任何方法可以捕获此类错误并在代码中识别用户计算机上是否安装了相应的本机应用程序。
如果有人能提供一些这方面的信息,那将非常有帮助。
例如:
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.');
},
在 Firefox 中没有 runtime.lastError
。
您传递给 runtime.Port.onDisconnect
的侦听器函数没有传递消息,它传递了端口本身。
然后你想要port.error
.
请在此处查看有关 onDisconnect 的文档 https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/runtime/Port
这里的问题是 port.error 在低于 52 的 Firefox 版本中没有给出任何错误响应,因此我在识别是否安装了本机应用程序时遇到了问题。
经过 Mozilla 社区的讨论 (https://discourse.mozilla-community.org/t/firefox-native-messaging-runtime-lasterror-not-giving-any-errors-in-case-of-no-native-application-installed-on-connectnative/12880/4) , we found that it is actually missed and a bug is already reported : https://bugzilla.mozilla.org/show_bug.cgi?id=12994116 这将在 Firefox 52 中得到解决。
但是,我还需要支持 Firefox 50,所以我使用的替代方法是在启动时调用本机应用程序以查看它是否已安装。
如果我收到回复而不是安装,否则不是。 但是,Firefox52 将提供特定的错误消息。