js window.open return null ILifeSpanHandler:OnBeforePopup

Having problems with building or using the CefSharp .NET binding? Ask your CEF-related questions here. Please ask general usage questions on StackOverflow.

Moderator: amaitland

js window.open return null ILifeSpanHandler:OnBeforePopup

Postby Shay » Sat Dec 05, 2020 4:16 am

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
Attachments
CEFException.png
CEFException.png (25.12 KiB) Viewed 5445 times
Shay
Newbie
 
Posts: 9
Joined: Fri Dec 04, 2020 9:25 am

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

Postby amaitland » Sat Dec 05, 2020 2:45 pm

Please provide examples of your code, version you are using. See https://github.com/cefsharp/CefSharp/wi ... -following
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

Postby Shay » Sun Dec 06, 2020 3:44 am

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
Shay
Newbie
 
Posts: 9
Joined: Fri Dec 04, 2020 9:25 am

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

Postby amaitland » Sun Dec 06, 2020 4:53 am

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.
Maintainer of the CefSharp project.
amaitland
Virtuoso
 
Posts: 1290
Joined: Wed Jan 14, 2015 2:35 am

Re: js window.open return null ILifeSpanHandler:OnBeforePopu

Postby Shay » Tue Dec 08, 2020 4:13 pm

OK thanks,
I will try it.
Shay
Newbie
 
Posts: 9
Joined: Fri Dec 04, 2020 9:25 am


Return to CefSharp Forum

Who is online

Users browsing this forum: No registered users and 11 guests