Closed adsonvinicius closed 4 years ago
This is not a bug, if you are canceling popup creation by returning true then there can be no link to the parent browser.
I see. But is possible to intercept a popup from its parent and set this as a new IWebBrowser and keep the link even returning true? Or cancelling a popup creation kills all links to its parent?
Returning true cancels popup creation. If your website is creating another popup it's likely doing so in JavaScript as some sort of error retry handling. You are creating a new browser instance with the url that the popup was to open, there's no association. It's like independently opening a browser instance.
If you need to host the popup as a tab then you need to return false to allow the popup to be created. The specifics of how depend or version, WinForms/WPF (You didn't fill out the bug report temple so I don't know any of this information)
I was trying returning true and adding a new ChromiumWebBrowser with the targetUrl only. I'm using last version of CefSharp and WinForms. So is there a chance to popup as a tab?
In future please specify the exact version, latest is relative.
The WinForms example in the main repository has a working example see https://github.com/cefsharp/CefSharp/blob/cefsharp/83/CefSharp.WinForms.Example/Handlers/LifeSpanHandler.cs
Additionally you need https://github.com/cefsharp/CefSharp/blob/cefsharp/83/CefSharp.WinForms.Example/Helper/PopupAsChildHelper.cs
Ok thank you. About the helper I got an error in this method:
public void RefindParentForm()
{
parentControl.InvokeOnUiThreadIfRequired(() =>
{
ParentFormChanged(parentControl, null);
});
}
Which throws: "Controls doesn't have a definition to InvokeOnUiThreadIfRequired and can't find any extension method which takes the first argument as control". Once this method is an internal Cefsharp, what's wrong with it?
Once this method is an internal Cefsharp, what's wrong with it?
What do you mean?
The example could be updated to use the version contained within the example project. https://github.com/cefsharp/CefSharp/blob/cefsharp/83/CefSharp.WinForms.Example/ControlExtensions.cs#L18
You are welcome to submit a PR.
It's not a CefSharp specific function, it's just a helper method.
Does the example project works fine on last version os CefSharp? I ask because I'm getting errors like Extension method must be defined in a non-generic static class to instantiate the PopupAsChildHelper class.
Does the example project works fine on last version os CefSharp?
Yes see https://ci.appveyor.com/project/cefsharp/cefsharp
I ask because I'm getting errors like Extension method must be defined in a non-generic static class to instantiate the PopupAsChildHelper class.
The error is self explanatory, you've added an extension method to a non static class. Turn it into a regular method if you don't want to create a new class.
Ok, I tried and now is working as expected. My new tab is opened without difference from Chrome behavior.
About the event FrameLoadEnd on webBrowser instantiated on OnBeforePopup method, the property args.Frame.IsMain is never true. Is this correct?
You'll need to implement http://cefsharp.github.io/api/83.4.x/html/T_CefSharp_ILoadHandler.htm the FrameLoadEnd should only be called for the main browser (not popups).
OK. It worked fine. Thanks.
I asked as a Bug Report because I could check different behavior from ILifeSpanHandler.OnBeforePopup . I created a TabControl which Invoke an action do add an IWebBrowser on JS window.open event. There's a website which I'm displaying that checks window/tab ID to avoid open on different tab/window from expected (the website is not under my control so I inspected and could see some javascript functions for it). I don't wanna make anything different from Chrome, where website opens a new tab and everything works fine. However when this code is ran:
ChromiumWebBrowser chromiumWebBrowser = new ChromiumWebBrowser(targetUrl); newBrowser = chromiumWebBrowser; [ ... Invoke TabControl and add a Tab ] return true;
The website throws an error and calls another page.
On this issue was said: The new browser instance you create will not have any link to the parent. So the popUp-new-browser have different behavior related to parent when the window is created returning false (and new Browser is null) than when the new browser is set to an new instance of browser and returning true on OnBeforePopup method?