This revision is primarily focused on codebase improvements all around. The code should be now much more readable and easy to comprehend as the responsibilities have been split into smaller pieces and composed as needed by each runtime context.
For end users of the library, the breaking changes aren't that "breaking", they'll just need to do a bit of import restructring. The API behaviour is mostly unchanged, with just minor exceptions.
- Runtime context is no longer automatically detected by
webext-bridge
. You must import the relevant part yourself depending on the context, eg:import Bridge from 'webext-bridge/window'
for a script that'll be running in the Window context. Learn more about the change here. setNamespace
is not available in any context exceptwindow
, andallowWindowMessaging
is not available in any context exceptcontent-script
.getCurrentContext
export has been removed.isInternalEndpoint
returnstrue
for some new contexts. In summary it'll betrue
forbackground
,content-script
,devtools
,popup
, andoptions
.- For messages sent from
background
, message queuing feature can no longer be trusted due to manifest v3 terminating the service worker runtime after certain time. The queue of messages sent frombackground
will be disposed off along with the termination of the said service worker. Queuing still works for messages sent from all other contexts.
- Fixed an issue with messages sometimes not reaching
content-script
orwindow
when being sent by some other context right after a tab had navigated forward or back. This was caused by old port'sonDisconnect
callback being called after the new port'sonConnect
callback. TheonDisconnect
would then remove the port mapping preventing messages from being routed tocontent-script
orwindow
. - If the message recipient terminates (tab closure for example) before replying to the sender, the sender will be notified about the session termination instead of it waiting indefinetly for a response
that's never coming back. Now, the
sendMessage
call in the sender will reject with an error.