HomePhabricator
Diffusion Comm dfb3e013cfdd

[web] Handle notifications in service worker

Description

[web] Handle notifications in service worker

Summary:
This diff modifies the service worker to actually handle the push event and display a notification, additionaly it modifies the other events:

  • 'install' -> adds a skipWaiting so it will immediately take over the previous service worker
  • 'activate' -> clients.claim() so it will claim tabs that aren't controlled by a service worker (while this tab wouldn't have a event listener and wouldn't be able to navigate to a chat when user click a notification, we will still be able to focus on it)

event.waitUntil is needed because otherwise the browser could put the service worker to sleep before the promises are resolved.

Test Plan: Rest if the notification shows up after getting a push event

Reviewers: tomek, atul, kamil

Reviewed By: tomek

Subscribers: ashoat

Differential Revision: https://phab.comm.dev/D6832

Details

Provenance
Michal Gniadek <michal.gniadek@swmansion.com>Authored on Feb 21 2023, 8:19 AM
Reviewer
tomek
Differential Revision
D6832: [web] Handle notifications in service worker
Parents
rCOMM18ba2d595d52: [web] Add notification permission modal
Branches
Unknown
Tags
Unknown

Event Timeline