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

PGlite does not work in MV3 browser extensions that operate on other origins #471

Closed
callum-gander opened this issue Dec 14, 2024 · 2 comments

Comments

@callum-gander
Copy link

So, I could be wrong here but as I understand it:

  • In order to function across tabs and ensure transactions are enforced, we need to run the web worker https://pglite.dev/docs/multi-tab-worker
  • Due to MV3, we can't spin up web workers from background scripts and due to cross-origin policies, we also can't spin up the web worker if we're running it within a content script on another origin, e.g. let's say this is a youtube extension, the content script wouldn't be able to spin up the web worker there as it'll

This makes it seem that for browser extensions that use MV3, there isn't a way to run the web worker unless we're running the extension on origins that we specifically own and can modify the content policy. Am I missing something here? I've gone down a huge rabbit hole today trying to get PGlite working on my extension and due to this limitation it feels like it won't work and, due to the limitations of MV3, can't work. Is this correct? Would be great to get a second opinion here on whether this is true and if so add it to the docs so others know not to try this out. Thanks

@ashrielbrian
Copy link

ashrielbrian commented Jan 4, 2025

hey @callum-gander - not sure if this addresses your issue: my extension operates on all origins http://*/* and I use the navigator's web lock API in lieu of the multi-tab worker, which I found, like you, difficult to adapt to a browser extension. This is my repo if it helps.

In short, I have my content scripts use chrome.runtime.sendMessage to the service workers in the background script, and these workers in turn get a reference to the pglite instance wrapped around the web lock API.

@samwillis
Copy link
Collaborator

Hey @callum-gander,

I'm not really up to speed on MV3, and browser extension in general. I do know they can complex for things like workers though.

You don't need to you the PGliteWorker api, you can run it on any thread you want. It sounds like @ashrielbrian has a good enough solution (the PGliteWorker api uses the web locks api itself), I hope that helped!

I'd like to expand the support for the worker, but it's not high on our priority list now.

I'm going to close this issue for now as out of scope.

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

No branches or pull requests

3 participants