-
Notifications
You must be signed in to change notification settings - Fork 15k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Popup handling in BrowserViews doesn't work with WebContentsView #42054
Comments
Hiding the ability to construct a WebContentsView with a pre-existing WebContents was an oversight, not an intentional design decision. Let's fix it :) My proposal would be: diff --git a/docs/api/web-contents-view.md b/docs/api/web-contents-view.md
index b4d6b4c93c..66bb257cf0 100644
--- a/docs/api/web-contents-view.md
+++ b/docs/api/web-contents-view.md
@@ -35,10 +35,11 @@ Process: [Main](../glossary.md#main-process)
### `new WebContentsView([options])`
* `options` Object (optional)
* `webPreferences` [WebPreferences](structures/web-preferences.md) (optional) - Settings of web page's features.
+ * `webContents` [WebContents](web-contents.md) (optional) - If present, the given WebContents will be adopted by the WebContentsView. A WebContents may only be presented in one WebContentsView at a time.
-Creates an empty WebContentsView.
+Creates a WebContentsView. |
That proposal looks good to me; I believe it matches how BrowserView works. |
To resolve this the following BrowserWindow code can be copied: shell\browser\api\electron_api_browser_window.cc // Copy the webContents option to webPreferences.
This allows us to simply pass the options argument of createWindow straight into as follows: new WebContentsView(options) Not sure who can add this. |
FYI: Here is the PR that attempts to add this functionality to |
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:
options
contains aWebContents
, 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
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
The text was updated successfully, but these errors were encountered: