I'm developing an extension for Chrome. Main idea is overriding navigator.credentials.create and navigator.credentials.get, so I added a content script to inject a script named injected.js . It works as expected but when I want to call a function from another file in injected.js I get this error :
Uncaught SyntaxError: Cannot use import statement outside a module (at injected.js:1:1)
Does anybody have idea how it can be fixed?
here is manifest.json :
{
"manifest_version": 3,
...
"content_scripts": [
{
"js": [
"content.js"
],
"all_frames": true,
"run_at": "document_start",
"matches": [
"<all_urls>"
]
}
],
"permissions": [
"storage"
],
"web_accessible_resources": [
{
"resources": [
"injected.js"
],
"matches": [
"<all_urls>"
]
}
]
}
content script:
var s = document.createElement('script');
s.src = chrome.runtime.getURL('injected.js');
s.onload = function() { this.remove(); };
// see also "Dynamic values in the injected code" section in this answer
(document.head || document.documentElement).appendChild(s);
injected.js:
import {process} from "./some_file.js";
navigator.credentials.create = function (options) {
process(options)
}