Skip to main content

Chrome Extension Support

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扩展API的一个子集,主要是为了支持DevTools扩展和Chromium内部扩展,但它也恰好支持一些其他扩展功能。

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不支持来自商店的任意Chrome扩展,并且Electron项目的目标不是与Chrome的扩展实现完全兼容。

Loading extensions正在加载扩展

Electron only supports loading unpacked extensions (i.e., .crx files do not work). Electron只支持加载未打包的扩展名(即.crx文件不起作用)。Extensions are installed per-session. 每个session都安装扩展。To load an extension, call ses.loadExtension:要加载扩展,请调用ses.loadExtension

const { session } = require('electron')

session.loadExtension('path/to/unpacked/extension').then(({ id }) => {
// ...
})

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.加载的扩展不会在出口之间自动记忆;如果在应用程序运行时不调用loadExtension,则不会加载该扩展。

Note that loading extensions is only supported in persistent sessions. 请注意,只有在持久会话中才支持加载扩展。Attempting to load an extension into an in-memory session will throw an error.试图将扩展加载到内存中的会话将引发错误。

See the session documentation for more information about loading, unloading, and querying active extensions.有关加载、卸载和查询活动扩展的更多信息,请参阅session文档。

Supported Extensions APIs支持的扩展API

We support the following extensions APIs, with some caveats. 我们支持以下扩展API,但有一些注意事项。Other APIs may additionally be supported, but support for any APIs not listed here is provisional and may be removed.可能会额外支持其他API,但对此处未列出的任何API的支持都是临时的,可能会被删除。

chrome.devtools.inspectedWindow

All features of this API are supported.支持此API的所有功能。

chrome.devtools.network

All features of this API are supported.支持此API的所有功能。

chrome.devtools.panels

All features of this API are supported.支持此API的所有功能。

chrome.extension

The following properties of chrome.extension are supported:支持chrome.extension的以下属性:

  • chrome.extension.lastError

The following methods of chrome.extension are supported:支持以下chrome.extension方法:

  • chrome.extension.getURL
  • chrome.extension.getBackgroundPage

chrome.runtime

The following properties of chrome.runtime are supported:支持chrome.runtime的以下属性:

  • chrome.runtime.lastError
  • chrome.runtime.id

The following methods of chrome.runtime are supported:支持以下chrome.runtime方法:

  • chrome.runtime.getBackgroundPage
  • chrome.runtime.getManifest
  • chrome.runtime.getPlatformInfo
  • chrome.runtime.getURL
  • chrome.runtime.connect
  • chrome.runtime.sendMessage
  • chrome.runtime.reload

The following events of chrome.runtime are supported:支持chrome.runtime的以下事件:

  • chrome.runtime.onStartup
  • chrome.runtime.onInstalled
  • chrome.runtime.onSuspend
  • chrome.runtime.onSuspendCanceled
  • chrome.runtime.onConnect
  • chrome.runtime.onMessage

chrome.storage

Only chrome.storage.local is supported; chrome.storage.sync and chrome.storage.managed are not.仅支持chrome.storage.local,不支持chrome.storage.syncchrome.storage.managed

chrome.tabs

The following methods of chrome.tabs are supported:支持以下chrome.tabs方法:

  • chrome.tabs.sendMessage
  • chrome.tabs.reload
  • chrome.tabs.executeScript
  • chrome.tabs.update (partial support)(部分支持)
    • supported properties: url, muted.支持的属性:urlmuted

Note: In Chrome, passing -1 as a tab ID signifies the "currently active tab". 在Chrome中,将-1作为选项卡ID表示“当前活动的选项卡”。Since Electron has no such concept, passing -1 as a tab ID is not supported and will raise an error.由于Electron没有这样的概念,不支持将-1作为选项卡ID传递,并且会引发错误。

chrome.management

The following methods of chrome.management are supported:支持以下chrome.management方法:

  • chrome.management.getAll
  • chrome.management.get
  • chrome.management.getSelf
  • chrome.management.getPermissionWarningsById
  • chrome.management.getPermissionWarningsByManifest
  • chrome.management.onEnabled
  • chrome.management.onDisabled

chrome.webRequest

All features of this API are supported.支持此API的所有功能。

NOTE: Electron's webRequest module takes precedence over chrome.webRequest if there are conflicting handlers.如果存在冲突的处理程序,Electron的webRequest模块优先于chrome.webRequest