Webview2 browser popup window is not coming in front
Description Popup window is not getting focus.
Version SDK: 1.0.1054.31 Runtime: 99.0.1150.39 Framework: WPF and .NET framework 4.8 OS: Windows 10 Web page have multiple links. When we click on the link it will open popup window and same popup window will be reused for other links. Issues is popup window is not focused when click on links which will load the url in existing popup window.
Its working fine in IE and Chrome(98.0.4758.102 ) browsers. On clicking the link its brings the existing popup window to front and loads the url.
Adding bring to front code in newwindow requested event is not working as it will come only for first time. please let us know if we need to set any property in webview2 or any event is available where we can add brig to front code.
Thanks.
Hey @SureshkPerumal - if I understand correctly you have code that will bring the popup window to the foreground that works in NewWindowRequested? Can you try using that code in response to the navigation as well (NavigationStarting on the popup's WebView2 probably)?
@champnic , Tried using it in NavigationStarting but its not proper user experience as its try to bring popup for each internal url navigation.
Try below html code.in chrome/edge browser .it bring the popup browser window to front. can we hook up that event in webview2?
<html>
<body>
<button onclick="OpenPopUp('https://www.google.com')">Link 1</button>
<button onclick="OpenPopUp('https://github.com/MicrosoftEdge/WebView2Feedback/issues')">Link 2</button>
<button onclick="OpenPopUp('https://github.com/MicrosoftEdge/WebView2Feedback/pulls')">Link 3</button>
<button onclick="OpenPopUp('https://github.com/MicrosoftEdge/WebView2Feedback/discussions')">Link 4</button>
<button onclick="OpenPopUp('https://docs.microsoft.com/en-us/microsoft-edge/webview2/release-notes')">Link 5</button>
<script>
function OpenPopUp(url) {
var myWindow = window.open(url, "PopWindow", "width=600,height=600");
}
</script>
</body>
</html>
We do use third party browser that have browser activate event using that we had achieved this use case.
https://www.essentialobjects.com/doc/eo.webbrowser.webview.activate
You could try limiting the activation of the popup window to your desired scenario:
When we click on the link it will open popup window and same popup window will be reused for other links.
The issue may also be that the popup window doesn't have foreground rights as it's out of process, so you may also want to consider handling NewWindowRequested and providing your own window which you can then handle the activation of.
@champnic , We handled NewWindowRequested ,In NewWindowRequested event we will open wpf window which have webview2 instance from NewWindowRequested event. Issue is NewWindowRequested invoked only once. we have no control when urls is loaded in webview2 embedded in popup wpf window on successive link clicks ,which is using existing webview2 instance from newWindowRequested event.
is it possible for you to try the above html in your WPF webview2 sample code and check if u are able to set the focus to popup.
I think the level of control you are looking for with the popup window is achievable if you supply your own window and a new WebView2 to the NewWindowRequested event. Then you can handle link clicks, activation, etc.
I'm not sure we want to change the default behavior here, as otherwise every time a popup does a navigation (including not in reaction to user input) the window would get activated and foreground, and could be stealing focus from other apps.
Hi @champnic, Is there any change went in webview2 runtime 100.0.1185.29 for setting focus to popup window? popup windows gets activated and working as expected after upgrading to above runtime.
Thanks
It's possible a fix went in. There's lots of code that gets checked in every release. Do you still see the correct behavior if you use Canary (version 102)? If so I'll close this as fixed.
@champnic , I have download and Installed the webview2 runtime version 101.0.1210.39 but still that Popup window is opened the behind the main window not focused actively. need to see that window to go to task manager. Also Updated and tried with Webview2 NuGet Package version 1.0.1185.39 didn't work as expected
Please suggest which version have fixed that to show the active popup window on top of main window
Thanks
So this likely is still an issue then. I'm opening this bug on our backlog to take a closer look. Thanks!
@champnic , Is this issue is addressed? we are still having this issue.
Hi @SureshkPerumal,
yes, this issue is fixed on 110.0.1587.63 version.
Here the following code
webview2.CoreWebView2Initialized += webview2_CoreWebView2Initialized;
need to do webview2 initialized.
private void webview2_CoreWebView2Initialized(Microsoft.UI.Xaml.Controls.WebView2 sender, Microsoft.UI.Xaml.Controls.CoreWebView2InitializedEventArgs args)
{
sender.CoreWebView2.NewWindowRequested += CoreWebView2_NewWindowRequested;
}
after initialized the new window request event will be created below code.
private void CoreWebView2_NewWindowRequested(Microsoft.Web.WebView2.Core.CoreWebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NewWindowRequestedEventArgs args)
{
args.NewWindow = (Microsoft.Web.WebView2.Core.CoreWebView2)sender;
args.GetDeferral().Complete();
}
Please use above code to open the new window opened within same main window.
I hope this would be helpful for your requirement.
Regards, Suresh.
@Suresh-BabuLV , Still have the issue. Able to recreate in below environment. Runtime:110.0.1587.69 sdk:1.0.1462.37
Fix is in runtime or in SDK?
Can you please try below html in webview2 sample? expectation is when we click on each link, it should activate opened popup in front and load the url.
<html>
<body>
<button onclick="OpenPopUp('https://www.google.com')">Link 1</button>
<button onclick="OpenPopUp('https://github.com/MicrosoftEdge/WebView2Feedback/issues')">Link 2</button>
<button onclick="OpenPopUp('https://github.com/MicrosoftEdge/WebView2Feedback/pulls')">Link 3</button>
<button onclick="OpenPopUp('https://github.com/MicrosoftEdge/WebView2Feedback/discussions')">Link 4</button>
<button onclick="OpenPopUp('https://docs.microsoft.com/en-us/microsoft-edge/webview2/release-notes')">Link 5</button>
<script>
function OpenPopUp(url) {
var myWindow = window.open(url, "PopWindow", "width=600,height=600");
}
</script>
</body>
</html>
@champnic, We are opening wpf screen in newwindow requested event and load the page. We have a control only for very first navigation. When we click the successive link we don't have any control to bring the window to front.it is reusing the existing wpf popup window and load the pages.
We do use third party browser that have browser activate event using that we had achieved this use case.
https://www.essentialobjects.com/doc/eo.webbrowser.webview.activate
Please advise.
@SureshkPerumal I just tried your HTML code in a WPF app and see the correct behavior, with the popup coming to foreground after clicking each button. Do you want to try again using the latest SDK and runtime?
@SureshkPerumal I just tried your HTML code in a WPF app and see the correct behavior, with the popup coming to foreground after clicking each button. Do you want to try again using the latest SDK and runtime?
Will check and update you.
I'm seeing this behavior in the WindowsAppSDK 1.3 and earlier when running from a fully installed packaged app. We have a WebView2 control that fills the entire screen and when calling window.open from that web view the new page shows up below the main window. We don't see this behavior when the app is launched from visual studio, only when the published msixbundle file is installed. We are not adding any extra code to the webview related to this.
Is this issue is addressed? we are still having this issue.