Update content script and popup script communication #6
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.
This pull request updates the communication mechanism between the content script and the popup script in the Chrome extension. The changes aim to address issues related to the extension context being invalidated, message channel closure, and asynchronous responses.
Summary of Changes:
In the content script:
Modified fetchBookmarks to use a callback instead of returning a promise.
Updated event handlers (addNewBookmarkEventHandler and newVideoLoaded) to use the modified fetchBookmarks with callbacks.
Modified handleMessage to handle the DELETE type message using the modified fetchBookmarks with a callback.
In the popup script:
Modified onDelete to directly call the background page's handleMessage using chrome.runtime.getBackgroundPage.
Added a .then() block to handle the response from the background page, assuming it contains an updated list of bookmarks.
Updated viewBookmarks to accept currentBookmarks as a parameter and display the bookmarks accordingly.
In the manifest script:
Updated wrapper.js to wrap around SW. In the wrapper.js, there is a try/catch. This idea is taken from Simeon Vincent's post 24 Jun 2021, 19:12:58 (https://groups.google.com/a/chromium.org/g/chromium-extensions/c/POU6sW-I39M).
These changes provide a more reliable and efficient communication flow between the content script, popup script, and the background page. They address issues such as extension context invalidation, message channel closure, and asynchronous responses.
Please review and consider merging these updates into the main repository.