PlasmoHQ / plasmo

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

[RFC] Progressive migration for messaging #829

Open samdoeswork opened 9 months ago

samdoeswork commented 9 months ago

How do you envision this feature/change to look/work like?

If you already have a chrome.runtime.onMessage.addListener, then messaging does not work.

This makes it unrealistically challenging to migrate an existing app - as every single command needs to be migrated simultaneously.

I think it would be quite strightforward to provide a migration-path:

  1. When sending events, add a "plasmoVersion: x" - or some other metadata which makes it clear this was a framework-sent event
  2. Provide a method to manually trigger the Plasmo event handler

This way if you need to run the listener yourself, you can check for the existence of plasmoVersion on the event & pass it through to Plasmo's handler.

I am proposing "plasmoVersion" as the key here because it's extremely unlikely to have collisions (unlike something like "from").

What is the purpose of this change/feature? Why?

To provide a gradual migration path with existing projects which already have listeners (or anyone who needs to have a listener for any other purpose).

(OPTIONAL) Example implementations

No response

(OPTIONAL) Contribution

Verify canary release

Code of Conduct