chore: remove deprecated extension APIs ()

This commit is contained in:
Milan Burda 2020-11-30 23:40:56 +01:00 committed by GitHub
parent 7d49ce898a
commit 19954126e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 43 additions and 156 deletions

View file

@ -723,94 +723,6 @@ Returns `BrowserWindow | null` - The window that owns the given `browserView`. I
Returns `BrowserWindow | null` - The window with the given `id`.
#### `BrowserWindow.addExtension(path)` _Deprecated_
* `path` String
Adds Chrome extension located at `path`, and returns extension's name.
The method will also not return if the extension's manifest is missing or incomplete.
**Note:** This API cannot be called before the `ready` event of the `app` module
is emitted.
**Note:** This method is deprecated. Instead, use
[`ses.loadExtension(path)`](session.md#sesloadextensionpath).
#### `BrowserWindow.removeExtension(name)` _Deprecated_
* `name` String
Remove a Chrome extension by name.
**Note:** This API cannot be called before the `ready` event of the `app` module
is emitted.
**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.
**Note:** This method is deprecated. Instead, use
[`ses.getAllExtensions()`](session.md#sesgetallextensions).
#### `BrowserWindow.addDevToolsExtension(path)` _Deprecated_
* `path` String
Adds DevTools extension located at `path`, and returns extension's name.
The extension will be remembered so you only need to call this API once, this
API is not for programming use. If you try to add an extension that has already
been loaded, this method will not return and instead log a warning to the
console.
The method will also not return if the extension's manifest is missing or incomplete.
**Note:** This API cannot be called before the `ready` event of the `app` module
is emitted.
**Note:** This method is deprecated. Instead, use
[`ses.loadExtension(path)`](session.md#sesloadextensionpath).
#### `BrowserWindow.removeDevToolsExtension(name)` _Deprecated_
* `name` String
Remove a DevTools extension by name.
**Note:** This API cannot be called before the `ready` event of the `app` module
is emitted.
**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.
To check if a DevTools extension is installed you can run the following:
```javascript
const { BrowserWindow } = require('electron')
const installed = 'devtron' in BrowserWindow.getDevToolsExtensions()
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:

View file

@ -26,6 +26,45 @@ shell.moveItemToTrash(path)
shell.trashItem(path).then(/* ... */)
```
### Removed: `BrowserWindow` extension APIs
The deprecated extension APIs have been removed:
* `BrowserWindow.addExtension(path)`
* `BrowserWindow.addDevToolsExtension(path)`
* `BrowserWindow.removeExtension(name)`
* `BrowserWindow.removeDevToolsExtension(name)`
* `BrowserWindow.getExtensions()`
* `BrowserWindow.getDevToolsExtensions()`
Use the session APIs instead:
* `ses.loadExtension(path)`
* `ses.removeExtension(extension_id)`
* `ses.getAllExtensions()`
```js
// Removed in Electron 13
BrowserWindow.addExtension(path)
BrowserWindow.addDevToolsExtension(path)
// Replace with
session.defaultSession.loadExtension(path)
```
```js
// Removed in Electron 13
BrowserWindow.removeExtension(name)
BrowserWindow.removeDevToolsExtension(name)
// Replace with
session.defaultSession.removeExtension(extension_id)
```
```js
// Removed in Electron 13
BrowserWindow.getExtensions()
BrowserWindow.getDevToolsExtensions()
// Replace with
session.defaultSession.getAllExtensions()
```
## Planned Breaking API Changes (12.0)
### Removed: Pepper Flash support

View file

@ -231,7 +231,6 @@ auto_filenames = {
"lib/browser/api/web-contents-view.ts",
"lib/browser/api/web-contents.ts",
"lib/browser/api/web-frame-main.ts",
"lib/browser/chrome-extension-shim.ts",
"lib/browser/default-menu.ts",
"lib/browser/desktop-capturer.ts",
"lib/browser/devtools.ts",

View file

@ -1,31 +0,0 @@
// This is a temporary shim to aid in transition from the old
// BrowserWindow-based extensions stuff to the new native-backed extensions
// API.
import { app, session, BrowserWindow, deprecate } from 'electron/main';
app.whenReady().then(function () {
const addExtension = function (srcDirectory: string) {
return session.defaultSession.loadExtension(srcDirectory);
};
const removeExtension = function (name: string) {
const extension = session.defaultSession.getAllExtensions().find(e => e.name === name);
if (extension) { session.defaultSession.removeExtension(extension.id); }
};
const getExtensions = function () {
const extensions: Record<string, any> = {};
session.defaultSession.getAllExtensions().forEach(e => {
extensions[e.name] = e;
});
return extensions;
};
BrowserWindow.addExtension = deprecate.moveAPI(addExtension, 'BrowserWindow.addExtension', 'session.loadExtension');
BrowserWindow.removeExtension = deprecate.moveAPI(removeExtension, 'BrowserWindow.removeExtension', 'session.removeExtension');
BrowserWindow.getExtensions = deprecate.moveAPI(getExtensions, 'BrowserWindow.getExtensions', 'session.getAllExtensions');
BrowserWindow.addDevToolsExtension = deprecate.moveAPI(addExtension, 'BrowserWindow.addDevToolsExtension', 'session.loadExtension');
BrowserWindow.removeDevToolsExtension = deprecate.moveAPI(removeExtension, 'BrowserWindow.removeDevToolsExtension', 'session.removeExtension');
BrowserWindow.getDevToolsExtensions = deprecate.moveAPI(getExtensions, 'BrowserWindow.getDevToolsExtensions', 'session.getAllExtensions');
});

View file

@ -132,9 +132,6 @@ app._setDefaultAppPaths(packagePath);
// Load the chrome devtools support.
require('@electron/internal/browser/devtools');
// Load the chrome extension support.
require('@electron/internal/browser/chrome-extension-shim');
if (BUILDFLAG(ENABLE_REMOTE_MODULE)) {
require('@electron/internal/browser/remote/server');
}

View file

@ -401,33 +401,6 @@ describe('chrome extensions', () => {
});
});
describe('deprecation shims', () => {
it('loads an extension through BrowserWindow.addExtension', async () => {
BrowserWindow.addExtension(path.join(fixtures, 'extensions', 'red-bg'));
const w = new BrowserWindow({ show: false });
await w.loadURL(url);
const bg = await w.webContents.executeJavaScript('document.documentElement.style.backgroundColor');
expect(bg).to.equal('red');
});
it('loads an extension through BrowserWindow.addDevToolsExtension', async () => {
BrowserWindow.addDevToolsExtension(path.join(fixtures, 'extensions', 'red-bg'));
const w = new BrowserWindow({ show: false });
await w.loadURL(url);
const bg = await w.webContents.executeJavaScript('document.documentElement.style.backgroundColor');
expect(bg).to.equal('red');
});
it('removes an extension through BrowserWindow.removeExtension', async () => {
await (BrowserWindow.addExtension(path.join(fixtures, 'extensions', 'red-bg')) as any);
BrowserWindow.removeExtension('red-bg');
const w = new BrowserWindow({ show: false });
await w.loadURL(url);
const bg = await w.webContents.executeJavaScript('document.documentElement.style.backgroundColor');
expect(bg).to.equal('');
});
});
describe('chrome extension content scripts', () => {
const fixtures = path.resolve(__dirname, 'fixtures');
const extensionPath = path.resolve(fixtures, 'extensions');
@ -510,11 +483,11 @@ describe('chrome extensions', () => {
const COLOR_TRANSPARENT = 'rgba(0, 0, 0, 0)';
before(() => {
BrowserWindow.addExtension(contentScript);
session.defaultSession.loadExtension(contentScript);
});
after(() => {
BrowserWindow.removeExtension('content-script-test');
session.defaultSession.removeExtension('content-script-test');
});
beforeEach(() => {

View file

@ -181,10 +181,10 @@ describe('<webview> tag', function () {
nodeIntegration: true
}
});
BrowserWindow.removeDevToolsExtension('foo');
w.webContents.session.removeExtension('foo');
const extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo');
await BrowserWindow.addDevToolsExtension(extensionPath);
await w.webContents.session.loadExtension(extensionPath);
w.loadFile(path.join(__dirname, 'fixtures', 'pages', 'webview-devtools.html'));
loadWebView(w.webContents, {

View file

@ -462,8 +462,6 @@ window.setVibrancy('selection')
window.setVibrancy('popover')
window.setIcon('/path/to/icon')
const installed = BrowserWindow.getDevToolsExtensions().hasOwnProperty('devtron')
// content-tracing
// https://github.com/electron/electron/blob/master/docs/api/content-tracing.md