-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling push in main service worker vs. a background worker #3
Comments
W3C:
MDN:
Practically speaking, we can't make flutter apps run from different URLs, therefore, adding our own service worker (in the same scope) could mess with the default flutter one. Let's find a way to get this working without adding a service worker. That also prevents us from running into initialization problems with other variables/dependencies the app uses. |
FlutterFire, Firebase's Flutter library says the following: https://firebase.flutter.dev/docs/messaging/usage#background-messages
window.addEventListener('load', function () {
// ADD THIS LINE
navigator.serviceWorker.register('/firebase-messaging-sw.js');
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
// ...
}); So, the Flutter app isn't running in a worker. It's running on the main thread, attached to the DOM. that's why there's no reasonable way to make things better than running push stuff in JS. |
I don't know any open source Flutter apps that do webpush, much less apps that are also e2ee in dart. But the following JS implementations exist: mastodon-web: https://github.com/mastodon/mastodon/blob/main/app/javascript/mastodon/service_worker/web_push_notifications.js |
Another observation here. They register the push worker right before the flutter worker is registered. That ensures that the flutter worker is the 'active' (?) worker. Another way to do this is to register it in dart, so app devs don't have to manually register this each time. However, the main obstacle to that is that the lib would have to make sure the right 'flutter_service_worker.js' got registered once after the push worker. This could be done by only registering the service worker if it hasn't already been registered, so the first run of the app is the only one where flutter_service_worker isn't 'active'. However, this might be susceptible to browser timeout behaviors and other edge cases. IDK, maybe just imitating the Firebase architecture is the right choice here. |
Another question that needs to be asked and documented... Probably making it configurable by the app dev is the simplest solution |
This is something I need to investigate. The current implementation on my repo uses a background worker and passes push to the app when it's in the foreground, but that's not a good experience for app devs because the background worker doesn't have access to anything fancy (like keys for matrix).
The text was updated successfully, but these errors were encountered: