Manifest v3

2,603 views
Skip to first unread message

pooja shah

unread,
Jul 22, 2021, 10:22:19 AM7/22/21
to Chromium Extensions
How to add multiple background script in manifest v3 file? I just send demo of v2 file syntax. 

"background": {
"scripts": [
"assets/js/environment.js",
"assets/js/jquery.min.js",
"assets/js/request.js",
"assets/js/background.js"
]
},

in v3 
we will convert this like 

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

But remaining files that is execute above background.js how to add? 
Give me suggestion on this.

Cameron Eckelberry

unread,
Jul 22, 2021, 10:41:08 AM7/22/21
to Chromium Extensions, pooj...@gmail.com
Any files you need, you can load as modules e.g. require('./environment.js') or import './environment.js'.

pooja shah

unread,
Jul 22, 2021, 10:42:43 AM7/22/21
to Cameron Eckelberry, Chromium Extensions
In background. Js? 

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/ba143db9-16be-4655-ae39-8e3c9ba36f2an%40chromium.org.

Cameron Eckelberry

unread,
Jul 22, 2021, 10:43:42 AM7/22/21
to Chromium Extensions, pooj...@gmail.com, Chromium Extensions, Cameron Eckelberry
Yep!

pooja shah

unread,
Jul 22, 2021, 10:58:12 AM7/22/21
to Chromium Extensions, cecke...@malwarebytes.com, pooja shah, Chromium Extensions
After adding it throws error like: Service worker registration failed

Jackie Han

unread,
Jul 22, 2021, 12:29:14 PM7/22/21
to pooja shah, Chromium Extensions
1. Traditional Method - importScripts
Because service worker is a worker, you can use importScripts(). For example:

// in manifest.json
"background": {
  "service_worker": "sw.js"
}


// in sw.js
importScripts('path/a.js');
importScripts('path/b.js');
importScripts('path/c.js');


2. ES Module - import
Note: This is a very new feature, only the latest Chrome(91?, 92) can use it. See https://bugs.chromium.org/p/chromium/issues/detail?id=1194681 

// in manifest.json
"background": {
  "service_worker": "sw.js",
  "type": "module"
}


// in sw.js
import * as myModule from "path/module-name.js";


3. Use any package tools, package multiple js files into one bundle file
For example, 

// in manifest.json
"background": {
  "service_worker": "sw.js"
}


// command line
cat a.js b.js c.js > sw.js


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

Simeon Vincent

unread,
Jul 22, 2021, 1:25:32 PM7/22/21
to Chromium Extensions, Jackie Han, Chromium Extensions, pooj...@gmail.com
+1 to the suggestions that Jackie shared.


> Any files you need, you can load as modules e.g. require('./environment.js') or import './environment.js'.

To be clear, this presumes you're using tooling that supports these patterns. Vanilla JS doesn't support require() – that's a pattern from the Node.js ecosystem. In order to use require, you'll either need to use a compiler or import a CommonJS module loader. The import keyword was introduced in ES6, but standard service workers don't support dynamic or static imports. As Jackie mentioned, Chrome recently shipped support for module service workers, so it is now possible to use static imports (but not dynamic) inside your extension's service worker if it is declared with "type": "module".

Simeon - @dotproto
Chrome Extensions DevRel

Sweta Naik

unread,
Jul 23, 2021, 8:35:15 AM7/23/21
to Chromium Extensions, Simeon Vincent, Jackie Han, Chromium Extensions, pooj...@gmail.com
I have used in V2
chrome.tabs.executeScript(tabId, { code: "$('#xxx').remove();" });
Can you please let me know how this convert in V3?

Simeon Vincent

unread,
Jul 23, 2021, 2:20:08 PM7/23/21
to Chromium Extensions, swet...@gmail.com, Simeon Vincent, Jackie Han, Chromium Extensions, pooj...@gmail.com
Check out the Manifest V3 migration guide or the chrome.tabs.executeScript API docs :)

Simeon - @dotproto
Chrome Extensions DevRel 

Sweta Naik

unread,
Jul 29, 2021, 7:11:34 AM7/29/21
to Chromium Extensions, Simeon Vincent, Sweta Naik, Simeon Vincent, Jackie Han, Chromium Extensions, pooj...@gmail.com
Hello 
I want to use eval() in background.js in manifest V3 but not able to do it getting error if I use 'unsafe-eval' :
 "content_security_policy": {
"extension_pages": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}

Error : 
'content_security_policy.extension_pages': Insecure CSP value "'unsafe-eval'" in directive 'script-src'.

Simeon Vincent

unread,
Aug 6, 2021, 9:24:54 PM8/6/21
to Sweta Naik, Chromium Extensions, Jackie Han, pooj...@gmail.com
Unlike Manifest V2, the CSP rules for Manifest V3 extension cannot be relaxed to allow eval.

Simeon - @dotproto
Chrome Extensions DevRel

Reply all
Reply to author
Forward
0 new messages