Skip to content

Commit

Permalink
fix: check for service worker support before registration (#32)
Browse files Browse the repository at this point in the history
* fix: check for service worker support before registration

* fix: ensure service worker is supported before registration

* fix: typo

---------

Co-authored-by: S. Amir Mohammad Najafi <[email protected]>
  • Loading branch information
arashagp and njfamirm authored Jan 9, 2025
1 parent fedbf3d commit c8cc5f4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/service-worker/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ export const serviceWorkerSignal = /* @__PURE__ */ new AlwatrSignal<{event: Serv
export async function registerServiceWorker(serviceWorkerPath: string): Promise<void> {
logger.logMethodArgs?.('registerServiceWorker', {serviceWorkerPath});

if (('serviceWorker' in navigator) === false) {
logger.incident?.('registerServiceWorker', 'service_worker_not_supported');
return;
}

try {
const swRegistration = await navigator.serviceWorker.register(serviceWorkerPath);
serviceWorkerSignal.notify({event: 'service_worker_registered'});
Expand Down

0 comments on commit c8cc5f4

Please sign in to comment.