diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 1fc946a628d7..32a12b3fe77a 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -138,11 +138,16 @@ new [`BrowserWindow`](browser-window.md). If you call `event.preventDefault()` a instance, failing to do so may result in unexpected behavior. For example: ```javascript -myBrowserWindow.webContents.on('new-window', (event, url) => { +myBrowserWindow.webContents.on('new-window', (event, url, frameName, disposition, options) => { event.preventDefault() - const win = new BrowserWindow({ show: false }) + const win = new BrowserWindow({ + webContents: options.webContents, // use existing webContents if provided + show: false + }) win.once('ready-to-show', () => win.show()) - win.loadURL(url) + if (!options.webContents) { + win.loadURL(url) // existing webContents will be navigated automatically + } event.newGuest = win }) ```