Load and interact with extensions.
Process: Main
This class is not exported from the 'electron'
module. It is only available as a return value of other methods in the Electron API.
Instances of the Extensions
class are accessed by using extensions
property of a Session
.
The following events are available on instances of Extensions
:
Returns:
event
Eventextension
ExtensionEmitted after an extension is loaded. This occurs whenever an extension is added to the "enabled" set of extensions. This includes:
Extensions.loadExtension
.chrome.runtime.reload()
).Returns:
event
Eventextension
ExtensionEmitted after an extension is unloaded. This occurs when Session.removeExtension
is called.
Returns:
event
Eventextension
ExtensionEmitted after an extension is loaded and all necessary browser state is initialized to support the start of the extension's background page.
Instance MethodsâThe following methods are available on instances of Extensions
:
extensions.loadExtension(path[, options])
â
path
string - Path to a directory containing an unpacked Chrome extensionoptions
Object (optional)
allowFileAccess
boolean - Whether to allow the extension to read local files over file://
protocol and inject content scripts into file://
pages. This is required e.g. for loading devtools extensions on file://
URLs. Defaults to false.Returns Promise<Extension>
- resolves when the extension is loaded.
This method will raise an exception if the extension could not be loaded. If there are warnings when installing the extension (e.g. if the extension requests an API that Electron does not support) then they will be logged to the console.
Note that Electron does not support the full range of Chrome extensions APIs. See Supported Extensions APIs for more details on what is supported.
Note that in previous versions of Electron, extensions that were loaded would be remembered for future runs of the application. This is no longer the case: loadExtension
must be called on every boot of your app if you want the extension to be loaded.
const { app, session } = require('electron')
const path = require('node:path')
app.whenReady().then(async () => {
await session.defaultSession.extensions.loadExtension(
path.join(__dirname, 'react-devtools'),
{ allowFileAccess: true }
)
})
This API does not support loading packed (.crx) extensions.
note
This API cannot be called before the ready
event of the app
module is emitted.
note
Loading extensions into in-memory (non-persistent) sessions is not supported and will throw an error.
extensions.removeExtension(extensionId)
â
extensionId
string - ID of extension to removeUnloads an extension.
note
This API cannot be called before the ready
event of the app
module is emitted.
extensions.getExtension(extensionId)
â
extensionId
string - ID of extension to queryReturns Extension | null
- The loaded extension with the given ID.
note
This API cannot be called before the ready
event of the app
module is emitted.
extensions.getAllExtensions()
â
Returns Extension[]
- A list of all loaded extensions.
note
This API cannot be called before the ready
event of the app
module is emitted.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4