Skip to content

Commit 60cfeee

Browse files
Willie-Boyroot
and
root
authored
[DevTools] Replace deprecated new-window with webContents.setWindowOpenHandler() (#26559)
## Summary The electron package was recently upgraded from ^11.1.0 to ^23.1.2 (#26337). However, the WebContents `new-window` event – that is used in the react-devtools project – was deprecated in [v12.0.0](https://releases.electronjs.org/release/v12.0.0) and removed in [v22.2.0](https://releases.electronjs.org/release/v22.2.0). The event was replaced by `webContents.setWindowOpenHandler()`. This PR replaces the `new-window` event with `webContents.setWindowOpenHandler()`. ## How did you test this change? I created a simple electron application with similar functionality: ``` const { app, BrowserWindow, shell } = require('electron') const createWindow = () => { const mainWindow = new BrowserWindow({ width: 800, height: 600 }) mainWindow.webContents.setWindowOpenHandler(({ url }) => { shell.openExternal(url) return { action: 'deny' } }) mainWindow.loadFile('index.html') } app.whenReady().then(() => { createWindow() }) ``` --------- Co-authored-by: root <root@DESKTOP-KCGHLB8.localdomain>
1 parent 9cfba0f commit 60cfeee

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

packages/react-devtools/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
const {app, BrowserWindow} = require('electron'); // Module to create native browser window.
8+
const {app, BrowserWindow, shell} = require('electron'); // Module to create native browser window.
99
const {join} = require('path');
1010
const os = require('os');
1111

@@ -40,9 +40,9 @@ app.on('ready', function () {
4040
}
4141

4242
// https://stackoverflow.com/questions/32402327/
43-
mainWindow.webContents.on('new-window', function (event, url) {
44-
event.preventDefault();
45-
require('electron').shell.openExternal(url);
43+
mainWindow.webContents.setWindowOpenHandler(({url}) => {
44+
shell.openExternal(url);
45+
return {action: 'deny'};
4646
});
4747

4848
// and load the index.html of the app.

0 commit comments

Comments
 (0)