PlasmoHQ / plasmo

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

feat(external_messaging): Adds external messaging resolver #961

Closed sleekslush closed 2 months ago

sleekslush commented 2 months ago

Details

Introduces concept of external messaging handlers. By using the path of messages/external/, we can leverage the same messaging features, but they will be registered via chrome.runtime.onMessageExternal.addListener instead of chrome.runtime.onMessage.addListener.

This fixes an issue currently where all message handlers are being registered as internal AND external handlers, which can be unsafe.

You can either set up a message handler in background/messages/my-handler.ts , or background/messages/external/my-external-handler.ts. If you want a message handler to work in both contexts, symlink it ln -s background/messages/my-safe-handler.ts background/messages/external/my-safe-handler.ts.

Code of Conduct

Contacts

If your PR is accepted, we will award you with the Contributor role on Discord server.

To join the server, visit: https://www.plasmo.com/s/d

ivliag commented 2 months ago

The thing to notice - this actually breaks backwards compatibility, as currently registered external message handlers will stop working until moved to messages/external.