I am trying to inject a module structured like "injection.js" below into a browser tab with a chrome extension structured like "extension.js". I am using manifest v3.
//injection.js
export function f(){...}
export function g(){...}
export default function main(){
f()
g()
}
//extension.js
import main from "./injection.js";
...
chrome.scripting.executeScript({target: {tabId: tabs[0].id}, function:main });//tabs[0].id is defined elsewhere
...
However, I receive an error, because f
and g
are undefined, since it literally seems to only be injecting main
. If I try to inject the entire file injection.js
, I receive an error for using the keyword export
since I can't specify I am injecting a module.
I am aware that I could wrap all 3 functions in injection.js with a wrapper function to resolve this problem. However, this makes running tests on functions f
and g
difficult, since I have no way of isolating them for unit tests.
Is there a way to inject modules into tabs on chrome extensions?
(This is a simplified version of my actual code. For example, my actual code has the return values of f
and g
interacting with each other. But for the purpose of highlighting the problem, I included only necessary info)