Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: document new extensions APIs #21809

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions docs/api/browser-window.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -701,15 +704,21 @@ 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<String, ExtensionInfo>` - The keys are the extension names and each value is
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

Expand All @@ -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

Expand All @@ -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<string, ExtensionInfo>` - The keys are the extension names and each value is
an Object containing `name` and `version` properties.
Expand All @@ -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:
Expand Down
59 changes: 59 additions & 0 deletions docs/api/session.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<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.

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`:
Expand Down
5 changes: 5 additions & 0 deletions docs/api/structures/extension.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Extension Object

* `id` String
* `name` String
* `version` String
1 change: 1 addition & 0 deletions filenames.auto.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down