PlasmoHQ / plasmo

🧩 The Browser Extension Framework
https://www.plasmo.com
MIT License
10.26k stars 354 forks source link

[RFC] @plasmohq/gcm #3

Open raed667 opened 2 years ago

raed667 commented 2 years ago

What is the example you wish to see?

I would like to see a simple import / function call that abstracts away the hacky aspects of keeping the background service worker alive.

There are hacky solutions that would be nice to be abstracted away by a package:

https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension

Is there any context that might help us understand?

This feature might help migrate v2 extensions to v3 more easily.

Code of Conduct

louisgv commented 2 years ago

I was thinking about how this can be done cleanly. One thought so far is a module that developer import into their background SW, which facilitate all the hacky solution and official solution (like using fcm/gcm).

Rodrigue21 commented 2 years ago

Hello did you need someone to assist you

ColdSauce commented 2 years ago

We will definitely explore generic ways to lengthen a service worker's life, but I'm worried they will never be good enough and will likely be hacky/buggy, full of edge cases to consider. We'll probably have this functionality for people where MV3 completely breaks their extension, and nothing can be done to mitigate it.

One of the things I've been thinking about is to capture the most common use cases where a persistent service worker is necessary and come up with specific abstractions or examples on how to use them in Mv3 instead of building something generic.

For example, people used to store their Redux store in their background page in-memory. With MV3, it's no longer possible, so we built an example showcasing how to use Redux with chrome.storage instead.

The other use case we heard was that it'd be nice to wake a service worker up when an event outside of Chrome fires. The only way to do this, to my knowledge, is to use Firebase Cloud Messaging and have a server send a message to your extension, as that will wake a service worker up. Wrote up a blog post about that yesterday. If this is something people are super interested in, we can also think about building some server-side library/abstraction to make it easier to work with w.r.t. Chrome extensions.

If there's a use case y'all are dying to have, I'd love to hear about it, and we can work to see how it can be done using the MV3 architecture and write an example for it!

nahtnam commented 2 years ago

I would like to add that having a service worker active greatly increases the speed that the new tab page loads