externally_connectable

externally_connectable 資訊清單屬性會宣告哪些擴充功能、應用程式和網頁可透過 runtime.connectruntime.sendMessage 連結至您的應用程式。

如需訊息傳遞的教學課程,請參閱跨擴充功能和應用程式訊息從網頁傳送訊息

在沒有 external_connectable 的情況下連線

如果未在應用程式資訊清單中宣告 externally_connectable,所有擴充功能和應用程式皆可連線,但無法連結網頁。因此,在更新資訊清單以使用 externally_connectable 時,如未指定 "ids": ["*"],其他擴充功能和應用程式就無法連結至您的應用程式。這可能是非預期的後果,因此請注意。

manifest.json 範例

{
  "name": "My externally connectable app",
  "externally_connectable": {
    // Extension and app IDs. If this field is not specified, no
    // extensions or apps can connect.
    "ids": [
      "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
      "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
      ...
      // Alternatively, to match all extensions and apps, specify only
      // "*".
      "*"
    ],
    // Match patterns for web pages. Does not affect content scripts.
    // If this field is not specified, no webpages can connect.
    "matches": [
      "https://*.google.com/*",
      "*://*.chromium.org/*",
      ...
    ],
    // 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
  },
  ...
}

參考資料

external_connectable 資訊清單金鑰可包含下列屬性:

  • ids (字串陣列) - 選用

    允許連結的擴充功能或應用程式的 ID。如果留空或未指定,則任何擴充功能或應用程式都無法連線。

    "*" 萬用字元會允許所有擴充功能和應用程式連線。

  • matches (字串陣列) - 選用

    允許連線的網頁網址模式。這不會影響內容指令碼。如果留空或未指定,表示沒有網頁可供連線。

    模式不得包含萬用字元網域或 (有效) 頂層網域的子網域;*://google.com/*https://*.chromium.org/* 有效,但 <all_urls>https://*/**://*.com/*,甚至是 https://*.appspot.com/* 都無效。

  • accepts_tls_channel_id (布林值) - 選用

    如果為 true,透過 runtime.connectruntime.sendMessage 傳送的訊息會設為 runtime.MessageSender.tlsChannelId (如果這些方法要求傳送訊息)。如果為 false,則在任何情況下,系統一律不會設定 runtime.MessageSender.tlsChannelId