Hacks together a working resolver which allows bundling a referenced dependency as a (wrapped) IIFE, which can be serialized for use with chrome.scripting.executeScript(). Relies on esbuild for the globalName, banner, and footer functionality which I couldn't figure out how to replicate just using Parcel. 🤷
This allows passing JSON serializable arguments to the injected function, meaning context that is already available in a background script (like chrome.runtime.id or application configuration already loaded from localStorage) can be passed immediately and directly to the function.
For me, this was necessary to avoid less ergonomic solutions for passing context to content scripts injected into the MAIN world. It's possible there's an easier way to do this, but I'm not aware of it and this still seems generally useful.
Assuming the contribution is appreciated, documentation on its usage, including some issues like esbuild requiring pnpm install --shamefully-hoist to resolve dependencies (on Windows? haven't checked whether this is only a problem on my Windows machine) and how to pass polyfill plugins would follow.
Details
Hacks together a working resolver which allows bundling a referenced dependency as a (wrapped) IIFE, which can be serialized for use with
chrome.scripting.executeScript()
. Relies onesbuild
for theglobalName
,banner
, andfooter
functionality which I couldn't figure out how to replicate just using Parcel. 🤷This allows passing JSON serializable arguments to the injected function, meaning context that is already available in a background script (like
chrome.runtime.id
or application configuration already loaded fromlocalStorage
) can be passed immediately and directly to the function.For me, this was necessary to avoid less ergonomic solutions for passing context to content scripts injected into the
MAIN
world. It's possible there's an easier way to do this, but I'm not aware of it and this still seems generally useful.Assuming the contribution is appreciated, documentation on its usage, including some issues like
esbuild
requiringpnpm install --shamefully-hoist
to resolve dependencies (on Windows? haven't checked whether this is only a problem on my Windows machine) and how to pass polyfill plugins would follow.Code of Conduct
Contacts
If your PR is accepted, we will award you with the
Contributor
role on Discord server.To join the server, visit: https://www.plasmo.com/s/d