N
N
newaitix2019-05-02 22:19:14
JavaScript
newaitix, 2019-05-02 22:19:14

Service Worker at Google Chrome Extension. I really want to, but it hurts?

Previously asked the question Why does caching not work?
The question concerns exactly the chrome extention.
I fetch templaters and they are not cached.
Then I remembered about sw and its power in appCatch.
He took his hands and pressed the buttons, it turned out.

if ('serviceWorker' in navigator) {
    window.addEventListener('load', function() {
        navigator.serviceWorker.register('/js/sw.js').then(function(registration) {
            console.log('ServiceWorker registration successful with scope: ', registration.scope);
        }).catch(function(err) {
            console.log('ServiceWorker registration failed: ', err);
        });
    });
}

sw.js
var CACHE_NAME = 'my-site-cache-v1';
var urlsToCache = [
  '/html/templater/popUpId.tpl',
  '/html/templater/bodyId.tpl',
  '/html/templater/topNavLog.tpl',
  '/html/templater/topNav.tpl',
  '/html/templater/bodyFailedAuth.tpl',
  '/html/templater/registration.tpl',
  '/html/templater/login.tpl',
  '/html/templater/syncToServ.tpl',
  '/html/templater/syncToPc.tpl',
  '/html/templater/emptySearch.tpl',
  '/html/templater/updateButton.tpl',
  '/html/templater/notification.tpl'
];
self.addEventListener('install', function(event) {
  event.waitUntil(
    caches.open(CACHE_NAME)
      .then(function(cache) {
        return cache.addAll(urlsToCache);
      })
  );
});

Ran.
Look in console and there sis.
ServiceWorker registration successful with scope
And then
Uncaught (in promise) TypeError: Add/AddAll does not support schemes other than "http" or "https"

Is it possible to somehow use sw in the Orthodox chrome-extension:// and not in this http of yours?
Are there any workarounds that anyone has come across? Fetschit not from local but from remote? Not a good idea as I'm claiming the "Offline Application" achievement.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question