-
Notifications
You must be signed in to change notification settings - Fork 16.5k
Closed
Description
Preflight Checklist
- I have read the Contributing Guidelines for this project.
- I agree to follow the Code of Conduct that this project adheres to.
- I have searched the issue tracker for a feature request that matches the one I want to file, without success.
Problem Description
Previously described in #41432 (comment)
#41432 added an API to set a custom callback on popup window creation. This is necessary to, for example, have popups open in a BrowserView, rather than a new window.
With a BrowserView, this looks like:
mainWindow.webContents.setWindowOpenHandler((details) => {
return {
action: 'allow',
createWindow: (options) => {
const browserView = new BrowserView(options)
mainWindow.addBrowserView(browserView)
browserView.setBounds({ x: 0, y: 0, width: 640, height: 480 })
return browserView.webContents
}
}
})
options
contains a WebContents
, which is passed through to the BrowserView constructor.
The problem is that WebContentsView does not support passing in a WebContents
during it's construction, which makes this API impossible to use.
For now, I'm continuing to use a BrowserView in my app, but as BrowserView is deprecated, I'm concerned that once it's removed, I won't have any migration path to a newer version.
Proposed Solution
- Option 1: Allow passing in a WebContents to the WebContentsView constructor. This is already supported internally, and used by the BrowserView compatibility layer, it just isn't publicly exposed: https://github.com/electron/electron/blob/main/lib/browser/api/browser-view.ts#L13-L17. I'm not sure what the reason for hiding it was.
- Option 2: Change the
setWindowOpenHandler
API to work around this somehow. I expect that would be harder; I'm not sure exactly what the correct API would look like in that case.
Alternatives Considered
None.
Additional Information
No response