vite-plugin-web-extension icon indicating copy to clipboard operation
vite-plugin-web-extension copied to clipboard

Can't use injected scripts

Open aleksolutions opened this issue 2 years ago • 2 comments

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?

aleksolutions avatar Jun 08 '23 16:06 aleksolutions

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.

samrum avatar Jun 09 '23 03:06 samrum

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);}

gehaktmolen avatar Jun 19 '23 12:06 gehaktmolen