vite-plugin-web-extension
vite-plugin-web-extension copied to clipboard
Can't use injected scripts
When I try to inject a script to the client (I need to use some globals available in the site) and build the extension, the transpiled code tries to use getUrl but that method is not available on the client (obviously)
There is any way to make this work?
The plugin creates a wrapper script for scripts that contain imports, so to avoid that you can remove imports from your script. Alternatively could drop a static script in public and manually inject it.
Can't you just use the Chrome executeScript function?
await chrome.scripting.executeScript({
target: {
tabId = 0,
// frameIds = []
},
func: runInjectScript,
args: ['something', true, 123],
world: 'MAIN'
});
const runInjectScript = () => { console.log('Hi, show me window object:', window);}