Content Scripts UI
Plasmo has first-class support for mounting React, Svelte3, or Vue3 components into the current webpage. This feature is called content scripts UI (CSUI).
An extension can have as many CSUI as needed, with each CSUI targeting a group of webpages or a specific webpage by exporting the config object. To start injecting UI using React:
- Create a
content.tsx
- Export a default React component
- Profit 🎉
const CustomButton = () => {
return <button>Custom button</button>
}
export default CustomButton
NOTE: To have multiple content scripts, create a contents/
directory and
have your CSUI entries there.
See with-content-scripts-ui (opens in a new tab) for a full example.
Config
Content scripts UI are a subset of content scripts. Thus, you can export a config object just as you would a regular Plasmo content script.
How does Plasmo CSUI work?
TL;DR: Plasmo creates a Shadow DOM (opens in a new tab) and mounts your exported component onto it. This isolation technique prevents the web page's style from affecting your component's styling and vice-versa.
For more details, please see the Life Cycle of Plasmo CSUI.