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

Uncaught (in promise) TypeError: Request scheme 'chrome-extension' is unsupported #1

Open
masumonline opened this issue May 26, 2019 · 12 comments

Comments

@masumonline
Copy link

When i try to refresh the page. i get this error.

Capture

@InSantoshMahto
Copy link

I am also getting same error .

@raylee
Copy link

raylee commented Jun 11, 2019

@MirajMenon
Copy link

@masumonline , @InSantoshMahto, @iamshaunjp Anyone who fixed this error?

@InSantoshMahto
Copy link

InSantoshMahto commented Sep 4, 2019

hey, I have solved this issue in this way.

  // check if request is made by chrome extensions or web page
  // if request is made for web page url must contains http.
  if (!(evt.request.url.indexOf('http') === 0)) return; // skip the request. if request is not made with http protocol


whole code for fetch event:

// fetch event
self.addEventListener('fetch', evt => {
  // check if request is made by chrome extensions or web page
  // if request is made for web page url must contains http.
  if (!(evt.request.url.indexOf('http') === 0)) return; // skip the request. if request is not made with http protocol

  evt.respondWith(
    caches
      .match(evt.request)
      .then(
        cacheRes =>
          cacheRes ||
          fetch(evt.request).then(fetchRes =>
            caches.open(dynamicNames).then(cache => {
              cache.put(evt.request.url, fetchRes.clone());
              // check cached items size
              limitCacheSize(dynamicNames, 75);
              return fetchRes;
            })
          )
      )
      .catch(() => caches.match('/fallback'))
  );
});

// cache size limit function
const limitCacheSize = (name, size) => {
  caches.open(name).then(cache => {
    cache.keys().then(keys => {
      if (keys.length > size) {
        cache.delete(keys[0]).then(limitCacheSize(name, size));
      }
    });
  });
};


my service worker script: ### https://teckat.com/sw.js

@riuann23
Copy link

riuann23 commented Apr 2, 2020

hey, I have solved this issue in this way.

  // check if request is made by chrome extensions or web page
  // if request is made for web page url must contains http.
  if (!(evt.request.url.indexOf('http') === 0)) return; // skip the request. if request is not made with http protocol

whole code for fetch event:

// fetch event
self.addEventListener('fetch', evt => {
  // check if request is made by chrome extensions or web page
  // if request is made for web page url must contains http.
  if (!(evt.request.url.indexOf('http') === 0)) return; // skip the request. if request is not made with http protocol

  evt.respondWith(
    caches
      .match(evt.request)
      .then(
        cacheRes =>
          cacheRes ||
          fetch(evt.request).then(fetchRes =>
            caches.open(dynamicNames).then(cache => {
              cache.put(evt.request.url, fetchRes.clone());
              // check cached items size
              limitCacheSize(dynamicNames, 75);
              return fetchRes;
            })
          )
      )
      .catch(() => caches.match('/fallback'))
  );
});

// cache size limit function
const limitCacheSize = (name, size) => {
  caches.open(name).then(cache => {
    cache.keys().then(keys => {
      if (keys.length > size) {
        cache.delete(keys[0]).then(limitCacheSize(name, size));
      }
    });
  });
};

my service worker script: ### https://teckat.com/sw.js

Thanks for this!!

@ahmad-ali14
Copy link

ahmad-ali14 commented Aug 8, 2020

#1 (comment)
perfect answer

@justingolden21
Copy link

Wouldn't that also detect any https requests as well and block all of yours? I saw the SO post and decided against because I figured it would do that. If it "works on your machine" it's probably just localhost, right?

@justingolden21
Copy link

I tried adding:

caches.match(evt.request).then(cacheRes => {
			return cacheRes || fetch(evt.request).then(fetchRes => {
				return caches.open(dynamicCacheName).then(cache => {
+					if (new RegExp('^(?:[a-z]+:)?//', 'i').test(new URL(evt.request.url).protocol) ) return;
					cache.put(evt.request.url, fetchRes.clone());

According to these links:

https://stackoverflow.com/a/19709846/4907950

madskristensen/WebEssentials.AspNetCore.ServiceWorker#66

But still no use. Are we sure that http is the problem?

@Darkace01
Copy link

So what I did was to check if the url if it doesn't starts with http or https
caches.open(version) .then(function (cache) { // here be the fix if(request.url.match("^(http|https)://")){ cache.put(request, copy); }else{ return; }

@emekaelo
Copy link

I tried adding:

caches.match(evt.request).then(cacheRes => {
			return cacheRes || fetch(evt.request).then(fetchRes => {
				return caches.open(dynamicCacheName).then(cache => {
+					if (new RegExp('^(?:[a-z]+:)?//', 'i').test(new URL(evt.request.url).protocol) ) return;
					cache.put(evt.request.url, fetchRes.clone());

According to these links:

https://stackoverflow.com/a/19709846/4907950

madskristensen/WebEssentials.AspNetCore.ServiceWorker#66

But still no use. Are we sure that http is the problem?

According to the comments in the solution, the code is checking if the url of the request being made contains 'http'.
A browser extension is trying to make a request which is causing the error. The request from the extension does not have http in its url (example) so this line of code if (!(evt.request.url.indexOf('http') === 0)) return; terminates the code if there is no 'http' in the request url (which is from the extension)

@Zibri
Copy link

Zibri commented Nov 18, 2022

self.addEventListener("fetch", event=>{
    event.respondWith(caches.open(cacheName).then(cache=>{
        return cache.match(event.request).then(response=>{
            return response || fetch(event.request).then(networkResponse=>{
                if (!(event.request.url.indexOf('chr') === 0)) cache.put(event.request, networkResponse.clone());
                return networkResponse;
            }
            );
        }
        )
    }
    ));
}
);

@ImieboGodson
Copy link

Wouldn't that also detect any https requests as well and block all of yours? I saw the SO post and decided against because I figured it would do that. If it "works on your machine" it's probably just localhost, right?

No, it wont. As long as the http is at index 0, that statement returns true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests