MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Problem/Bug]: WebResourceRequested not called from CSS with custom URI scheme

Open
#4,362 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
PowerShell
Stars
526
Forks
67
PR merge metrics
No merged PRs in 30d

Description

What happened?

Hello! I'm developing Embedded Desktop Application using webview2 like GUI. I want statically link resources, so I registered a custom URI scheme and add WebResourceRequested handler. I ran into a problem that loading resources in CSS does not trigger this event.

My CSS:

@font-face {
  font-family: 'Consolas Bold';
  src: url('res://consolasbold.woff2');
  font-weight: bold;
  font-style: normal;
  font-display: swap;
}

My WebResourceRequested handler: (cut down version)

HRESULT STDMETHODCALLTYPE Invoke(
    ICoreWebView2 *sender, ICoreWebView2WebResourceRequestedEventArgs *args) {
  ICoreWebView2WebResourceRequest *request{};
  LPWSTR requestUrl{};
  args->get_Request(&request);
  request->get_Uri(&requestUrl);
  std::printf("%ws\n", requestUrl);
  return S_OK;
}

My scheme registration code:

const WCHAR *allowedOrigins[1] = {L"*"};
auto customSchemeRegistration =
    Microsoft::WRL::Make<CoreWebView2CustomSchemeRegistration>(L"res");
customSchemeRegistration->put_TreatAsSecure(TRUE);
customSchemeRegistration->SetAllowedOrigins(1, allowedOrigins);
customSchemeRegistration->put_HasAuthorityComponent(TRUE);
ICoreWebView2CustomSchemeRegistration *registrations[1] = {
    customSchemeRegistration.Get()};
options->SetCustomSchemeRegistrations(
    1,
    static_cast<ICoreWebView2CustomSchemeRegistration **>(registrations));
Importance

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

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

No response

SDK Version

No response

Framework

Win32

Operating System

Windows 10

OS Version

No response

Repro steps

The behavior I expect is for the WebResourceRequested event to be raised when using a custom schema in CSS.
The current behavior outputs to me in the developer console: Failed to load resource: the server responded with a status of 401 (Unauthorized) and when refreshing the page GET res://consolasbold.woff2/ net::ERR_ABORTED 401 (Unauthorized)
Moreover, if you make the same request through the Fetch API in JavaScript, the resource is perfectly defined and obtained.
The only difference between these two requests that I found is the presence of "Origin: null" in the headers on the CSS side of the request

request made by CSS: (does not raise the WebResourceRequested event)
image
request executed JS: (raises the WebResourceRequested event)
image

Repros in Edge Browser

No

Regression

No, this never worked

Last working version (if regression)

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied Win32 WebView2 reproduction: register the res custom URI scheme, attach the WebResourceRequested handler, and load the @font-face CSS resource. Compare the CSS request with the working Fetch API request, especially the Origin header; done means the CSS request raises WebResourceRequested and the font loads successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
desktop, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.