Skip to content

CefSharp.WinForms.Example.netcore crashes when popup window #4656

Open
@gearsns

Description

@gearsns

Is there an existing issue for this?

  • I have searched both open/closed issues, no issue already exists.

CefSharp Version

120.1.80

Operating System

Windows 11

Architecture

x64

.Net Version

.Net 6.0

Implementation

WinForms

Reproduction Steps

  1. Run CefSharp.WinForms.Example.netcore
  2. Show popup window
  3. Close popup window
  4. Repeat 2 - 3.

Expected behavior

Expectations is that it will not crash when you close the popup window

Actual behavior

crash

Regression?

No response

Known Workarounds

Is this due to DoClose in LifeSpanHandler.cs?
Excluding control.Dispose() from InnvokeSyncOnUiThreadIfRequired stops crashing.

Does this problem also occur in the CEF Sample Application

No

Other information

html source

<!DOCTYPE HTML>
<html>
<a href="javascript:popup_open()" id="open">Popup!</a>
<a href="javascript:popup_close()" id="close">Close!</a>
<script>
    const popup_open = () => {
        window.open("index.html?pop=on")
    }
    const popup_close = () => {
        parent.window.close()
    }
    const params = new URLSearchParams(document.location.search)
    if (params.has("pop")) {
        document.getElementById("open").style.display = "none"
        document.title = "Popup!!"
    } else {
        document.getElementById("close").style.display = "none"
        document.title = "Popup Main"
    }
</script>
</html>

edit source code
CefSharp.WinForms\Handler\LifeSpanhandler.cs

                        control.InvokeSyncOnUiThreadIfRequired(new Action(() =>
                        {
                            onPopupDestroyed?.Invoke(control, browser);

                            //control.Dispose(); // Comment out!!
                        }));
                        // Add
                        control.InvokeOnUiThreadIfRequired(new Action(() =>
                        {
                            control.Dispose();
                        }));

CefSharp.WinForms.Example\BrowserTabUserControl.cs

                .OnPopupDestroyed((ctrl, popupBrowser) =>
                {
                    //If we docked  DevTools (hosted it ourselves rather than the default popup)
                    //Used when the BrowserTabUserControl.ShowDevToolsDocked method is called
                    if (popupBrowser.MainFrame.Url.Equals("devtools://devtools/devtools_app.html"))
                    {
                        //Dispose of the parent control we used to host DevTools, this will release the DevTools window handle
                        //and the ILifeSpanHandler.OnBeforeClose() will be call after.
                        ctrl.Dispose();
                    }
                    else
                    {
                        //If browser is disposed or the handle has been released then we don't
                        //need to remove the tab in this example. The user likely used the
                        // File -> Close Tab menu option which also calls BrowserForm.RemoveTab
                        if (!ctrl.IsDisposed && ctrl.IsHandleCreated)
                        {
                            if (ctrl.FindForm() is BrowserForm owner)
                            {
                                owner.RemoveTab(ctrl);
                            }

                            //ctrl.Dispose(); // Comment out!!
                        }
                    }
                })

Metadata

Metadata

Assignees

No one assigned

    Labels

    upstreamThese issues require fixing in the Chromium Embedded Framework(CEF) or Chromium.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions