Код: Выделить всё
test.htmlКод: Выделить всё
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("./sw.js", { scope: "/" }).then(
(registration) => {
console.log("Service worker registration succeeded:", registration);
},
(error) => {
console.error(`Service worker registration failed: ${error}`);
},
);
} else {
console.error("Service workers are not supported.");
}
[url=https://www.example.com]Visit Example[/url]
< /code>
sw.jsconsole.log('loaded')
self.addEventListener('fetch', function (event) {
console.log('fetch', event.request.url);
});
< /code>
Looking at my console:
loaded
fetch test.html
test.html:31 Service worker registration succeeded
fetch favicon.ico
favicon.ico:1 GET favicon.ico 404 (Not Found)
< /code>
So you can see above that it even blocks an attempt to load favicon.ico (host provider icon) but it doesn't block me if I click the link - I just go to example.com.
Подробнее здесь: https://stackoverflow.com/questions/797 ... -from-page
Мобильная версия