Chrome 扩展支持
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.
[!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.
加载扩展
Electron 只支持加载未打包的扩展 (即不能使用 .crx 文件)。 插件会被安装到每一个会话。 To load an extension, call ses.extensions.loadExtension:
const { session } = require('electron')
session.defaultSession.loadExtension('path/to/unpacked/extension').then(({ id }) => {
// ...
})
加载的扩展将不会被自动记住;如果在应用程序运行时未调用 loadExtension,则不会加载扩展。
注意,仅能在持久 session 中加载扩展。 尝试将扩展加载到内存 session 中会出现错误。
有关加载、卸载和查询活动扩展的更多信息,请查阅 session 文档。
支持的扩展 API
我们支持以下扩展 API,并需要注意一些警告。 其他API可能会得到额外支持,但对此处未列出的任何API的支持都是临时的,可能会被删除。
Supported Manifest Keys
nameversionauthor权限content_scriptsdefault_localedevtools_pageshort_namehost_permissions(Manifest V3)manifest_versionbackground(Manifest V2)minimum_chrome_version
See Manifest file format for more information about the purpose of each possible key.
chrome.devtools.inspectedWindow
支持这些 API 的所有功能。
See official documentation for more information.
chrome.devtools.network
支持这些 API 的所有功能。
See official documentation for more information.
chrome.devtools.panels
支持这些 API 的所有功能。
See official documentation for more information.
chrome.extension
支持 chrome.extension 的以下属性:
chrome.extension.lastError
支持 chrome.extension 的以下方法:
chrome.extension.getURLchrome.extension.getBackgroundPage
See official documentation for more information.
chrome.management
支持 chrome.management 的以下方法:
chrome.management.getAllchrome.management.getchrome.management.getSelfchrome.management.getPermissionWarningsByIdchrome.management.getPermissionWarningsByManifest
支持 chrome.management 的以下事件:
chrome.management.onEnabledchrome.management.onDisabled
See official documentation for more information.
chrome.runtime
支持 chrome.runtime 的以下属性:
chrome.runtime.lastErrorchrome.runtime.id
支持 chrome.runtime 的以下方法:
chrome.runtime.getBackgroundPagechrome.runtime.getManifestchrome.runtime.getPlatformInfochrome.runtime.getURLchrome.runtime.connectchrome.runtime.sendMessagechrome.runtime.reload
支持 chrome.runtime 的以下事件:
chrome.runtime.onStartupchrome.runtime.onInstalledchrome.runtime.onSuspendchrome.runtime.onSuspendCanceledchrome.runtime.onConnectchrome.runtime.onMessage
See official documentation for more information.
chrome.scripting
支持这些 API 的所有功能。
See official documentation for more information.
chrome.storage
支持 chrome.storage 的以下方法:
chrome.storage.local
chrome.storage.sync and chrome.storage.managed are not supported.
See official documentation for more information.
chrome.tabs
支持 chrome.tab 的以下方法:
chrome.tabs.sendMessagechrome.tabs.reloadchrome.tabs.executeScriptchrome.tabs.query(部分支持)- supported properties:
url,title,audible,active,muted.
- supported properties:
chrome.tabs.update(部分支持)- 支持的属性:
url,muted。
- 支持的属性:
[!NOTE] In Chrome, passing
-1as a tab ID signifies the "currently active tab". 因为 Electron 没有这样的概念,通过-1作为选项卡ID不支持而且会报错。
See official documentation for more information.
chrome.webRequest
支持这些 API 的所有功能。
[!NOTE] Electron's
webRequestmodule takes precedence overchrome.webRequestif there are conflicting handlers.
See official documentation for more information.