Repository: electron/electron (language: cpp)

Issue:
[Bug]: Please fix the webview docs
### Preflight Checklist

- [X] I have read the [Contributing Guidelines](https://github.com/electron/electron/blob/main/CONTRIBUTING.md) for this project.
- [X] I agree to follow the [Code of Conduct](https://github.com/electron/electron/blob/main/CODE_OF_CONDUCT.md) that this project adheres to.
- [X] I have searched the [issue tracker](https://www.github.com/electron/electron/issues) for a bug report that matches the one I want to file, without success.

### Electron Version

19.0.5

### What operating system are you using?

Windows

### Operating System Version

Windows 10

### What arch are you using?

x64

### Last Known Working Electron version

13.0.0

### Expected Behavior

When I update electron from 13.0.0 to 19.0.5 ，webview's new-window event will not be triggered when I click a new url.
I searched a lot of docs and issues to find this answer . I finally found some discussions in #31117。
In docs [https://www.electronjs.org/docs/latest/api/web-contents#event-new-window-deprecated](https://www.electronjs.org/docs/latest/api/web-contents#event-new-window-deprecated)
Event: 'new-window' has been deprecated, but there is no any  notices or declarations in  webview docs: [https://www.electronjs.org/docs/latest/api/webview-tag](https://www.electronjs.org/docs/latest/api/webview-tag) , this is so confused me. Please fix the docs.

### Actual Behavior

 Please fix the webview docs, add some declarations about event: 'new-window' has been deprecated.

### Testcase Gist URL

_No response_

### Additional Information

_No response_


Discussion / hints:
hey I would like to work on this project can I get started?
For visibility. @miniak made related changes in the following PRs:

- A warning was added for `new-window` event until version 22: https://github.com/electron/electron/pull/34528
- In version 22 the event is set to be removed: https://github.com/electron/electron/pull/34526

I guess the only missing thing to close this issue is to update the document. However, `main` branch doesn't have that event already. Not sure how to push this change to the docs now. Restore the docs and release or make the change in a specific branch.

Can someone point to an example of how this is usually done?
This issue has been automatically marked as stale. **If this issue is still affecting you, please leave any comment** (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the [latest version of Electron](https://www.electronjs.org/releases/stable) or in the [beta](https://www.electronjs.org/releases/beta)—please include it with your comment!
Hey, I would like to work on this project, how can I start?
I would like to work on this issue, please assign me this issue to resolve.
@Michael-py001  I believe the issue is resolved as the event has been removed and documentation updated. 

Fix patch:
diff --git a/docs/breaking-changes.md b/docs/breaking-changes.md
index 68cf3d4e04818..ab473fc43e6b5 100644
--- a/docs/breaking-changes.md
+++ b/docs/breaking-changes.md
@@ -278,6 +278,39 @@ webContents.setWindowOpenHandler((details) => {
 })
 ```
 
+### Removed: `<webview>` `new-window` event
+
+The `new-window` event of `<webview>` has been removed. There is no direct replacement.
+
+```js
+// Removed in Electron 22
+webview.addEventListener('new-window', (event) => {})
+```
+
+```javascript fiddle='docs/fiddles/ipc/webview-new-window'
+// Replace with
+
+// main.js
+mainWindow.webContents.on('did-attach-webview', (event, wc) => {
+  wc.setWindowOpenHandler((details) => {
+    mainWindow.webContents.send('webview-new-window', wc.id, details)
+    return { action: 'deny' }
+  })
+})
+
+// preload.js
+const { ipcRenderer } = require('electron')
+ipcRenderer.on('webview-new-window', (e, webContentsId, details) => {
+  console.log('webview-new-window', webContentsId, details)
+  document.getElementById('webview').dispatchEvent(new Event('new-window'))
+})
+
+// renderer.js
+document.getElementById('webview').addEventListener('new-window', () => {
+  console.log('got new-window event')
+})
+```
+
 ### Deprecated: BrowserWindow `scroll-touch-*` events
 
 The `scroll-touch-begin`, `scroll-touch-end` and `scroll-touch-edge` events on
diff --git a/docs/fiddles/ipc/webview-new-window/child.html b/docs/fiddles/ipc/webview-new-window/child.html
new file mode 100644
index 0000000000000..90c94376c284b
--- /dev/null
+++ b/docs/fiddles/ipc/webview-new-window/child.html
@@ -0,0 +1,3 @@
+<body>
+  <a href="child.html" target="_blank">new window</a>
+</body>
diff --git a/docs/fiddles/ipc/webview-new-window/index.html b/docs/fiddles/ipc/webview-new-window/index.html
new file mode 100644
index 0000000000000..8b461bd15f83a
--- /dev/null
+++ b/docs/fiddles/ipc/webview-new-window/index.html
@@ -0,0 +1,4 @@
+<body>
+  <webview id=webview src="child.html" allowpopups></webview>
+  <script src="renderer.js"></script>
+</body>
diff --git a/docs/fiddles/ipc/webview-new-window/main.js b/docs/fiddles/ipc/webview-new-window/main.js
new file mode 100644
index 0000000000000..cab3b1ec1b656
--- /dev/null
+++ b/docs/fiddles/ipc/webview-new-window/main.js
@@ -0,0 +1,51 @@
+// Modules to control application life and create native browser window
+const { app, BrowserWindow } = require('electron')
+const path = require('path')
+
+function createWindow () {
+  // Create the browser window.
+  const mainWindow = new BrowserWindow({
+    width: 800,
+    height: 600,
+    webPreferences: {
+      preload: path.join(__dirname, 'preload.js'),
+      webviewTag: true
+    }
+  })
+
+  mainWindow.webContents.on('did-attach-webview', (event, wc) => {
+    wc.setWindowOpenHandler((details) => {
+      mainWindow.webContents.send('webview-new-window', wc.id, details)
+      return { action: 'deny' }
+    })
+  })
+
+  // and load the index.html of the app.
+  mainWindow.loadFile('index.html')
+
+  // Open the DevTools.
+  // mainWindow.webContents.openDevTools()
+}
+
+// This method will be called when Electron has finished
+// initialization and is ready to create browser windows.
+// Some APIs can only be used after this event occurs.
+app.whenReady().then(() => {
+  createWindow()
+
+  app.on('activate', function () {
+    // On macOS it's common to re-create a window in the app when the
+    // dock icon is clicked and there are no other windows open.
+    if (BrowserWindow.getAllWindows().length === 0) createWindow()
+  })
+})
+
+// Quit when all windows are closed, except on macOS. There, it's common
+// for applications and their menu bar to stay active until the user quits
+// explicitly with Cmd + Q.
+app.on('window-all-closed', function () {
+  if (process.platform !== 'darwin') app.quit()
+})
+
+// In this file you can include the rest of your app's specific main process
+// code. You can also put them in separate files and require them here.
diff --git a/docs/fiddles/ipc/webview-new-window/preload.js b/docs/fiddles/ipc/webview-new-window/preload.js
new file mode 100644
index 0000000000000..5b5b6e70a6265
--- /dev/null
+++ b/docs/fiddles/ipc/webview-new-window/preload.js
@@ -0,0 +1,6 @@
+const { ipcRenderer } = require('electron')
+const webview = document.getElementById('webview')
+ipcRenderer.on('webview-new-window', (e, webContentsId, details) => {
+  console.log('webview-new-window', webContentsId, details)
+  webview.dispatchEvent(new Event('new-window'))
+})
diff --git a/docs/fiddles/ipc/webview-new-window/renderer.js b/docs/fiddles/ipc/webview-new-window/renderer.js
new file mode 100644
index 0000000000000..e62d0b4d17bc3
--- /dev/null
+++ b/docs/fiddles/ipc/webview-new-window/renderer.js
@@ -0,0 +1,4 @@
+const webview = document.getElementById('webview')
+webview.addEventListener('new-window', () => {
+  console.log('got new-window event')
+})


Test patch: