Chrome 扩展支持
¥Chrome Extension Support
Electron 支持 Chrome 扩展 API 的一个子集,主要是为了支持 DevTools 扩展和 Chromium 内部扩展,但它也恰好支持一些其他扩展功能。
¥Electron supports a subset of the Chrome Extensions API, primarily to support DevTools extensions and Chromium-internal extensions, but it also happens to support some other extension capabilities.
注意:Electron 不支持商店中的任意 Chrome 扩展,并且与 Chrome 的扩展实现完美兼容并不是 Electron 项目的目标。
¥Note: Electron does not support arbitrary Chrome extensions from the store, and it is a non-goal of the Electron project to be perfectly compatible with Chrome's implementation of Extensions.
加载扩展
¥Loading extensions
Electron 仅支持加载未打包的扩展(即 .crx
文件不起作用)。扩展按 session
安装。要加载扩展,请调用 ses.loadExtension
:
¥Electron only supports loading unpacked extensions (i.e., .crx
files do not
work). Extensions are installed per-session
. To load an extension, call
ses.loadExtension
:
const { session } = require('electron')
session.defaultSession.loadExtension('path/to/unpacked/extension').then(({ id }) => {
// ...
})
加载的扩展不会在退出时自动记住;如果应用运行时不调用 loadExtension
,则不会加载扩展程序。
¥Loaded extensions will not be automatically remembered across exits; if you do
not call loadExtension
when the app runs, the extension will not be loaded.
请注意,仅在持久会话中支持加载扩展。尝试将扩展加载到内存会话中将引发错误。
¥Note that loading extensions is only supported in persistent sessions. Attempting to load an extension into an in-memory session will throw an error.
有关加载、卸载和查询活动扩展的更多信息,请参阅 session
文档。
¥See the session
documentation for more information about
loading, unloading, and querying active extensions.
支持的扩展 API
¥Supported Extensions APIs
我们支持以下扩展 API,但有一些注意事项。可能还会支持其他 API,但对此处未列出的任何 API 的支持是临时的,可能会被删除。
¥We support the following extensions APIs, with some caveats. Other APIs may additionally be supported, but support for any APIs not listed here is provisional and may be removed.
支持的清单键
¥Supported Manifest Keys
-
name
-
version
-
author
-
permissions
-
content_scripts
-
default_locale
-
devtools_page
-
short_name
-
host_permissions
(清单 V3)¥
host_permissions
(Manifest V3) -
manifest_version
-
background
(清单 V2)¥
background
(Manifest V2) -
minimum_chrome_version
有关每个可能的密钥的用途的更多信息,请参阅 清单文件格式。
¥See Manifest file format for more information about the purpose of each possible key.
chrome.devtools.inspectedWindow
支持此 API 的所有功能。
¥All features of this API are supported.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.devtools.network
支持此 API 的所有功能。
¥All features of this API are supported.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.devtools.panels
支持此 API 的所有功能。
¥All features of this API are supported.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.extension
支持 chrome.extension
的以下属性:
¥The following properties of chrome.extension
are supported:
chrome.extension.lastError
chrome.extension
支持以下方法:
¥The following methods of chrome.extension
are supported:
-
chrome.extension.getURL
-
chrome.extension.getBackgroundPage
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.management
chrome.management
支持以下方法:
¥The following methods of chrome.management
are supported:
-
chrome.management.getAll
-
chrome.management.get
-
chrome.management.getSelf
-
chrome.management.getPermissionWarningsById
-
chrome.management.getPermissionWarningsByManifest
支持 chrome.management
的以下事件:
¥The following events of chrome.management
are supported:
-
chrome.management.onEnabled
-
chrome.management.onDisabled
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.runtime
支持 chrome.runtime
的以下属性:
¥The following properties of chrome.runtime
are supported:
-
chrome.runtime.lastError
-
chrome.runtime.id
chrome.runtime
支持以下方法:
¥The following methods of chrome.runtime
are supported:
-
chrome.runtime.getBackgroundPage
-
chrome.runtime.getManifest
-
chrome.runtime.getPlatformInfo
-
chrome.runtime.getURL
-
chrome.runtime.connect
-
chrome.runtime.sendMessage
-
chrome.runtime.reload
支持 chrome.runtime
的以下事件:
¥The following events of chrome.runtime
are supported:
-
chrome.runtime.onStartup
-
chrome.runtime.onInstalled
-
chrome.runtime.onSuspend
-
chrome.runtime.onSuspendCanceled
-
chrome.runtime.onConnect
-
chrome.runtime.onMessage
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.scripting
支持此 API 的所有功能。
¥All features of this API are supported.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.storage
chrome.storage
支持以下方法:
¥The following methods of chrome.storage
are supported:
chrome.storage.local
不支持 chrome.storage.sync
和 chrome.storage.managed
。
¥chrome.storage.sync
and chrome.storage.managed
are not supported.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.tabs
chrome.tabs
支持以下方法:
¥The following methods of chrome.tabs
are supported:
-
chrome.tabs.sendMessage
-
chrome.tabs.reload
-
chrome.tabs.executeScript
-
chrome.tabs.query
(部分支持)¥
chrome.tabs.query
(partial support)-
支持的属性:
url
、title
、audible
、active
、muted
。¥supported properties:
url
,title
,audible
,active
,muted
.
-
-
chrome.tabs.update
(部分支持)¥
chrome.tabs.update
(partial support)-
支持的属性:
url
、muted
。¥supported properties:
url
,muted
.
-
注意:在 Chrome 中,传递
-1
作为选项卡 ID 表示 "当前活动选项卡"。由于 Electron 没有这样的概念,因此不支持传递-1
作为选项卡 ID,并且会引发错误。¥Note: In Chrome, passing
-1
as a tab ID signifies the "currently active tab". Since Electron has no such concept, passing-1
as a tab ID is not supported and will raise an error.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.
chrome.webRequest
支持此 API 的所有功能。
¥All features of this API are supported.
注意:如果存在冲突的处理程序,Electron 的
webRequest
模块优先于chrome.webRequest
。¥NOTE: Electron's
webRequest
module takes precedence overchrome.webRequest
if there are conflicting handlers.
请参阅 官方文档 了解更多信息。
¥See official documentation for more information.