-
Notifications
You must be signed in to change notification settings - Fork 16.9k
feat: add support for webContents option in BrowserView #26802
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
Conversation
|
I'm not sure how I understand the way this would work—would you pass |
|
It allows us to override the internal tab.webContents.removeAllListeners('-add-new-contents' as any);
tab.webContents.on(
'-add-new-contents' as any,
(
event: any,
webContents: Electron.WebContents,
disposition: string,
_userGesture: boolean,
_left: number,
_top: number,
_width: number,
_height: number,
url: string,
frameName: string,
referrer: Electron.Referrer,
rawFeatures: string,
postData: PostData,
) => {
if (
disposition !== 'foreground-tab' &&
disposition !== 'new-window' &&
disposition !== 'background-tab'
) {
event.preventDefault();
return;
}
new BrowserView({ webContents });
},
); |
|
Given this API is intended to be undocumented, I'm downgrading from JFYI, we don't support overriding |
nornagon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some tests, thanks!
|
@nornagon done. |
|
Sorry for changing my mind, but would it be possible to also backport to 10 and 11? |
This is for @electron/wg-releases to decide, I'll add related tags. |
|
No Release Notes |
|
I was unable to backport this PR to "10-x-y" cleanly; |
* feat: add support for webContents option in BrowserView * tests: add tests
* feat: add support for webContents option in BrowserView (#26802) * feat: add support for webContents option in BrowserView * tests: add tests * fix: missing webContents import * fix: WebContents::New -> Create
|
Is there any plan to turn this into a public API? This would be really useful for me, but I'm concerned about depending on it as long as it remains undocumented. |
|
Hey guys, i am trying to use this API to open a browserview as a guest window upon window.open and this is what i am doing to make it work Now this works fine but when i try to close the BrowserView by clicking on any option on the UI(it may be calling Can anyone tell me what i could be doing wrong here? Also what @sentialx suggested doesn't work, this code below doesn't open any |
|
By closing do you mean calling |
|
In my case, removing the view from the window and calling |
When i said the application crashes, the application wasn't actually crashing which i later realized, what actually was happening was that, the new BrowserView(new Guest window) was closing the mainWindow upon calling window.close, i guess this is also an existing issue when we use BrowserView as a guest window I solved this issue by adding a preload script to the When this issue will be resolved, this hack won't be needed anymore. |
|
In my case, it is actually crashing, but after testing it again, I'm only seeing the crash infrequently (maybe 1/20 view closes?). I may still try to make a testcase at some point, but I don't think I can until I find a way to reproduce it consistently. I don't have an actual crash report; this is what I get as console output: But that's probably not very helpful for diagnosing. |
|
|
Description of Change
This PR adds support for
webContentsoption in BrowserView, which works similarly as in BrowserWindow. Since the newwebContents.setWindowOpenHandlerdoesn't support BrowserViews, we can at least listen to the internal-add-new-contentsevent and create a BrowserView with providedwebContents. This PR will also help in adding support for BrowserView insetWindowOpenHandlerin the future.Closes #24833
Could this be backported to 12-x-y?
Checklist
npm testpassesRelease Notes
Since it's a hidden API, I think it's not worth mentioning this change in the release notes.
Notes: no-notes