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

[request] Manifest V3 serviceWorker example #528

Closed
jfdelarosa opened this issue Dec 16, 2020 · 15 comments
Closed

[request] Manifest V3 serviceWorker example #528

jfdelarosa opened this issue Dec 16, 2020 · 15 comments

Comments

@jfdelarosa
Copy link

Manifest v3 states that service workers replace background pages, but currently there's no real example of how to achieve this and the migration guide doesn't help at all.

There are some hints of how to use SW around Stack Overflow, but all of them make use of the background script (e.g. this one).

It would be great if someone show us an example of how to use service workers in Chrome extensions correctly.

@amitsingh-007
Copy link

Would this help: https://stackoverflow.com/questions/65311898/chrome-extension-migrate-from-manifest-v2-to-v3?

@jfunction
Copy link

jfunction commented Jan 20, 2021

Please also see #526
I haven't coded an extension before and don't want to start my first project with a deprecated manifest version so having V3 samples would be useful.
How does collaboration within this repository work? Can anyone just pop in a pull request? Is anyone specifically in charge of deciding what gets merged in? etc.
Going to at the last person who committed in the hopes they will know more. That's you @samthor :)

@pzpzpzA
Copy link

pzpzpzA commented Feb 1, 2021

@jfunction I'm in the exact same situation as you, do you know when MV3 is going to be fully supported?

@jfunction
Copy link

MV3 is supported. Right now. In chrome 88. I'm not sure why this issue doesn't seem to be a priority (or at least updating the docs, since the "MV3" docs are still talking about MV2 functionality).

I needed to get some work done on it and didn't want to be stuck relying on this issue being resolved so I eventually caved and started my extension with MV2. I now see why having a clunky always-on background worker is being phased out. I just wish it was a bit easier learn how to do away with the background worker and move to service workers (and probably persistent thread-safe storage of state?).

@jfunction
Copy link

@petele shared https://developer.chrome.com/blog/new-in-chrome-88/#mv3
It refers to the MV3 docs which have improved since I last checked but still need a bit of love.
eg https://developer.chrome.com/docs/extensions/mv3/background_pages/ shouldn't exist
And we really could do with some MV3 samples 🙏

Hopefully someone at Google sees this and can assist.

@dotproto
Copy link
Contributor

We have a few MV3 examples in the repo and this point and I'm in the process of converting MV2 extensions to MV3. If there's a particular example you'd like to see prioritized, please open a new issue for it.

@ghzhou
Copy link

ghzhou commented Mar 29, 2021

cannot find a workable service-worker based background sample, I am frustrated that a simple runtime.onMessage doesn't work :(

@lbragile
Copy link

lbragile commented Nov 21, 2021

@ghzhou I ran into the same issue, this seems to be a bug as outlined in the comment to my post. I cannot even get a simple console.log('message') to show up in the background service worker... Hopefully this is fixed relatively soon given the push to MV3 migration.

Edit

Turns out my issue was caused by vendor splitting optimization in webpack (see update 4 in my linked post), removing that from webpack made everything work properly for me!

@ctjlewis
Copy link

ctjlewis commented Dec 30, 2021

A year gone by and all these comments and someone can't drop an example of a service worker. Yes, we've read the one low-quality "migrating to v3" article, thanks.

@ctjlewis
Copy link

ctjlewis commented Dec 30, 2021

Absolutely insane. Docs say we can use ESM, yet the worker throws because of an import statement. But make sure to use a try/catch or you won't know why it failed!

Is anyone actually working on this? What is happening here? Why are the resources for this so exceptionally poor?

@mengodkidjo
Copy link

@alexander-mart
Copy link

Expample with service_worker on manifest v3:
https://github.com/SimGus/chrome-extension-v3-starter

@mindplay-dk
Copy link

Is there still no way to replace HTML content (before page load) using manifest v3?

That's the only example I want to see.

(Is Google still trying to kill off ad-blockers?)

@sebastianbenz
Copy link
Collaborator

@mindplay-dk Thanks for the feedback. Can you please provide a bit more context. What is the specific use case that you have in mind? How would you have solved it in an MV2 extension?

@mindplay-dk
Copy link

Can you please provide a bit more context. What is the specific use case that you have in mind?

Nothing specific, just trying to learn. Any basic example of modifying the body would do.

Let's say, replacing all occurrences of "Google" in the body with "G👀gle" ?

The important point is, the content should be modified before it loads - and not by performing a redirect.

Having spent most of my day on this, I'm starting to suspect it's not at all possible?

How would you have solved it in an MV2 extension?

I don't know. I can't figure it out anymore.

I swear I did this, many years ago... but I might have been using manifest v1 then, I don't recall.

I've read this post which makes the whole situation with v3 sound pretty bleak. But from the way they describe the situation, it sounds at least v2 was capable of this? Anything changed with v3 since this article about a year ago?

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