-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Problem/Bug]: CoreWebView2.AddWebResourceRequestedFilter("*", Document) doesn't work for secondary WebViews in the same process #4689
Comments
Further testing shows that occasionally, the WebResourceRequested event fails to fire for the primary form as well. We have not been able to establish a pattern here. Perhaps this is really the same issue as #2341. However, that seems to indicate that the event never fires but, in our testing, it seems to fire about half of the times for the main window. |
Hi, it seems your iframe may be a different origin, which would prevent you from getting WebResourceRequested event for such iframes. For this one, you'd need to use the |
Hi, thanks for the recommendation. Specifying ResourceSourceKinds.All for the third parameter seems to address the erratic behavior we were seeing on the primary form/WebView2 control. However, it doesn't help getting the event to fire on the secondary form/WebView2 controls. I tried with ResourceContext.All in addition to ResourceSourceKinds.All as well. To reiterate, on those forms, it fires for "prefix:" URLs just not for "anythingElse:". On the off chance that the bug was specific to "", I tried replacing the "" filter with "https://" and "http://" but that didn't work either. To provide a little more information, we are intercepting the NewWindowRequested event, created a new form, and assigning args.NewWindow = newForm.WebView2Control.CoreWebWebView2. |
✅ Successfully linked to Azure Boards work item(s): |
Hi, It's good to see that a work item has been created for this. Is there any status update that can be shared? |
We are currently looking into it; will keep you posted here if there's any updates |
Hi @Manish3177 , when I try with our .NET sample app on an opened window with WebView2, I see the WebResourceRequested event fires for document when I add the filter as expected. For the opened window, are you registering the filter and WebResourceRequested event before or after you set the NewWindow property? In past we had some timing issues with the event not being registered on time for the first navigation of an opened WebView. Could you try changing the order you add the filter and the event to setting the NewWindow property to see if helps? You can try the following options: |
Hi Çağrı, Our code currently attaches all event handlers, including the one for WebResourceRequested event, right after awaiting the call to webView.EnsureCoreWebView2Async. While we have not tried exactly what you are suggesting, we have tried attaching the event handler for WebResourceRequested on the first NavigationCompleted event firing. That helped a little bit in that, it was able to catch subsequent navigations of the top level window but it still didn't catch any navigations of iframes within that window. I will try to get a minimal repro app out to you sometime next week. Ultimately, the event not firing reliably is a deal breaker for us. Even if it were to work 99% of the times on being attached in a strategic place, that would still not be good enough. Placing it in a very specific place seems fragile and inspires a feeling of uneasiness that it may not work under certain circumstances/configurations. Despite some problems with [Frame]NavigationStarting events, since those are 100% reliable, I think we will implement our solution using those for now. The problems with those don't have as severe an impact. Also, we think we can find workarounds to those but not this problem. |
Can you try adding the event handler and the filter after setting the NewWindow property as per NewWindow remarks? |
Closing this for now as I haven't heard back from you. Feel free to re-open if you are still running into this after trying (#4689 (comment)) |
What happened?
We have an application where we want to inspect each frame-navigation and run some logic asynchronously to figure out if we want to allow that navigation. Failing that check, we want the iframe to stay on the page where the link was clicked. To achieve that, we first tried using the FrameNavigationStarting event whose args even have a Cancel property. The problem that made it not usable for us was that the args don't allow deferral so we couldn't run our asynchronous check.
As an alternative, we attempted using WebResourceRequested event which does support args.GetDeferral() method. We set up the following filters to intercept all navigation requests and some requests with a certain prefix:
This works fine for the first WebView2 control we create on our main form of our application. We also create additional forms with new WebView2 controls and wire them up using the exact same code. However, the first filter does not work. Interestingly, the second filter does! I have tried changing the second parameter for first filter to All as well but it doesn't help.
Importance
Important. My app's user experience is significantly compromised.
Runtime Channel
Stable release (WebView2 Runtime)
Runtime Version
126.0.2592.102
SDK Version
1.0.2535.41
Framework
Winforms
Operating System
Windows 11
OS Version
10.0.22631.3737
Repro steps
Steps to reproduce and relevant code is included in the problem description.
Repros in Edge Browser
No, issue does not reproduce in the corresponding Edge version
Regression
No, this never worked
Last working version (if regression)
No response
AB#52931928
The text was updated successfully, but these errors were encountered: