有没有办法指定我希望通知出现在屏幕上的时间?或者只是让它直到它关闭。这是代码:
self.addEventListener('notificationclick', function(event) {
//console.log('[Service Worker] Notification click Received.');
var url = event.notification.data.url;
//console.log('[Service Worker] event url = ' + url );
//console.log(event);
event.notification.close();
// ensure the browser doesn't terminate our service worker before our new window has been displayed.
event.waitUntil(
clients.openWindow( url )
);
});
您无法控制时间。但是您可以使用requireInteraction
标志使通知永久化(直到单击(。
更多信息: https://developer.mozilla.org/en-US/docs/Web/API/ServiceWorkerRegistration/showNotification