cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.88k stars 2.92k forks source link

Impossible to use window.open during page load. #4940

Closed max3163 closed 1 month ago

max3163 commented 1 month ago

Is there an existing issue for this?

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.

max3163 commented 1 month ago

I'm just trying the 128 release, and the problem is still here ...

image

1-2sec before you can call the method....

When I use the ALLOW (version 127), it work on the first call as expected :

image

campersau commented 1 month ago

I had to disable popup blocking all together to make it work:

cefSettings.CefCommandLineArgs.Add("disable-popup-blocking");
amaitland commented 1 month ago

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)

max3163 commented 1 month ago

I'm a little confused, for me in 128 version, the alloy style is no more available ?

mitchcapper commented 1 month ago

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.

max3163 commented 1 month ago

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 :)

magreenblatt commented 1 month ago

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);