0

So I know there are a couple of standard service worker events and events in extension namespaces that my extension can react to and which can awake it. The question is when I use event listeners from 3rd party module (I'm using supabase specifically) will they wake the extension service worker? For example, in supabase we have onAuthStateChange event which triggers every time an auth event happens (i.e. refresh token's expired). But if my service worker's asleep? Will it be fired/will that kind of event wake the service worker? Supabase listener's declared in the global scope of the service worker, of course.

MCVE: background.ts

import supabase from 'API/client';

chrome.runtime.onInstalled.addListener((details: chrome.runtime.InstalledDetails) => {
  if (details.reason === 'update') {
    chrome.storage.local.set({ lastSyncSnapshot: null });
  }
});

supabase.auth.onAuthStateChange((event: any, session: any) => {
  if (event == 'TOKEN_REFRESHED') {
    chrome.storage.local.set({ session: session });
  }
});

  • @wOxxOm it is actually at the top of the service worker, I register it synchronously. so there shouldn't be any issues in that case? – John Jethro Rashbold May 18 '23 at 11:45
  • @wOxxOm take a look once more please if it's more clear now. but from what I can experience and see atm it doesn't work. as soon as SW falls asleep I don't receive any realtime updates from supabase. – John Jethro Rashbold May 21 '23 at 18:34
  • 1
    Yes, only `chrome` events and SW messaging/fetch events wake the SW up. See [Persistent Service Worker in Chrome Extension](https://stackoverflow.com/a/66618269) – wOxxOm May 21 '23 at 19:42

0 Answers0