[Webkit-unassigned] [Bug 252544] If a Home Screen Web App is backgrounded and tries to focus() a ServiceWorkerWindowClient in a notificationclick handler, the focus() promise rejects

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Mar 7 19:01:24 PST 2023


https://bugs.webkit.org/show_bug.cgi?id=252544

--- Comment #10 from lehu <hi at lehu.in> ---
I will not change the live demo site since now. 

And here is the current code of https://taoshu.in/web/push-demo/sw.js, in which I just commented out three lines of code.

function receivePushNotification(event) {
  console.log("[Service Worker] Push Received.");

  const { title, body, data } = event.data.json();

  const options = {
    body: body,
    data: data, 
  };

  event.waitUntil(self.registration.showNotification(title, options));
}

async function openPushNotification(event) {
  console.log("[Service Worker] Notification click Received.", event);

  event.notification.close();
  event.waitUntil((async () => {
    const allClients = await clients.matchAll({ type: 'window' });

    for (const client of allClients) {
      // if (!client.focused) {
      //   await client.focus().catch(e => { console.log(e) });
      // }
      client.postMessage(event.notification.data);
      return;
    }

    let url = event.target.registration.scope;
    let w = await clients.openWindow(url);
    w.postMessage(event.notification.data);
  })());
}

self.addEventListener("push", receivePushNotification);
self.addEventListener("notificationclick", openPushNotification);

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20230308/b8165979/attachment.htm>


More information about the webkit-unassigned mailing list