Trying to write a Service Worker for my PWA app, caugth this error. I used Google/Mozilla samples for service workers, but, anyway.
var CACHE_NAME = 'test-cache';
var urlsToCache = [
'/'
];
self.addEventListener('install', function (event) {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function (cache) {
console.log('Opened cache');
return cache.addAll(urlsToCache);
})
);
});
Use window.self
instead of self
.
You can explicitly remove self
from the no-restricted-globals rule or simply disable the rule for the line containing self
using eslint-disable-line
or eslint-disable-next-line
:
self.addEventListener('install', function (event) { /* eslint-disable-line no-restricted-globals */
...
Or
/* eslint-disable-next-line no-restricted-globals */
self.addEventListener('install', function (event) {
...
Add var self = this;
or use this.addEventListener(...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With