WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

[Problem/Bug]: WebResourceRequested is not fired for a nested cross-origin iframe's subresources

Open taratari opened this issue 1 month ago • 0 comments

What happened?

Summary -

My issue looks and feels like the same problems as https://github.com/MicrosoftEdge/WebView2Feedback/issues/5376 and/or https://github.com/MicrosoftEdge/WebView2Feedback/issues/4447 but those are quite vague so I wanted to create this one with more information. I'm not seeing any WebResourceRequested events raised for a nested cross-origin iframe's subresources that are being loaded for the filter we have set. I've been able to narrow it down a bit: the event is raised for a nested cross-origin iframe's navigation, but never for that iframe's subresources, even with a catch-all filter and SOURCE_KINDS_ALL.

Ex:

Frame structure

https://app.contoso.com/page            (top-level document)
  └─ <iframe src="https://widget.fabrikam.com/">        cross-site to top
       └─ <iframe src="https://data.contoso.com/view">  cross-site to its parent, same-site to top
            ├─ <script src="https://data.contoso.com/vendor.js">
            └─ <script src="https://data.contoso.com/main.js">

Filter registration (before the first navigation, on a controller that had never navigated)

wil::com_ptr<ICoreWebView2_22> webView22 = webView.query<ICoreWebView2_22>();
webView22->AddWebResourceRequestedFilterWithRequestSourceKinds(
    L"*",
    COREWEBVIEW2_WEB_RESOURCE_CONTEXT_ALL,
    COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_ALL);   // returns S_OK
webView->add_WebResourceRequested(handler, &token);

What we observe (handler logs every raised request; compared against a DevTools HAR of the same session)

Request Raised?
Top-level document and its subresources Yes
widget.fabrikam.com iframe navigation and all its subresources Yes
data.contoso.com/view iframe navigation Yes
data.contoso.com/vendor.js, main.js (parser-initiated <script>, same-origin to that iframe) No

Every request that was raised reported RequestedSourceKind == COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_DOCUMENT. The missing requests do show up in the HAR, so they are made; they just never reach WebResourceRequested. We use the event to add a header, so those requests go out unmodified.

What we ruled out

  • Filter pattern / source kind: same result with a host-specific pattern + DOCUMENT and with L"*" + ALL.
  • Filter timing: same result when every WebView was created fresh and had its filters added before its first navigation.
  • Using the old AddWebResourceRequestedFilter instead is worse: nothing inside the first cross-origin iframe is raised at all (as documented to use WithRequestSourceKinds).

Questions

  1. Is this expected behavior or a known limitation for subresources of a frame nested inside another cross-origin (out-of-process) frame?
  2. Is there a flag or workaround to get these requests raised?

Please let me know if there is anything else I can try to provide. The reason why this is essential for our workflow is to replace CEF (where this works) in favor of WebView2 with the need to inject our OAuth Authorization header tokens for any cross-origin sites that we embed that call back into our side. I would imagine this would be broken for anyone else that is trying to stay to the RFC spec's for OAuth https://www.rfc-editor.org/info/rfc6749/#section-7.1 & https://www.rfc-editor.org/info/rfc6750/#section-2.1.

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

155.0.4283.60

SDK Version

1.0.3485.44

Framework

Win32

Operating System

Windows 11

OS Version

10.0.26100 24H2

Repro steps

see the summary.

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Don't know

Last working version (if regression)

No response

AB#64807360

taratari avatar Oct 17 '26 14:10 taratari