Impossible to use window.open during page load.
Closed this issue · 7 comments
Is there an existing issue for this?
- I have searched both open/closed issues, no issue already exists.
CefSharp Version
126.2.180 or later
Operating System
Windows 10
Architecture
x64
.Net Version
4.8
Implementation
WinForms
Reproduction Steps
Start load this page :
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<script>
let count = 0;
function openWindowRec() {
console.log("Try window.open : " + count );
if (!window.open('', 'ID321')) {
setTimeout(() => {
count++;
openWindowRec();
}, 500)
}
}
console.log("First call openWindowRec" );
openWindowRec();
</script>
</body>
</html>
Expected behavior
A new window is create directly when the first window.open call is made.
Actual behavior
window.open return null during 4-5 second, no window is created and it work after.
Regression?
It work with ALLOY Runtime
Known Workarounds
None since 128
Does this problem also occur in the CEF Sample Application
No
Other information
The problem is present on the Minimal CEF Sharp Application but it work with the minimal CEF Client.
The problem is so on the C# implementation side.
I had to disable popup blocking all together to make it work:
cefSettings.CefCommandLineArgs.Add("disable-popup-blocking");
The problem is present on the Minimal CEF Sharp Application but it work with the minimal CEF Client.
I've updated the cefclient
links to reflect upstream changes, testing with --use-alloy-style
is now required for comparison.
The problem is so on the C# implementation side.
It's very unlikely this is a CefSharp
specific problem. More likely it's the alloy styled browsers (which CefSharp uses by default, the last cefclient uses chrome styled) don't handled the popup blocking gracefully.
CefSharp
can probably disable popup blocking by default, though that may not be wise as a long term general solution.
Please retest with --use-alloy-style
(in addition to the other command line args required for testing)
I'm a little confused, for me in 128 version, the alloy style is no more available ?
Alloy was split into runtime component and a 'style' component. The style component still exists on top of chrome to make it work much like the old alloy mode with the new runtime. While 128 killed off the old runtime the style still exists.
Ok , thanks for explanation !
So I tested the cefclient.exe with the '--use-alloy-style' and the problem occur too , worse it crash when the popup appear !
In any case, with the "disable-popup-blocking" option, on my CefSharp project it work like a charm !
Thank for the help :)
You can also allow specific origins to create popups using (C++) code like the following in CefRequestContextHandler::OnRequestContextInitialized
:
context->SetContentSetting(origin_url, origin_url,
CEF_CONTENT_SETTING_TYPE_POPUPS,
CEF_CONTENT_SETTING_VALUE_ALLOW);