'ChromiumWebBrowser opens blank form why?

I created a project and added CefSharp.WinForms from nuget in it.

I gave an address and ChromiumWebBrowser opened it. While I was navigating around this address, I clicked a download link. No problem, the file is downloaded. but with that an empty form opens.

what is this empty form, why is it opening and how can i close it from the code?

Blank Form Comes Link



Solution 1:[1]

If the link you clicked opened a popup then a blank window is expected. You can hide the window until the download is complete then close it. The following code saves all files to a temp folder. You can change the folder to a path within the users profile or instead of UseFolder call AskUser.

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

var tempPath = System.IO.Path.GetTempPath();

browser.DownloadHandler =
    Fluent.DownloadHandler.UseFolder(tempPath,
        (chromiumBrowser, browser, downloadItem, callback) =>
        {
            if (downloadItem.IsComplete || downloadItem.IsCancelled)
            {
                if (browser.IsPopup && !browser.HasDocument)
                {
                    browser.GetHost().CloseBrowser(true);
                }
            }
            //TODO: You may wish to customise this condition to better suite your
            //requirements. 
            else if(downloadItem.ReceivedBytes < 100)
            {
                var popupHwnd = browser.GetHost().GetWindowHandle();

                var visible = IsWindowVisible(popupHwnd);
                if(visible)
                {
                    const int SW_HIDE = 0;
                    ShowWindow(popupHwnd, SW_HIDE);
                }
            }
        });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 amaitland