3

Chrome のネイティブ メッセージング機能を使用して、Web ページと Mac アプリケーション間の通信を実装しています。chrome.runtime.connectNative("my_native_host_app_name") への JavaScript 呼び出しを行うまで、すべてがうまくいくように見えます。これにより、コンソールに次のエラーが生成されます。

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

このエラーの原因と思われる実際の呼び出し (スタック トレースの background.js への参照の 19 行目) は次のとおりです。

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

より多くのコンテキストを提供するために、リスナーから呼び出されます。

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's connectInfo
    // or runtime.sendMessage's options.
    "accepts_tls_channel_id": false
  }
}
4

1 に答える 1

2

「ネイティブ アプリへの接続エラー: [ネイティブ メッセージング ホスト ID]」の考えられる原因の 1 つは、必要なnativeMessagingアクセス許可がないことです。

マニフェスト ファイルでアクセス許可を宣言"nativeMessaging"、拡張機能を再読み込みして、もう一度お試しください。

(この許可なしでchrome.runtime.connectNativeとが利用できるという事実はバグです。)sendNativeMessage

于 2014-12-31T12:25:40.977 に答える