I created a program that will effectively act like a web browser using the CefSharp.Winforms Chromium browser (version 111.2.20). I have a panel that I use with the Chromium browser:
public ChromiumWebBrowser chromeBrowser;
public void InitializeChromium()
{
chromeBrowser = new ChromiumWebBrowser(TEXT_FIELD.Text);
chromeBrowser.Dock = DockStyle.Fill;
this.PANEL_BROWSER.Controls.Add(chromeBrowser);
}
This initialization method takes place right after "InitializeComponent();".
When I use the built in WebBrowser (IE), I get pop ups when navigating to a site that requires it. However, there are issues with how certain pages load and I am using the Chromium browser as a result. Unfortunately I do not get the pop up with the Chromium browser. Navigating to the site just skips the log in pop up and the site fails to load. I have looked at the resources online for the tool, but I am very self taught and I do not fully understand the best way to resolve this.
I added the following code to my program (tweaking it to say false), but I get errors on the first line. I also notice that the class has no references, but I'd like some guidance on how to have this take effect and allow the pop up.
chromiumWebBrowser.LifeSpanHandler = new LifeSpanHandler();
public class LifeSpanHandler : CefSharp.Handler.LifeSpanHandler
{
protected override bool OnBeforePopup(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo, IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
newBrowser = null;
//Return true to cancel the popup creation
return false;
}
}
I am by no means an expert and any help is appreciated. I can follow up on any questions and do my best to clarify my question if it is not clear.
These are the resources that I looked at trying to resolve this myself.
https://github.com/cefsharp/CefSharp/wiki/General-Usage (pop up section)
How to handle popup links in CefSharp
My program largely follows this guide by Fox Learn (without the tabs): https://www.youtube.com/watch?v=p3trglnFZ9Y&ab_channel=FoxLearn
Thank you for any advice and assistance.