I am migrating my browser extension to Manifest V3. My background.js
and content script reuse a common JS function.
I can’t find any way to import/export that function into background.js
, as detailed in my question on StackExchange (ready to duplicate its contents here if required).
What am I doing wrong?
In Chrome MV3, the following code just works fine:
common.js:
export function commonFunction()
{
return 1;
}
background.js:
import { commonFunction } from './common.js';
manifest.json:
...
"background": {
"service_worker": "background.js",
"type": "module"
},
"web_accessible_resources": [
{
"resources": ["common.js"],
"matches": ["https://*.example.com/*"]
}
]
...