Conversation
rugk
commented
Aug 19, 2025
Member
Author
There was a problem hiding this comment.
The AI suggested these additional changes BTW, too, but the were too risky for me to include, through a cautionary look it seems to look good (but for AI stuff that means nothing, it often looks good on the first sight):
diff --git a/BrowserCommunication.js b/BrowserCommunication.js
index e8b0484..8451d1b 100644
--- a/BrowserCommunication.js
+++ b/BrowserCommunication.js
@@ -75,40 +75,25 @@ function handleMessages(request, sender, sendResponse) {
if (!(messageType in callbacks) || callbacks[messageType].length === 0) {
console.warn(`No callbacks for message type "${messageType}" registered.`);
- return true;
+ return;
}
// call all callbacks and keep return values
const promises = [];
- let gotTrueAsReturn = false;
for (const callback of callbacks[messageType]) {
const returnValue = callback(request, sender, sendResponse);
- // notice if return value is just "true"
- if (returnValue === true) {
- gotTrueAsReturn = true;
- continue;
+ // If the callback returns a Promise, add it to the list
+ if (returnValue && typeof returnValue.then === "function") {
+ promises.push(returnValue);
}
-
- // return value should be a Promise
- promises.push(returnValue);
}
- // handle returning
- if (gotTrueAsReturn) {
- if (callbacks[messageType].length !== 1) {
- // if it was not the only callback, then show a real error
- console.error(`At least one callback for message type "${messageType}" returned the legacy value "true".
- As you have registered ${callbacks[messageType].length} listeners this may lead to errors.`);
- } else {
- // show warning as this behaviour is discouraged
- console.warn(`At least one callback for message type "${messageType}" returned the legacy value "true". Please return a Promise instead.`);
- }
-
- return true;
+ if (promises.length > 0) {
+ // If there are async handlers, return a Promise
+ return Promise.all(promises);
}
-
- return Promise.all(promises);
+ // Otherwise, return nothing (void)
}
/**
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix(ts): use correct typing for JSDoc COMMUNICATION_MESSAGE_TYPE
Fixes #5