MicrosoftEdge / MicrosoftEdge/WebView2Feedback

[Feature]: Support WebResourceRequested event on the same domain used as virtual hostname (SetVirtualHostNameToFolderMapping

Open
#4,201 8 comments 0 reactions 1 assignee View on GitHub

@Lakshmisha-KS is already working on this.

Since Feb 12, 2025.

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

Description

Describe the feature/enhancement you need

When a web resource requested filter added with the AddWebResourceRequestedFilter method uses the same hostname as the one specified as a virtual hostname with the SetVirtualHostNameToFolderMapping method, the WebResourceRequested event is not fired.

If a requested web resource does not exist in the folder that is virtually hosted, it should fallback on the WebResourceRequested event to handle the request if a filter was added for that url.

The scenario/use case where you would use this feature

Our web application will be hosted either with nginx or in a webview2 in a windows application. When hosted with nginx, we forward data requests to our backend. So our web pages use relative paths to access data. When hosted in a windows application, the web application is virtually hosted and the data requests will be handled locally in process with the WebResourceRequested event.

Since the same web pages are hosted in 2 environments, we'd prefer not to have to adapt all the pages to specify a different domain and leave the data requests relative to the web application.

webView.CoreWebView2.SetVirtualHostNameToFolderMapping("test.fred", @"c:\dev\website1", Microsoft.Web.WebView2.Core.CoreWebView2HostResourceAccessKind.Allow); webView.CoreWebView2.AddWebResourceRequestedFilter("http://test.fred/api/*", CoreWebView2WebResourceContext.All); webView.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested;

How important is this request to you?

Nice to have. There are other ways to tackle this, but having official API support would be beneficial.

Suggested implementation

When a requested resource does not exist in the folder that is virtually hosted and there's a web resource requested filter added on the same hostname, the WebResourceRequested is fired to allow to handle the request.

Alternatively, it could be argued that the WebResourceRequested might have priority and allow to cancelled the handling of the resource by the virtual hostname mapping.

What does your app do? Is there a pending deadline for this request?

The application hosted in a webview2 control (and with nginx) is the production build of a React web application. Nginx acts as a reverse proxy to our backend server therefore, all data requests are sent to the same hostname as the web application

Eg : http://somedomain.net/reactapp/index.html

JavaScript data requests : fetch("/api/data/stops", ...); // Full url is http://somedomain.net/reactapp/api/data/stops

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.