StarkShang / vite-plugin-chrome-extension

A vite plugin to bundle chrome extensions for Manifest V3.
MIT License
460 stars 68 forks source link

Content Scripts should not be IIFE #17

Open steinybot opened 2 years ago

steinybot commented 2 years ago

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

thopiddock commented 2 years ago

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.