madskristensen / WebEssentials.AspNetCore.ServiceWorker

Other
342 stars 61 forks source link

Request scheme 'chrome-extension' is unsupported #66

Open Siderite opened 4 years ago

Siderite commented 4 years ago

Uncaught (in promise) TypeError: Request scheme 'chrome-extension' is unsupported at serviceworker:26

I get this error in the console from cache.put(request, copy). I don't see any way to fix it without downloading the source code and changing it.

Siderite commented 4 years ago

The docs say that the Web cache API can only put http/https requests (https://developer.mozilla.org/en-US/docs/Web/API/Cache/put#Return_value). So this can be solved by adding a check in code like:

caches.open(version)
            .then(function (cache) {
                // here be the fix
                if (!/^https?:$/i.test(new URL(request.url).protocol)) return;
                cache.put(request, copy);
            });

used in CacheFingerprinted.js and CacheFirstSafe.js

Darkace01 commented 3 years ago

The docs say that the Web cache API can only put http/https requests (https://developer.mozilla.org/en-US/docs/Web/API/Cache/put#Return_value). So this can be solved by adding a check in code like:

caches.open(version)
            .then(function (cache) {
                // here be the fix
                if (!/^https?:$/i.test(new URL(request.url).protocol)) return;
                cache.put(request, copy);
            });

used in CacheFingerprinted.js and CacheFirstSafe.js

How do we add this to our code?

Darkace01 commented 3 years ago

I think I found a fix to it caches.open(version) .then(function (cache) { // here be the fix if(request.url.match("^(http|https)://")){ cache.put(request, copy); }else{ return; }

jolugama commented 3 years ago

yes, it's works. Thanks

kenneymyers commented 3 years ago

I think I found a fix to it caches.open(version) .then(function (cache) { // here be the fix if(request.url.match("^(http|https)://")){ cache.put(request, copy); }else{ return; }

How did you apply this fix? Is this something that can be merged into the nuget package so we can all benefit from the fix?

Darkace01 commented 3 years ago

I think I found a fix to it caches.open(version) .then(function (cache) { // here be the fix if(request.url.match("^(http|https)://")){ cache.put(request, copy); }else{ return; }

How did you apply this fix? Is this something that can be merged into the nuget package so we can all benefit from the fix?

I added that in my service worker.js file

I don't know if it could be added to the nugget package

I can try to figure out a way to make a pull request to the repo to fix this

kenneymyers commented 3 years ago

I went ahead and pulled down the source and just fixed it in the CacheFirstSafe.js, CacheFirst.js, and NetworkFirst.js. It seems to work well. Thank you!

Darkace01 commented 3 years ago

I went ahead and pulled down the source and just fixed it in the CacheFirstSafe.js, CacheFirst.js, and NetworkFirst.js. It seems to work well. Thank you!

84

Check out this pull request if it would help

xbaha commented 2 years ago

I got the same error, is this going to be merged in the next release?

Darkace01 commented 2 years ago

I think @madskristensen is working on the next release

Darkace01 commented 2 years ago

I got the same error, is this going to be merged in the next release?

Also I think you can just update your service worker directly before the release

xbaha commented 2 years ago

How do I update the service worker??

Darkace01 commented 2 years ago

you can create the service worker file but I think it is auto-created when you install the package