I have a Chrome extension communicating with my Windows application by Native Messaging. However there is case that user installs extension, but doesn't have application installed. In this case there is a runtime error (Unchecked runtime.lastError: Specified native messaging host not found.) appeared in my extension in chrome://extensions list when extension calls chrome.runtime.connectNative(). Is there any way to avoid this error message?
Asked
Active
Viewed 113 times
0
-
It doesn't exist. – Norio Yamamoto Jan 26 '23 at 10:11
-
1As the error message says you need to check chrome.runtime.lastError in the callback of connectNative. – wOxxOm Jan 26 '23 at 10:33
-
but according to https://developer.chrome.com/docs/extensions/reference/runtime/#method-connectNative, it does not have a callback – SantK Jan 26 '23 at 14:04
-
2@SantK - You are correct, chrome.runtime.connectNative doesn't have a callback. But it always returns a Port object, even if there's an error. And you can attach callbacks to the port's onDisconnect and onMessage events. An error during connection causes an onDisconnect event. – Thomas Mueller Jan 26 '23 at 15:18
-
Example: [How do I find out if connectNative failed or succeeded](https://stackoverflow.com/a/43321860) – wOxxOm Jan 26 '23 at 20:57