亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

即使我有服務人員并且我的 PWA 工作正常,也沒有檢測到匹配的服務人員

即使我有服務人員并且我的 PWA 工作正常,也沒有檢測到匹配的服務人員

慕標5832272 2022-05-22 10:06:46
我一直在做一個用 HTML、CSS 和 JS 編寫的項目,并在屏幕上隨機顯示不同的視頻。我希望它是一個 PWA,所以它做到了。它工作得很好,但是當我打開 Chrome DevTools 和“應用程序”頁面時,在“清單”部分它會拋出一個警告:“沒有檢測到匹配的服務工作人員。您可能需要重新加載頁面,或者檢查服務工作人員的當前頁面還控制清單中的起始 URL?!蔽覍Ψ杖藛T了解不多,我想知道為什么它有效,但似乎無效。另一個問題是我從來沒有彈出“添加到主屏幕”。但是如果我手動添加它,它會完美運行。它也可以離線工作。網站鏈接:https ://ondersumer07.github.io/vinematik/我的 main.js 中的服務人員代碼:window.addEventListener("load", () => {  registerSW();});async function registerSW() {  if ('serviceWorker' in navigator) {    try {      await navigator.serviceWorker.register('./sw.js');    } catch (e) {      console.log(`SW registration failed`);    }  }}我的 sw.js://CACHING FILES//const filesToCache = [  './',  './offline.html',  './css/offline.css',];const staticCacheName = 'pages-cache-v2';self.addEventListener('install', event => {  console.log('Attempting to install service worker and cache static assets');  event.waitUntil(    caches.open(staticCacheName)    .then(cache => {      return cache.addAll(filesToCache);    })  );});//LOADING FILES WHEN OFFLINE//self.addEventListener('fetch', event => {  console.log('Fetch event for ', event.request.url);  event.respondWith(    caches.match(event.request)    .then(response => {      if (response) {        console.log('Found ', event.request.url, ' in cache');        return response;      }      console.log('Network request for ', event.request.url);      return fetch(event.request)        .then(response => {          // TODO 5 - Respond with custom 404 page          return caches.open(staticCacheName).then(cache => {            cache.put(event.request.url, response.clone());            return response;          });        });    }).catch(error => {      console.log('Error, ', error);      return caches.match('./offline.html');    })  );});// TODO 6 - Respond with custom offline pageself.addEventListener('activate', event => {  console.log('Activating new service worker...');  const cacheWhitelist = [staticCacheName];          }        })      );    })  );});
查看完整描述

1 回答

?
哈士奇WWW

TA貢獻1799條經驗 獲得超6個贊

解決方案是我沒有使manifest.jsonscope和start_url內部manifest.json相同,它需要是網站地址。所以我將代碼更改為:


  "start_url": "https://ondersumer07.github.io/vinematik/",

  "background_color": "#00adb5",

  "display": "standalone",

  "scope": "https://ondersumer07.github.io/vinematik/",

  "theme_color": "#00adb5"

問題就解決了。


查看完整回答
反對 回復 2022-05-22
  • 1 回答
  • 0 關注
  • 189 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號