externally_connectable
清单属性声明了哪些扩展程序、应用和网页可以通过 runtime.connect 和 runtime.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.connect 或 runtime.sendMessage 发送的消息将设置 runtime.MessageSender.tlsChannelId(如果这些方法请求)。如果为false
,则在任何情况下都永远不会设置 runtime.MessageSender.tlsChannelId。