UI Push Deep Links und Drive Diagnose verbessern
All checks were successful
CI / Build and Deploy (push) Successful in 2m30s
All checks were successful
CI / Build and Deploy (push) Successful in 2m30s
This commit is contained in:
19
public/sw.js
19
public/sw.js
@@ -62,18 +62,27 @@ self.addEventListener("push", (event) => {
|
||||
|
||||
self.addEventListener("notificationclick", (event) => {
|
||||
event.notification.close();
|
||||
const targetUrl = new URL(event.notification.data?.url || "/", self.location.origin).href;
|
||||
const targetUrl = new URL(event.notification.data?.url || "/", self.location.origin);
|
||||
|
||||
event.waitUntil(
|
||||
clients.matchAll({ type: "window", includeUncontrolled: true }).then((clientList) => {
|
||||
clients.matchAll({ type: "window", includeUncontrolled: true }).then(async (clientList) => {
|
||||
for (const client of clientList) {
|
||||
if ("focus" in client) {
|
||||
client.navigate(targetUrl);
|
||||
const clientUrl = new URL(client.url);
|
||||
|
||||
if (clientUrl.origin === targetUrl.origin && "focus" in client) {
|
||||
if ("navigate" in client) {
|
||||
await client.navigate(targetUrl.href).catch(() => null);
|
||||
}
|
||||
|
||||
return client.focus();
|
||||
}
|
||||
}
|
||||
|
||||
return clients.openWindow(targetUrl);
|
||||
if (clients.openWindow) {
|
||||
return clients.openWindow(targetUrl.href);
|
||||
}
|
||||
|
||||
return undefined;
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user