Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update content script and popup script communication #6

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

cnm13ryan
Copy link

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.

cnm13ryan added 5 commits July 3, 2023 20:42
    Continue to fix on top of (raman-at-pieces#5)
    Added error checking that prints the error message to the console
    Previously:
    After a bookmark is deleted, viewBookmarks will be executed and this refreshes the entire list of bookmarks

    What changes:
    Fetch the stored bookmarks array using chrome.storage.sync.get, then find the index of the bookmark that needs to be deleted. After that, we use Array.prototype.splice to remove that bookmark from the array. Finally, we update the stored bookmarks array using chrome.storage.sync.set.

    What resulted:
    The `onDelete` function to first delete the bookmark from the storage, then update the DOM.
    1. Modified the `fetchBookmarks` function to use a callback instead of returning a promise.

    2. Modified the `addNewBookmarkEventHandler` function to use the modified `fetchBookmarks` function with a callback.

    3. Modified the `newVideoLoaded` function to use the modified `fetchBookmarks` function with a callback.

    4. Modified the `handleMessage` function to handle the DELETE type message by
fetching bookmarks using the modified `fetchBookmarks` function with a
callback.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant