我正在尝试实施Google推送通知,但是服务工作者遇到问题。一切正常,但突然我开始在控制台中收到此错误消息。 当我从onMessage函数(当页面中的用户使用)调用函数ModifyVideoDoneWindow(payload)时,没有问题。 我认为问题在于范围。
错误:“未捕获(承诺)ReferenceError:未定义ModifyVideoDoneWindow”
// Initialize the Firebase app in the service worker by passing the config.
firebase.initializeApp(config);
self.addEventListener('notificationclick', (event) => {
event.waitUntil(self.clients.openWindow('http://localhost:8080/#videodone'));
event.notification.close();
});
// Retrieve an instance of Firebase Messaging so that it can handle background messages.
const messaging = firebase.messaging();
// Handle Messages, when the page is closed.
messaging.setBackgroundMessageHandler( (payload) => {
console.log('Received background message in the service worker PAYLOAD', payload);
console.log("Notification status: ", payload.data.status);
// Customize notification here
var notificationTitle = 'Video Making Tool';
var notificationOptions = {
body: 'Your video is ready.',
icon: '/logo......'
};
modifyVideoDoneWindow(payload);
return self.registration.showNotification(notificationTitle, notificationOptions);
});