我需要知道如何向客户端发送无法获取的请求:
self.addEventListener('install', async ()=>{
event.waitUntil(caches.open(CACHE_NAME).then((cache)=>
cache.addAll(urlsToCache)
));
});
我需要在客户端接收它。就像是:
//client.js
var reg=Navigator.serviceWorker.register('sw.js');
Navigator.serviceWorker.onerror=(ev)=>{
document.getElementById('err1').textContent = ev.data.message;
}
// sw.js
self.addEventListener('install', async (ev)=>{
event.waitUntil(caches.open(CACHE_NAME).then((cache)=>
cache.addAll(urlsToCache)
).catch((err)=>{
var client = clients.get(ev.clientId); // ev does not have clientId
client.postMessage(err.offendingRequest); // offendingRequest does not exist
}));
});