This commit is contained in:
@@ -98,13 +98,18 @@ self.addEventListener('notificationclick', (event) => {
|
||||
clients.matchAll({ type: 'window', includeUncontrolled: true }),
|
||||
])
|
||||
.then(([urlToOpen, clientList]) => {
|
||||
const urlToOpenObj = new URL(urlToOpen, location.origin)
|
||||
for (const client of clientList) {
|
||||
console.log('client.url', client.url)
|
||||
if (client.url === urlToOpen && 'focus' in client) {
|
||||
const clientUrlObj = new URL(client.url)
|
||||
if (
|
||||
urlToOpenObj.pathname + urlToOpenObj.search ===
|
||||
clientUrlObj.pathname + clientUrlObj.search
|
||||
) {
|
||||
console.log('focus')
|
||||
|
||||
return Promise.all([
|
||||
client.focus(),
|
||||
'focus' in client && client.focus(),
|
||||
client.postMessage({
|
||||
type: 'notificationClick',
|
||||
tag: event.notification.tag,
|
||||
@@ -122,15 +127,14 @@ self.addEventListener('notificationclick', (event) => {
|
||||
if (!client) {
|
||||
console.log('new window not opened')
|
||||
for (const client of clientList) {
|
||||
return client.navigate(urlToOpen)
|
||||
// return client.postMessage({
|
||||
// type: 'notificationClick',
|
||||
// url: urlToOpen,
|
||||
// tag: event.notification.tag,
|
||||
// payload: event.notification.payload,
|
||||
// matchUrl: false,
|
||||
// msg: 'new window not opened',
|
||||
// })
|
||||
return client.postMessage({
|
||||
type: 'notificationClick',
|
||||
url: urlToOpen,
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
matchUrl: false,
|
||||
msg: 'new window not opened',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -138,15 +142,14 @@ self.addEventListener('notificationclick', (event) => {
|
||||
console.log('clients.openWindow not available')
|
||||
|
||||
for (const client of clientList) {
|
||||
return client.navigate(urlToOpen)
|
||||
// return client.postMessage({
|
||||
// type: 'notificationClick',
|
||||
// url: urlToOpen,
|
||||
// tag: event.notification.tag,
|
||||
// payload: event.notification.payload,
|
||||
// matchUrl: false,
|
||||
// msg: 'clients.openWindow not available',
|
||||
// })
|
||||
return client.postMessage({
|
||||
type: 'notificationClick',
|
||||
url: urlToOpen,
|
||||
tag: event.notification.tag,
|
||||
payload: event.notification.payload,
|
||||
matchUrl: false,
|
||||
msg: 'clients.openWindow not available',
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user