Page 1 of 1

js window.open return null ILifeSpanHandler:OnBeforePopup

PostPosted: Sat Dec 05, 2020 4:16 am
by Shay
Hello,

I have a similar problem to the discussion in viewtopic.php?f=6&t=14109&p=30522&hilit=window.open+window.open+#p30522

I have a JS code that open a window (It is a 3rd party code and I cannot change it)
var myWindow = window.open("", "MsgWindow", "width=200,height=100");

The return value of "window.open" is null when I implement the method ILifeSpanHandler:OnBeforePopup ()
When I tried to set a value to the parameter "out IWebBrowser newBrowser" I got the attache exeption.

Please help.
How can I fix this?

Thanks,
Shay

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

PostPosted: Sat Dec 05, 2020 2:45 pm
by amaitland
Please provide examples of your code, version you are using. See https://github.com/cefsharp/CefSharp/wi ... -following

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

PostPosted: Sun Dec 06, 2020 3:44 am
by Shay
Hi
I am using version 83.4.20 with WinForms/OffScreen. The problem is also reproduced in version 86.

Here is my code:

public bool OnBeforePopup(IWebBrowser browserControl, IBrowser browser, IFrame frame, string targetUrl, string targetFrameName,
WindowOpenDisposition targetDisposition, bool userGesture, IPopupFeatures popupFeatures, IWindowInfo windowInfo,
IBrowserSettings browserSettings, ref bool noJavascriptAccess, out IWebBrowser newBrowser)
{



if (_eventsHandler != null)
{
ChNewWindowEventArgs eventArgs = new ChNewWindowEventArgs(targetUrl, (ChNewWindowEventArgs.WindowOpenType) targetDisposition);
_eventsHandler.DispatchNewWindow(this, eventArgs) ;
newBrowser = null;
return true;
}
}

newBrowser = null;
return false;
}
DispatchNewWindow(object sender, ChNewWindowEventArgs eventArgs){
...Here we create and navigate IWinFormsWebBrowser
...I tried to check it sync and async
}

Thanks,
Shay

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

PostPosted: Sun Dec 06, 2020 4:53 am
by amaitland
See https://github.com/cefsharp/CefSharp/bl ... Handler.cs for an example of hosting the popup as a tab, you can adapt this to suite your needs. You'll also need
https://github.com/cefsharp/CefSharp/bl ... dHelper.cs

Your example is incomplete, you've left out important parts.

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

PostPosted: Tue Dec 08, 2020 4:13 pm
by Shay
OK thanks,
I will try it.