Skip to content
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

WebResourceRequested event not raised for ServiceWorker fetch #1114

Closed
James-Deadman-DDG opened this issue Mar 24, 2021 · 9 comments
Closed
Assignees
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@James-Deadman-DDG
Copy link

James-Deadman-DDG commented Mar 24, 2021

Description
When fetching through a service worker, WebView2 does not raise the WebResourceRequested event.

Version
SDK: 1.0.774.44 and 1.0.824-prerelease
Runtime: Beta 90.0.818.14
Framework: WPF
OS: Win10

Repro Steps

  • Create a service worker passing through a fetch (ServiceWorker.js)
self.addEventListener('install', (evt) => {
    self.skipWaiting();
});

self.addEventListener('activate', (evt) => {
    evt.waitUntil(self.clients.claim());
});

self.addEventListener('message', (event) => {
    console.log('message');
    if (event.data.action && event.data.action === 'fetch') {
        fetch(event.data.url)
            .then(r => {
                console.log('response received for ' + event.data.url);
                return r;
            });
    }
});

  • Create a client page, register the service worker and use it to fetch anything:
if ('serviceWorker' in navigator) {
    navigator.serviceWorker
        .register('ServiceWorker.js', { scope: './' })
        .then(registration => {
            if (registration.active) {
                registration.active.postMessage({ action: 'fetch', url: `data.json` });
            } else if (registration.installing) {
                registration.installing.addEventListener('statechange', () => {
                    if (registration.active) {
                        registration.active.postMessage({ action: 'fetch', url: `data.json` });
                    }
                });
            }
        });
}
  • Create a WPF application with a WebView2 control, handle its WebResourceRequested event and create a catch-all filter:
webView2.CoreWebView2InitializationCompleted += (s, e) =>
{
    webView2.CoreWebView2.AddWebResourceRequestedFilter("*", Microsoft.Web.WebView2.Core.CoreWebView2WebResourceContext.All);
    webView2.CoreWebView2.WebResourceRequested += (s, e) => Debug.WriteLine($"Web Request URI: {e.Request.Uri}");
};
  • Navigate to the client page
  • Check console output in the WebView2 control for the response received message. (The message containing data.json is present)
  • Check the VS output window for the Web Request URI message. (The message containing data.json missing)

AB#30969096

@James-Deadman-DDG James-Deadman-DDG added the bug Something isn't working label Mar 24, 2021
@champnic
Copy link
Member

Thanks for the bug report - I've linked this up with an existing issue on our backlog that we're going to take a look at!

@champnic champnic added the tracked We are tracking this work internally. label May 10, 2022
@mohitbagra
Copy link

Any update on this issue? We are facing the same. Weird thing is, it works fine if I open edge dev tools in the web view by pressing F12. Without the dev tools open, it doesnt work.

@champnic
Copy link
Member

@mohitbagra We are currently working on adding this support. It's past the design phase and is currently in the implementation phase. I'm assigning this issue to @vbryh-msft in case there's anything else to add.

@DexterWoo
Copy link

DexterWoo commented Jul 6, 2022

Any update on this issue?
is the feature implemented?
we actually wanted to develop an application that contains webapp as archive and want to provision everything into the serviceworker to boost the first startup experience.

@vbryh-msft
Copy link
Contributor

vbryh-msft commented Jul 6, 2022

@DexterWoo I'm actively working on the feature, will be out soon in prerelease =)

@vbryh-msft
Copy link
Contributor

AddWebResourceRequestedFilterWithRequestSourceKinds - COREWEBVIEW2_WEB_RESOURCE_REQUEST_SOURCE_KINDS_SERVICE_WORKER will cover service worker fetch.
SDK - NuGet Gallery | Microsoft.Web.WebView2 1.0.1340-prerelease
Please give it a try and let us know how it works for you.

@champnic champnic closed this as completed Apr 3, 2024
@roa-nyx
Copy link

roa-nyx commented Jun 28, 2024

This not working for me. I added:

			webview.CoreWebView2.AddWebResourceRequestedFilter($"abc://WebRoot/*",
				CoreWebView2WebResourceContext.All,
				CoreWebView2WebResourceRequestSourceKinds.All
			);

But I still get:

Fetch API cannot load godot-launcher://WebRoot/api/versions. URL scheme "abc" is not supported.

@Curve
Copy link

Curve commented Jul 22, 2024

This not working for me. I added:

			webview.CoreWebView2.AddWebResourceRequestedFilter($"abc://WebRoot/*",
				CoreWebView2WebResourceContext.All,
				CoreWebView2WebResourceRequestSourceKinds.All
			);

But I still get:

Fetch API cannot load godot-launcher://WebRoot/api/versions. URL scheme "abc" is not supported.

@champnic This is happening to me as well. JS fetch does not seem to work for custom schemes - I reckon this is a different issue though?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests

8 participants