0

I try to migrate my manifest from v2 to v3 and fail with background scripts. I get an error unexpected token. I think my syntax is correct. What I'm doing wrong? How can I migrate this setup with multiple background scripts?

manifest v2

{
   "description": "Tooltip Dictionary",
   "manifest_version": 2,
   "name": "Tooltip Dictionary",
   "permissions": [ "https://www.example.com/*", "storage" ],   
   "version": "1.0.0",
   "icons":{
      "16":"icon16.png",
      "32":"icon32.png",
      "48":"icon48.png",
      "128":"icon128.png"
   },
   "browser_action":{
      "default_icon": "icon32.png"
   },
   "content_scripts":[{
      "matches":["<all_urls>"],
      "js":["jquery.min.js", "tooltip.css.js", "cs.js"]
   }],
   "background":{
      "scripts":[ "jquery.min.js","bg.js" ]
   },
       "commands":{
      "run-script": {
        "suggested_key": {
          "default": "Alt+1",
          "windows": "Alt+1",
          "mac": "Command+E"
        },
        "description": "Run"
      }
    }
}

manifest v3

{
   "description": "Tooltip Dictionary",
   "manifest_version": 3,
   "name": "Tooltip Dictionary",
   "host_permissions": ["https://www.example.com/*"],
   "permissions": ["storage"],
   "version": "1.0.0",
   "icons":{
      "16":"icon16.png",
      "32":"icon32.png",
      "48":"icon48.png",
      "128":"icon128.png"
   },
   "action":{
      "default_icon": "icon32.png"
   },
   "content_scripts":[{
      "matches":["<all_urls>"],
      "js":["jquery.min.js", "tooltip.css.js", "cs.js"]
   }],
  "background": {
        "service_worker": ["jquery.min.js", "bg.js"]
    },
       "commands":{
      "run-script": {
        "suggested_key": {
          "default": "Alt+1",
          "windows": "Alt+1",
          "mac": "Command+E"
        },
        "description": "Run"
      }
    }
}

If I try to use a single background file, it can't be registered too, like on screenshot: enter image description here

enter image description here

enter image description here

Evgeniy
  • 2,337
  • 2
  • 28
  • 68
  • Incorrect. The value should be a single string, not an array. See [chrome extension mv3 - Modularize service worker js file](https://stackoverflow.com/a/66408379) – wOxxOm Jan 21 '22 at 15:24
  • @wOxxOm is it really so? I tried to use a single file and failed too - I edited my post. Beside of this, how should I deal with your warning `Warning! Don't import DOM-based libraries like jQuery because service workers don't have DOM so there's no document, XMLHttpRequest, and so on.`? – Evgeniy Jan 21 '22 at 15:39
  • As the error shows there's no browserAction in MV3. See the [migration guide](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-migration/). As for jQuery, don't use it. Use `fetch`. – wOxxOm Jan 21 '22 at 15:51
  • 1
    @wOxxOm `there's no browserAction in MV3` - I don't have it too, changed to `action`. About `don't use jquery, use fetch instead` - could you please be a bit more specific? I'm not yet on the level of understanding you on the fly :) – Evgeniy Jan 21 '22 at 16:50
  • Then change browserAction to action too. How do you use jquery in the background script? – wOxxOm Jan 21 '22 at 20:16
  • After the change I get an error `Error in event handler: ReferenceError: $ is not defined` background.js , as in the post edit. – Evgeniy Jan 21 '22 at 20:37
  • Yes, that's why I said use `fetch`. You can find examples, here's the [documentation](https://developer.mozilla.org/en-US/docs/Web/API/fetch). – wOxxOm Jan 21 '22 at 20:56

0 Answers0