Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Popup handling in BrowserViews doesn't work with WebContentsView #42054

Copy link
Copy link
@PalmerAL

Description

@PalmerAL
Issue body actions

Preflight Checklist

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.