I tried to handle the popup in Cefsharp(version 43, for Winforms), because I need to execute some javascript in the popup and to navigate to other site, but the application start to freezing when the popup appear. Also, I read the answer from this question How to handle popup links in CefSharp and I tried to implement it and my code look like this.
public class LifeSpanHandler : ILifeSpanHandler
{
public event Action<string> PopupRequest;
//The other members of this interface I leave empty
public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName, WindowOpenDisposition targetDisposition, bool userGesture, IWindowInfo windowInfo, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{
if (PopupRequest != null)
PopupRequest(targetUrl);
newBrowser = browserControl; // here I think is a problem
return true;
}
}
// Here is Form1 class
private void Button1_Click(object sender, EventArgs e)
{
LifeSpanHandler life = new LifeSpanHandler();
chromiumWebBrowser1.LifeSpanHandler = life;
life.PopupRequest += life_PopupRequest;
chromiumWebBrowser1.Load("http://www.popuptest.com/goodpopups.html");
}
void life_PopupRequest(object sender, string e)
{
Popup pop = new Popup();
ChromiumWebBrowser popBrowser = new ChromiumWebBrowser(e);
pop.Controls.Add(popBrowser);
pop.Visible = true;
popBrowser.Dock = DockStyle.Fill;
popBrowser.Visible = true;
// here the Application is freezing
}`
So how can I control the popups (to execute some javascript and navigate to other site) ?