[PR #18] [MERGED] Refactor message passing and surface errors to users #46

Closed
opened 2026-03-23 20:32:14 +00:00 by mirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/tubearchivist/browser-extension/pull/18
Author: @bakkot
Created: 2/12/2023
Status: Merged
Merged: 2/20/2023
Merged by: @bbilly1

Base: masterHead: refactor


📝 Commits (5)

  • fbf1db6 refactor message passing between popup/background
  • 16a52bf surface errors to user in popup.js
  • ce827ef move logic into background.js
  • 5a59c4c split youtube message
  • ebb9247 handle errors from URL constructor

📊 Changes

5 files changed (+143 additions, -78 deletions)

View changed files

📝 extension/background.js (+76 -47)
📝 extension/index.html (+1 -0)
📝 extension/popup.js (+49 -22)
📝 extension/script.js (+12 -8)
📝 extension/style.css (+5 -1)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/tubearchivist/browser-extension/pull/18 **Author:** [@bakkot](https://github.com/bakkot) **Created:** 2/12/2023 **Status:** ✅ Merged **Merged:** 2/20/2023 **Merged by:** [@bbilly1](https://github.com/bbilly1) **Base:** `master` ← **Head:** `refactor` --- ### 📝 Commits (5) - [`fbf1db6`](https://github.com/tubearchivist/browser-extension/commit/fbf1db60bbc1b95afdc1c5be44a32b8f13c1bba9) refactor message passing between popup/background - [`16a52bf`](https://github.com/tubearchivist/browser-extension/commit/16a52bfdc7cf29a5a9728d9e554d619682fa27eb) surface errors to user in popup.js - [`ce827ef`](https://github.com/tubearchivist/browser-extension/commit/ce827efb05b64087e7f084d0e2cc0d1ef6414cf3) move logic into background.js - [`5a59c4c`](https://github.com/tubearchivist/browser-extension/commit/5a59c4c80bf48a3705dde198a187ee01a7f24a78) split youtube message - [`ebb9247`](https://github.com/tubearchivist/browser-extension/commit/ebb92473d5c97bd9a0254f1428305e4c943d2b39) handle errors from URL constructor ### 📊 Changes **5 files changed** (+143 additions, -78 deletions) <details> <summary>View changed files</summary> 📝 `extension/background.js` (+76 -47) 📝 `extension/index.html` (+1 -0) 📝 `extension/popup.js` (+49 -22) 📝 `extension/script.js` (+12 -8) 📝 `extension/style.css` (+5 -1) </details> ### 📄 Description 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](https://github.com/tubearchivist/browser-extension/blob/c7069d90cbd6ebf679190d8a322a6808f5516f26/extension/background.js#L181); 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.) <img width="371" alt="Screenshot 2023-02-11 at 5 03 48 PM" src="https://user-images.githubusercontent.com/1653598/218287660-1982b210-532e-4958-be95-f06023db8ed0.png"> <img width="371" alt="Screenshot 2023-02-11 at 5 04 08 PM" src="https://user-images.githubusercontent.com/1653598/218287661-260f0597-6e2f-463f-b378-3cd620e4394b.png"> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
mirror 2026-03-23 20:32:14 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tubearchivist/archived-browser-extension#46
No description provided.