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

Content Scripts should not be IIFE

Open steinybot opened this issue 4 years ago • 1 comments

A content script containing:

function setSelectedElement(el) {
    // do something with the selected element
}

Should be able to be executed by:

chrome.devtools.inspectedWindow.eval("setSelectedElement($0)",
    { useContentScriptContext: true });

But it can't because that function is being removed and converted to a IIFE.

See https://developer.chrome.com/docs/extensions/mv3/devtools/#selected-element

steinybot avatar Oct 08 '21 02:10 steinybot

This also would address the issue that MV3 service workers need to register event handlers on the first pass of a file so that the chrome API can spawn the service worker when a registered event is triggered.

thopiddock avatar Dec 17 '21 10:12 thopiddock