externally_connectable

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

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

不使用 external_connectable 連線

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

manifest.json 範例

{
  "name": "My externally connectable extension",
  "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/*http://*.chromium.org/* 有效,但 <all_urls>http://*/* *://*.com/*,甚至 http://*.appspot.com/* 都不是。

  • accepts_tls_channel_id (布林值) - 選用

    如果為 true,系統會設定透過 runtime.connectruntime.sendMessage 傳送的訊息 runtime.MessageSender.tlsChannelId。如果是 false, 在任何情況下,系統都不會設定 runtime.MessageSender.tlsChannelId