This cleans up the logic for passing messages between popup.js/script.js and background.js, so that instead of determining the kind of message based on which properties the message object has, there is an explicit type property. This is more traditional and, in my experience, much easier to maintain and reason about. Plus it means that if you get a message you don't recognize it's easy to throw an appropriate error.
Also, it wraps up the message-passing logic so that errors in background.js propagate to the script which passed the message, and surfaces those errors in the popup. (Previously errors weren't being handled at all; in Firefox that would eventually trigger an error in the popup, when the sendMessage handler was garbage collected, but in Chrome that failure was completely silent.)
This cleans up the logic for passing messages between
popup.js
/script.js
andbackground.js
, so that instead of determining the kind of message based on which properties the message object has, there is an explicittype
property. This is more traditional and, in my experience, much easier to maintain and reason about. Plus it means that if you get a message you don't recognize it's easy to throw an appropriate error.Also, it wraps up the message-passing logic so that errors in
background.js
propagate to the script which passed the message, and surfaces those errors in the popup. (Previously errors weren't being handled at all; in Firefox that would eventually trigger an error in the popup, when thesendMessage
handler was garbage collected, but in Chrome that failure was completely silent.)