tubearchivist / browser-extension

Tube Archivist Companion for your Browser
GNU General Public License v3.0
131 stars 18 forks source link

Refactor message passing and surface errors to users #18

Closed bakkot closed 1 year ago

bakkot commented 1 year ago

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.)

Screenshot 2023-02-11 at 5 03 48 PM Screenshot 2023-02-11 at 5 04 08 PM
bbilly1 commented 1 year ago

Sorry, took me some time.

Excellent work on this one, works like a charm. Very useful to see what exactly is wrong. Thanks for your contribution.