Webview2 New Popup window requested but opened in external browser window and not focused in UWP app #3954
Replies: 13 comments
-
Hello Suresh, Could you please provide some of the following information while we get back to you: SDK: Thanks! |
Beta Was this translation helpful? Give feedback.
-
The documentation for NewWindowRequestedEventArgs.NewWindow says:
You are providing the same CoreWebView2 that has made the request and so it has already navigated. Instead, can you create a new CoreWebView2? If you intend for it to show in the same window, you can replace the old WebView2 control with a new WebView2 control and use the new WebView2 control's CoreWebView2 for the new window. Alternatively, you might also try cancelling the NewWindowRequested event (by setting Handled to true, and NewWindow to null), and then manually navigating the sender CoreWebView2 to the URI of the NewWindow request. The NewWindowRequested event has more requirements about the NewWindow because it has to connect the JS engine in the sender to the JS engine in the new window's. But if you are just discarding the previous CoreWebView2, then you could skip the NewWindow part and manually navigate the original CoreWebView2. |
Beta Was this translation helpful? Give feedback.
-
Great Thanks @david-risney, I have tried to setting handled property is true and args.Newwindow is null is getting error it's not accessible parameter. When New window request event triggers time to first created webview2 visibility setting as Visibily.collapsed Please provide more suggestions to resolve the Issue. Thanks in Advance. Regards, |
Beta Was this translation helpful? Give feedback.
-
Can you please paste the actual error message and the code around the error? I'm not sure what you are saying had the error or what the error was.
Also not sure exactly what you are saying here. Is there a new window, or do you have two WebView2 controls on the same grid? Are you saying that one has focus but it is not the one that is displayed? |
Beta Was this translation helpful? Give feedback.
-
Great Thanks @david-risney We have only one Webview2. Q. Also not sure exactly what you are saying here. Is there a new window, or do you have two WebView2 controls on the same grid? Are you saying that one has focus but it is not the one that is displayed? A. We have only one Webview2. When we click on Learn course which is opening new popup window behind the main window After your suggestion tried that second webview2 created and bind the source into that webview2 that one also not working as expected. Expected Behavior: New popup window need to open and active(Focus) on Main window Please Provide More suggestions to resolve this issue. Thanks in Advance Regards, |
Beta Was this translation helpful? Give feedback.
-
Thanks @david-risney, I have provided the screenshot of error. Regards, |
Beta Was this translation helpful? Give feedback.
-
Oh wow there's an AccessViolation when setting the property to null. That is not expected, but thankfully it defaults to null and we don't need to set the property to null. I've made a sample app https://github.com/david-risney/WebView2Samples/tree/uwp-new-window-playground (its in the uwp-new-window-playground branch) that shows different ways of handling the NewWindowRequested event. Are you able to reproduce your issue in this sample or does the sample help answer your question? How are you opening your new window? You said your app is UWP, is it also WinUI3? |
Beta Was this translation helpful? Give feedback.
-
@david-risney, Great Thanks. I sincerely appreciate your help. I have tried as your suggestions it's working as expected but here getting one more issue. Thanks in Advance Regards, |
Beta Was this translation helpful? Give feedback.
-
I'm using the sample app I referenced above with https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input in both the left and right WebView2s and I don't see issues with any of the HTML controls. Are you seeing the problem in the sample app and if so which URI are you on? |
Beta Was this translation helpful? Give feedback.
-
Great Thanks @david-risney, I have tested with this URL (Google website) Please suggest and guide to me. What can i do for enable to user controls are working whole embed second(right side) webview2. Regards, |
Beta Was this translation helpful? Give feedback.
-
I'm not sure. It sounds like you have a problem with either input or focus. @bradp0721 may be able to provide some suggestions. |
Beta Was this translation helpful? Give feedback.
-
Hi @bradp0721, @david-risney. Please provide your valuable suggestions and guide to inject JavaScript or any input html elements to enable the input controls or focus input controls in webview2. Thanks in Advance. Regards, |
Beta Was this translation helpful? Give feedback.
-
It sounds like input is working correctly in the sample app but not in your project? Is there something your project is doing differently? Can you try loading the same (or similar) html in into the sample app and see if that reproduces the input issue? |
Beta Was this translation helpful? Give feedback.
-
Hi Team,
We have developed one UWP app that app need to learn courses when we click on learn course window that window open in new popup window
**We are not able to see that new course window in UWP but try to see that new window to click Task manager to open that window in windows OS, It is not possible to see that New popup (Course) window in Kiosk Systems **
I have tried below code to open new course window on same(Main) window but blank window is opened
private void CoreWebView2_NewWindowRequested(Microsoft.Web.WebView2.Core.CoreWebView2 sender, Microsoft.Web.WebView2.Core.CoreWebView2NewWindowRequestedEventArgs args)
{
args.Handled = true;
args.NewWindow = (Microsoft.Web.WebView2.Core.CoreWebView2)sender;
args.GetDeferral().Complete();
}
Requirement:1. Open new popup course window in Same window
2.Focus that popup window on same(Main window)
I have tried alternate ways but doesn't work for me, Please provide your valuable suggestions to resolve this issue
Thanks in Advance
Regards,
Suresh.
Beta Was this translation helpful? Give feedback.
All reactions