# Summary
Issue
My app synchronises user data from the server to local storage. It does it for 3 reasons:
- offline stability if the server is inaccessible
- privacy, making the chrome extension storage the single source of truth with optional server syncing (so the user can change their mind about data locations)
- cost, get local cached data rather than expensive server loops
Example: keeping their preferences the same between home & office (sadly, chrome.storage.sync is not workable, see P4 below).
Right now, it seems polling is the only option. And an expensive one. Because Push requires user visual approval for Notifications (which the user is unlikely to grant), and MV3 denies any long running listeners.
Goal
Ideally, when the server has an update, it can silently push that fact to the background page, which can then opt to sync.
The performance/cost gain is significant. Rather than a chrome alarm polling a server every few minutes, it can respond to a pushed sync request that really only needs to be done on average once a day.
# Other Discussion
# Detailing The Problems
P1. For background syncing, Push Notifications / FCM are unworkable due to UI requests
From the user's POV, they just want to optionally 'log in to turn on preference syncing'.
If I use Web Push Notifications, or FCM, or chrome.gcm, the user has to approve to receive a Notifications UI. That makes no sense to them in the context of preference syncing.
They'd either need it lengthily explained to them ("it's a workaround"), or they'd deny it, and then be upset that the preference syncing appears to be broken.
In either case, they've had a poorer UX.
P2. With Manifest V3, there can be no long-running listeners
It was previously possible to achieve non-polled syncing by either:
- Set Firestore's .onSnapshot, which would callback in the client any time the server data changed.
- Setting up an EventSource for SSE, so our server could push requests to sync. (Albeit those are also short-lived, but a 30 mins timeout was more workable than MV3's 5 mins.)
I totally appreciate MV3's decision to prevent costly long-running listeners. But currently, that decision is forcing me to resort to polling. Which is not only similarly costly in computer resources, it actually costs a lot more in server resources.
P3. Support docs don't currently answer what 'wakes up' MV3 service worker
Supposing P1 is fixed, and FCM's onMessage works silently (wonderful!)... Will it continue to actually 'wake up' the service worker?
The question really is: which initial event listeners survive the ephemeral service worker (MV3) being stopped after the max 5 mins?
I gather that the native chrome.alarm, and chrome.runtime.onMessage can wake up the service worker (and expect the deprecated chrome.gcm would). My assumption is based on their namespace.
But given that FCM's onMessage is imported - and looks like any other non-native Javascript - will it be terminated with the service worker?
What about Web Push Notifications?
P4 Chrome.storage.sync is not viable for Gmail extensions
This would have been such an easy option for many use-cases!
Alas, it fails for the many-many accounts problem of Chrome login vs. Gmail login. The crux is that the data is synced to their Chrome logged in user, but within that, they can log in to many Gmail accounts. There's no guarantee those data repositories align.
I find this slightly hard to explain, so let me give an example: syncing Preferences for my Gmail extension, between a home computer and work.
At home, the user:
At work, the user:
From their POV, as the Chrome Extension is for Gmail, they expect their synchronised data to always sync for
a...@mycompany.com.
Despite them both having a keyed entry for
a...@mycompany.com, the data is siloed, and no synchronisation can occur.
Summarising the Problems
A silent/background Push Notification system that doesn't require visual Notifications approval would solve all the above.
It would:
- Improve performance (no polling)
- Be a better UX (don't make the user choose to opt in to something that doesn't make sense - or worse, have to understand an explanation of why it's a workaround)
- Facilitate privacy (make it possible to have chrome local storage the 'single source of truth' for their data, with the _option_ to sync if the user permits their data to touch a server)