docs: update the example of webContents.setWindowOpenHandler to cla… (#49379)

docs: reorganize the comments for clarifying `webContents.setWindowOpenHandler` example
This commit is contained in:
ZHUO Xu
2026-03-17 00:12:52 +08:00
committed by GitHub
parent a561dd97a6
commit 078586fab0

View File

@@ -1485,6 +1485,11 @@ mainWindow.webContents.setWindowOpenHandler((details) => {
const browserView = new BrowserView(options)
mainWindow.addBrowserView(browserView)
browserView.setBounds({ x: 0, y: 0, width: 640, height: 480 })
// For `background-tab` disposition (e.g., when middle-clicking or ctrl/cmd-clicking a link),
// `options.webContents` is undefined because its creation can be deferred. So load the URL manually.
if (details.disposition === 'background-tab') {
browserView.webContents.loadURL(details.url)
}
return browserView.webContents
}
}