Chrome extensions: Use the "background.service_worker" key instead manifest_version 3
Asked Answered
B

2

45

When trying to install a chrome extension using manifest_version 3, I am unable to install as I keep getting the error:

The "background.scripts" key cannot be used with manifest_version 3. Use the "background.service_worker" key instead

or

The "background.persistent" key cannot be used with manifest_version 3. Use the "background.service_worker" key instead.

Bolster answered 5/2, 2021 at 0:26 Comment(0)
B
84

Manifest V3 no longer supports background pages. Instead it now supports a new feature called service workers.

The key background in your manifest.json can no longer contain the field persistent, and also update the value from scripts to service_worker. Service worker cannot contain an array but can only contain a single string value.

Eg:

{
  "name": "Test",
  "description" : "Test Chrome Extension",
  "version": "1.0",
  "manifest_version": 3,
  "background": {
    "service_worker": "background.js"
  }
}

Ref: Manifest V3 Migration Checklist

Bolster answered 5/2, 2021 at 0:26 Comment(5)
So what do you do if you have multiple background scripts?Multiped
@Multiped Multiple background 'scripts' don't exist in v3. There can only be a single 'service_worker'. developer.chrome.com/docs/extensions/mv3/…Bolster
@Multiped Use importScriptsPopery
Use content_scripts in the manifest to load additional javascript files.Glowworm
Oh can't they just make an api that is implementation independent so it can just stay the same for once.Magnanimous
S
0

This is easy to solve. Are you using...

"background": {
        "scripts": [
             "background.js"
         ],
         "persistent": false
    },
  • Or another method to add background on Google extension. JUST WRITE IT...

    "background": { "service_worker": "background.js" },

I hope this will help you to solve your problem. If not Please message me here.

Systemize answered 12/10, 2023 at 6:42 Comment(1)
Does not work with manifest_version 3Inappreciative

© 2022 - 2024 — McMap. All rights reserved.