我正在使用带有 PWA 的 create-react-app 并且无法使用通知 api :(
这个错误:
Cannot read property 'showNotification' of undefined
我的代码
Notification.requestPermission(function(status) {
console.log("Notification permission status:", status);
});
async function displayNotification() {
if (Notification.permission === "granted") {
await navigator.serviceWorker.getRegistration().then(reg => {
reg.showNotification("Go go")
});
}
}
我不明白错误