serversideup / webext-bridge

💬 Messaging in Web Extensions made easy. Batteries included.
https://serversideup.net/open-source/webext-bridge
MIT License
547 stars 50 forks source link

Reliable and safer messaging #38

Closed zikaari closed 2 years ago

zikaari commented 2 years ago

Fixes https://github.com/zikaari/webext-bridge/issues/23

Each message sent now relies on delivery receipts to ensure they were indeed delivered AND to expect the destination's response. In case the destination disconnects before it could have responded, sendMessage Promise will be rejected with an 'Transaction ended before it could complete'.

Queued messages are also no longer tracked in the background page, since it is ephemeral in manifest v3 extensions. Each endpoint now keeps track of its queued messages, and responses it is waiting on, in its on own runtime. This new strategy also acts as a safe-guard against destinations receiving stale messages from endpoints that no longer exist (previsouly this could happen as there was no message invalidation logic for when the sender disconneted).

The role of background page is no longer to maintain the "state" of the system, but to just act as a relay and to inform the relevant endpoints when the destination they are transacting with have been disconnected.