'use strict';
if ('serviceWorker' in navigator) {
console.log('Service Worker is supported');
navigator.serviceWorker.register('/sw.js').then(function() {
return navigator.serviceWorker.ready;
}).then(function(reg) {
console.log('Service Worker is ready :^)', reg);
reg.pushManager.subscribe({userVisibleOnly:true}).then(function(sub) {
isPushEnabled = true;
console.log('endpoint:', sub.endpoint);
});
}).catch(function(error) {
console.log('Service Worker Error :^(', error);
});
}
这是我的main.js文件,问题是订阅功能不起作用,其中的console.log函数没有显示值,也没有显示错误。我正在关注 this tutorial as it is