What causes a “Connect Error to Native Application” when connecting to my own host application using connectNative () in the Chrome extension?

I am implementing a link between a webpage and a Mac application using the Chrome Native Messaging feature. Everything seems to be going fine until I make a javascript call on chrome.runtime.connectNative ("my_native_host_app_name"), which causes the following error in the console:

Error in event handler for runtime.onMessageExternal: Error connecting to native app: com.allinlearning.nmhforbrowserextension
Stack trace: Error: Error connecting to native app: com.allinlearning.nmhforbrowserextension
    at Object.<anonymous> (extensions::runtime:189:11)
    at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
    at Object.handleRequest (extensions::binding:55:27)
    at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
    at Object.<anonymous> (extensions::binding:318:32)
    at chrome-extension://gldheanjpgopipommeingjlnoiamdfol/background.js:19:27
    at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
    at EventImpl.dispatchToListener (extensions::event_bindings:395:22)
    at Function.target.(anonymous function) (extensions::SafeBuiltins:19:14)
    at Event.$Array.forEach.publicClass.(anonymous function) [as dispatchToListener] (extensions::utils:65:26) extensions::event_bindings:383
EventImpl.dispatch_extensions::event_bindings:383
EventImpl.dispatchextensions::event_bindings:401
$Array.forEach.publicClass.(anonymous function)extensions::utils:65
messageListenerextensions::messaging:190
EventImpl.dispatchToListenerextensions::event_bindings:395
$Array.forEach.publicClass.(anonymous function)extensions::utils:65
EventImpl.dispatch_extensions::event_bindings:378
EventImpl.dispatchextensions::event_bindings:401
$Array.forEach.publicClass.(anonymous function)extensions::utils:65
dispatchOnMessageextensions::messaging:304

The actual call that appears to be causing this error (line 19 in the link to background.js in the stack trace):

port = chrome.runtime.connectNative("com.nmhforbrowserextension");

To provide more context, it is called from a listener:

chrome.runtime.onMessageExternal.addListener(

  function(request, sender, sendResponse) {
    //var imgdata = JSON.stringify(request.imgdata);
    //process it somehow here

    port = chrome.runtime.connectNative("com.allinlearning.nmhforbrowserextension");

    if (port)
       console.log("connectNative() returned a non-null port");
    else
       console.log("connectNative() returned null for the port");
});

if. , , - Chrome Native Messaging. , . , " " .

( "manifest.json" ):

{
  "manifest_version": 2,

    "name": "AIL Extension",
    "version": "1.0",
    "description": "New Reader",

    "background": {
        "scripts": ["background.js"]
     },

    "externally_connectable": {
    // Extension and app IDs. If this field is not specified, no
    // extensions or apps can connect.
    "ids": [
      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
    ],
    // Match patterns for web pages. Does not affect content scripts.
    // If this field is not specified, no webpages can connect.
    "matches": [
      "http://localhost/charles/qrexttest/*"
    ],

     "permissions": [
                   "nativeMessaging",
                    "tabs",
                    "activeTab",
                    "background",
                    "http://*/", "https://*/"
                    ],

    // Indicates that the extension would like to make use of the TLS
    // channel ID of the web page connecting to it. The web page must
    // also opt to send the TLS channel ID to the extension via setting
    // includeTlsChannelId to true in runtime.connect connectInfo
    // or runtime.sendMessage options.
    "accepts_tls_channel_id": false
  }
}
+2
1

" : [ ]" - nativeMessaging.

Declare "nativeMessaging" , .

( , chrome.runtime.connectNative sendNativeMessage .) >

+1

All Articles