Skip to content
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

fix: crash when clicking links with target=_blank from webview #29951

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 12 additions & 7 deletions shell/browser/web_view_guest_delegate.cc
Expand Up @@ -105,13 +105,18 @@ content::WebContents* WebViewGuestDelegate::CreateNewGuestWindow(
guest_params.context = embedder_web_contents_->GetNativeView();
std::unique_ptr<content::WebContents> guest_contents =
content::WebContents::Create(guest_params);
content::RenderWidgetHost* render_widget_host =
guest_contents->GetRenderViewHost()->GetWidget();
auto* guest_contents_impl =
static_cast<content::WebContentsImpl*>(guest_contents.release());
guest_contents_impl->GetView()->CreateViewForWidget(render_widget_host);

return guest_contents_impl;
if (!create_params.opener_suppressed) {
auto* guest_contents_impl =
static_cast<content::WebContentsImpl*>(guest_contents.release());
auto* new_guest_view = guest_contents_impl->GetView();
content::RenderWidgetHostView* widget_view =
new_guest_view->CreateViewForWidget(
guest_contents_impl->GetRenderViewHost()->GetWidget());
if (!create_params.initially_hidden)
widget_view->Show();
return guest_contents_impl;
}
return guest_contents.release();
}

} // namespace electron
9 changes: 9 additions & 0 deletions spec-main/webview-spec.ts
Expand Up @@ -491,6 +491,15 @@ describe('<webview> tag', function () {

await webContentsCreated;
});

it('does not crash when creating window with noopener', async () => {
loadWebView(w.webContents, {
allowpopups: 'on',
webpreferences: 'nativeWindowOpen=1',
src: `file://${path.join(fixtures, 'api', 'native-window-open-noopener.html')}`
});
await emittedOnce(app, 'browser-window-created');
});
});

describe('webpreferences attribute', () => {
Expand Down
10 changes: 10 additions & 0 deletions spec/fixtures/api/native-window-open-noopener.html
@@ -0,0 +1,10 @@
<html>
<body>
<a href="blank.html" target="_blank">noopener example</a>
</body>
<script type="text/javascript" charset="utf-8">
window.onload = () => {
document.querySelector('a').click()
}
</script>
</html>