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 扩展,并且 Electron 项目的非目标是与 Chrome 的扩展实现完全兼容。
加载扩展
🌐 Loading extensions
Electron 仅支持加载未打包的扩展(即,.crx 文件不适用)。扩展是按每个 session 安装的。要加载扩展,请调用 ses.extensions.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.extensions.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
nameversionauthorpermissionscontent_scriptsdefault_localedevtools_pageshort_namehost_permissions(清单 V3)manifest_versionbackground(清单 V2)minimum_chrome_version
有关每个可能键的用途的更多信息,请参见 Manifest 文件格式。
🌐 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.getURLchrome.extension.getBackgroundPage
有关更多信息,请参见官方文档。
🌐 See official documentation for more information.
chrome.management
支持以下 chrome.management 方法:
🌐 The following methods of chrome.management are supported:
chrome.management.getAllchrome.management.getchrome.management.getSelfchrome.management.getPermissionWarningsByIdchrome.management.getPermissionWarningsByManifest
支持以下 chrome.management 事件:
🌐 The following events of chrome.management are supported:
chrome.management.onEnabledchrome.management.onDisabled
有关更多信息,请参见官方文档。
🌐 See official documentation for more information.
chrome.runtime
支持以下 chrome.runtime 属性:
🌐 The following properties of chrome.runtime are supported:
chrome.runtime.lastErrorchrome.runtime.id
支持以下 chrome.runtime 方法:
🌐 The following methods of chrome.runtime are supported:
chrome.runtime.getBackgroundPagechrome.runtime.getManifestchrome.runtime.getPlatformInfochrome.runtime.getURLchrome.runtime.connectchrome.runtime.sendMessagechrome.runtime.reload
支持以下 chrome.runtime 事件:
🌐 The following events of chrome.runtime are supported:
chrome.runtime.onStartupchrome.runtime.onInstalledchrome.runtime.onSuspendchrome.runtime.onSuspendCanceledchrome.runtime.onConnectchrome.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 不受支持。
有关更多信息,请参见官方文档。
🌐 See official documentation for more information.
chrome.tabs
支持以下 chrome.tabs 方法:
🌐 The following methods of chrome.tabs are supported:
chrome.tabs.sendMessagechrome.tabs.reloadchrome.tabs.executeScriptchrome.tabs.query(部分支持)- 支持的属性:
url、title、audible、active、muted。
- 支持的属性:
chrome.tabs.update(部分支持)- 支持的属性:
url、muted。
- 支持的属性:
在 Chrome 中,将 -1 作为标签页 ID 传递表示“当前活动标签页”。由于 Electron 没有这样的概念,传递 -1 作为标签页 ID 是不支持的,并且会引发错误。
有关更多信息,请参见官方文档。
🌐 See official documentation for more information.
chrome.webRequest
支持此 API 的所有功能。
🌐 All features of this API are supported.
如果存在冲突的处理程序,Electron 的 webRequest 模块优先于 chrome.webRequest。
有关更多信息,请参见官方文档。
🌐 See official documentation for more information.