diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index e83833e55d9ff..ac313ccff3753 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -681,7 +681,7 @@ Returns `BrowserWindow | null` - The window that owns the given `browserView`. I Returns `BrowserWindow` - The window with the given `id`. -#### `BrowserWindow.addExtension(path)` +#### `BrowserWindow.addExtension(path)` _Deprecated_ * `path` String @@ -692,7 +692,10 @@ The method will also not return if the extension's manifest is missing or incomp **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. -#### `BrowserWindow.removeExtension(name)` +**Note:** This method is deprecated. Instead, use +[`ses.loadExtension(path)`](session.md#sesloadextensionpath). + +#### `BrowserWindow.removeExtension(name)` _Deprecated_ * `name` String @@ -701,7 +704,10 @@ Remove a Chrome extension by name. **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. -#### `BrowserWindow.getExtensions()` +**Note:** This method is deprecated. Instead, use +[`ses.removeExtension(extension_id)`](session.md#sesremoveextensionextensionid). + +#### `BrowserWindow.getExtensions()` _Deprecated_ Returns `Record` - The keys are the extension names and each value is an Object containing `name` and `version` properties. @@ -709,7 +715,10 @@ an Object containing `name` and `version` properties. **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. -#### `BrowserWindow.addDevToolsExtension(path)` +**Note:** This method is deprecated. Instead, use +[`ses.getAllExtensions()`](session.md#sesgetallextensions). + +#### `BrowserWindow.addDevToolsExtension(path)` _Deprecated_ * `path` String @@ -725,7 +734,10 @@ The method will also not return if the extension's manifest is missing or incomp **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. -#### `BrowserWindow.removeDevToolsExtension(name)` +**Note:** This method is deprecated. Instead, use +[`ses.loadExtension(path)`](session.md#sesloadextensionpath). + +#### `BrowserWindow.removeDevToolsExtension(name)` _Deprecated_ * `name` String @@ -734,7 +746,10 @@ Remove a DevTools extension by name. **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. -#### `BrowserWindow.getDevToolsExtensions()` +**Note:** This method is deprecated. Instead, use +[`ses.removeExtension(extension_id)`](session.md#sesremoveextensionextensionid). + +#### `BrowserWindow.getDevToolsExtensions()` _Deprecated_ Returns `Record` - The keys are the extension names and each value is an Object containing `name` and `version` properties. @@ -751,6 +766,9 @@ console.log(installed) **Note:** This API cannot be called before the `ready` event of the `app` module is emitted. +**Note:** This method is deprecated. Instead, use +[`ses.getAllExtensions()`](session.md#sesgetallextensions). + ### Instance Properties Objects created with `new BrowserWindow` have the following properties: diff --git a/docs/api/session.md b/docs/api/session.md index b8e4815695f2b..78e87151a1656 100644 --- a/docs/api/session.md +++ b/docs/api/session.md @@ -494,6 +494,65 @@ Returns `Boolean` - Whether the word was successfully written to the custom dict **Note:** On macOS and Windows 10 this word will be written to the OS custom dictionary as well +#### `ses.loadExtension(path)` + +* `path` String - Path to a directory containing an unpacked Chrome extension + +Returns `Promise` - 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. + +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. + +```js +const { app, session } = require('electron') +const path = require('path') + +app.on('ready', async () => { + await session.defaultSession.loadExtension(path.join(__dirname, 'react-devtools')) + // Note that in order to use the React DevTools extension, you'll need to + // download and unzip a copy of the extension. +}) +``` + +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. + +#### `ses.removeExtension(extensionId)` + +* `extensionId` String - ID of extension to remove + +Unloads an extension. + +**Note:** This API cannot be called before the `ready` event of the `app` module +is emitted. + +#### `ses.getExtension(extensionId)` + +* `extensionId` String - ID of extension to query + +Returns `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. + +#### `ses.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. + ### Instance Properties The following properties are available on instances of `Session`: diff --git a/docs/api/structures/extension.md b/docs/api/structures/extension.md new file mode 100644 index 0000000000000..f575d352634c2 --- /dev/null +++ b/docs/api/structures/extension.md @@ -0,0 +1,5 @@ +# Extension Object + +* `id` String +* `name` String +* `version` String diff --git a/filenames.auto.gni b/filenames.auto.gni index 27af484c8c02f..3fea7c4a9deda 100644 --- a/filenames.auto.gni +++ b/filenames.auto.gni @@ -79,6 +79,7 @@ auto_filenames = { "docs/api/structures/display.md", "docs/api/structures/event.md", "docs/api/structures/extension-info.md", + "docs/api/structures/extension.md", "docs/api/structures/file-filter.md", "docs/api/structures/file-path-with-headers.md", "docs/api/structures/gpu-feature-status.md",