1

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

Community
  • 1
  • 1
Valentin Anghel
  • 776
  • 8
  • 13
  • `newBrowser` is supposed to be a new instance of `ChromiumWebBrowser`. Do you need a custom popup or just control over the standard one that's created? – amaitland Oct 20 '15 at 09:16
  • See https://github.com/cefsharp/CefSharp/blob/cefsharp/43/CefSharp.WinForms.Example/Handlers/LifeSpanHandler.cs for a demo of using `newBrowser`. This feature is experimental and there have been reported problems in some scenarios. – amaitland Oct 20 '15 at 09:29
  • It is not maked experimental in the wpf example: https://github.com/amaitland/CefSharp/blob/master/CefSharp.Wpf.Example/Handlers/LifespanHandler.cs –  Jan 23 '17 at 03:41

0 Answers0