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

feat: adds boilerplate vite/svelte/typescript to create a browser extension to resolve #1 #2

Merged
merged 3 commits into from
Nov 30, 2023

Conversation

dylanbathurst
Copy link
Contributor

See the README for a full description of features and getting started guide.

@Evanfeenstra
Copy link
Collaborator

Nice start!

  • Don't we need a manifest.json file to declare the extension? We want to use the latest manifest format (version 3)
  • I don't see a service worker script, that can be long-running in the background (for example we could open a websocket in the background, and keep it open even if the popup closes).
  • The Sphinx provider should enable communication between the web page itself and the service worker. (is window.postMessage the right way?)
    @dylanbathurst

@dylanbathurst
Copy link
Contributor Author

@Evanfeenstra thanks!

  • For the first point in your comment, there is a manifest.json you can see it in the PR but it's in the public directory along with the popup.html template file. I put them there as they just get copied over to the top level of the dist dir from vite. I can move it to the top level of the project, it'll just be more configs to copy it over in the vite.config file.
  • It is definitely possible to add a background service worker script, I didn't think it was within the scope of this bounty though when I read the bounty description. There have been some changes between manifest v2 and v3 for how background scripts run. Since they're service workers now, they're no longer long running processes and so you need to use an event driven model + persistent store (ex. indexedDb, chrome.storage) of using them since they can shut down at any time.
  • This PR has the content script and is injecting it into the window object as a global sphinx class. That's where we would add more functionality for using window.postMessage in order for the website to talk to our extension and other browser apis.

@Evanfeenstra
Copy link
Collaborator

  1. oh i see it now, thanks
  2. The issue includes: A script should be injected into visited web pages, allowing communication between the service worker and the web page... i did edit the issue like 15 minutes after it was created, maybe u didn't see that in time? It looks like using the Chrome offscreen api is the way to go:

https://stackoverflow.com/questions/68966727/maintaining-a-persitant-connection-in-a-mv3-chrome-extension

https://stackoverflow.com/questions/66618136/persistent-service-worker-in-chrome-extension

  1. We need a way to pass messages back and forth from the web page to the popup, or to the long-running background process

@dylanbathurst
Copy link
Contributor Author

I see, ok. I'll spend some time getting this implemented tonight.

@dylanbathurst
Copy link
Contributor Author

I've added the background service worker and am posting messages from the content script. I'm still working on an issue where the messages aren't reaching the background script for some reason. I'll finish it up today.

…ges between content script, background script and popup
@dylanbathurst
Copy link
Contributor Author

@Evanfeenstra mind taking another look at this PR. I added the background script and also add examples of how to pass messages between the content/background/popup(Svelte) scripts.

@Evanfeenstra
Copy link
Collaborator

Awesome, thanks @dylanbathurst !

@Evanfeenstra Evanfeenstra merged commit 741383e into stakwork:master Nov 30, 2023
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.

2 participants