open url by send message to page
Deploy frontend / frontend (push) Successful in 1m3s

This commit is contained in:
2024-12-02 19:08:39 +02:00
parent de8496395b
commit 7b5cfebe80
2 changed files with 28 additions and 21 deletions
+26 -19
View File
@@ -104,31 +104,39 @@ self.addEventListener('notificationclick', (event) => {
console.log('focus')
return Promise.all([
client.focus(),
client.postMessage({
type: 'notificationClick',
tag: event.notification.tag,
payload: event.notification.payload,
matchUrl: true,
}),
client.focus(),
])
}
}
return Promise.resolve()
.then(() => {
if (!clients.openWindow) {
throw new Error('clients.openWindow not available')
}
return clients.openWindow(urlToOpen).then((newClient) => {
if (!newClient) {
throw new Error('new window not opened')
}
})
})
.catch((error) => {
console.debug('Error', error)
if (clients.openWindow) {
console.log('open new window', urlToOpen)
return clients.openWindow(urlToOpen).then((client) => {
if (!client) {
console.log('new window not opened')
for (const client of clientList) {
client.postMessage({
type: 'notificationClick',
url: urlToOpen,
tag: event.notification.tag,
payload: event.notification.payload,
matchUrl: false,
msg: 'new window not opened',
})
break
}
}
})
} else {
console.log('clients.openWindow not available')
for (const client of clientList) {
return Promise.all([
client.postMessage({
type: 'notificationClick',
url: urlToOpen,
@@ -136,11 +144,10 @@ self.addEventListener('notificationclick', (event) => {
payload: event.notification.payload,
matchUrl: false,
msg: 'clients.openWindow not available',
}),
client.focus(),
])
}
})
break
}
}
})
.catch((error) => {
+1 -1
View File
@@ -65,7 +65,7 @@ app.use(PrimeVue, {
app.mount('#app')
registerServiceWorker()
.then((registration) => {
.then(() => {
console.log('Service Worker успешно зарегистрирован')
navigator.serviceWorker.addEventListener('message', (event) => {
console.debug('serviceWorker message', event.data)