[英]Chrome & Firebase Push Notifications service worker not ready
遵循此代碼實驗室: https : //developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/
我下載了push-notifications.git
項目,並將最后的/completed/08-unsubscribe
示例上載到我的HTTPS Web服務器。
當我第一次訪問此頁面時,控制台日志顯示為:
Service Worker is supported
sw.js:24 Started
sw.js:28 Installed
sw.js:32 Activated
再次訪問該頁面的內容為:
Service Worker is supported
我要調試的問題是我沒有讓Service Worker is ready
從此函數輸出:
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('/sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(serviceWorkerRegistration) {
reg = serviceWorkerRegistration;
subscribeButton.disabled = false;
console.log('Service Worker is ready :^)', reg);
}).catch(function(error) {
console.log('Service Worker Error :^(', error);
});
}
阻止我的“訂閱”按鈕啟用並觸發console.log('Service Worker is ready :^)', reg);
的掛起在哪里console.log('Service Worker is ready :^)', reg);
還是console.log('Service Worker Error :^(', error);
消息?
您的代碼是正確的。 如果您提供控制台,它應該打印。 我驗證了,它有效。 只需在其中提供控制台即可進行檢查。
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('/sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(serviceWorkerRegistration) {
console.log('Service Worker is ready :^)', reg);
}).catch(function(error) {
console.log('Service Worker Error :^(', error);
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.