test web push
Main daploy / deploy (push) Successful in 45s

This commit is contained in:
2024-11-21 16:11:23 +02:00
parent 14e8a349e6
commit 75be87c144
14 changed files with 438 additions and 63 deletions
+30 -17
View File
@@ -34,28 +34,41 @@ self.addEventListener('push', (event) => {
})
self.addEventListener('notificationclick', (event) => {
console.log('клик на уведомление', event.notification)
event.notification.close()
// Открытие URL из данных уведомления
event.waitUntil(
clients.matchAll({ type: 'window' }).then((clientList) => {
for (const client of clientList) {
if (client.url === event.notification.data.url && 'focus' in client) {
console.log('клик на уведомление', event.notification.tag)
clients
.matchAll({ type: 'window', includeUncontrolled: true })
.then((clientList) => {
for (const client of clientList) {
console.log('client.url', client.url)
if (client.url === event.notification.data.url && 'focus' in client) {
console.log('фокус')
return Promise.all([
client.focus(),
client.postMessage({
type: 'notificationClick',
tag: event.notification.tag,
payload: event.notification.payload,
}),
])
return Promise.all([
client.focus(),
client.postMessage({
type: 'notificationClick',
tag: event.notification.tag,
payload: event.notification.payload,
}),
])
}
}
}
if (clients.openWindow) {
return clients.openWindow(event.notification.data.url)
}
}),
if (clients.openWindow) {
console.log('новое окно')
return clients.openWindow(event.notification.data.url).then((client) => {
if (client) {
return client.focus()
}
console.log('новое окно не открылось')
})
}
})
.catch((error) => {
console.error(error)
}),
)
})