Content Script UI disappears immediately after appearing.
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 10.5k
- Forks
- 564
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
I spent the whole day looking for a solution to this problem. The elements appeared but then immediately disappeared.
Previously, I used Plasmo and it worked fine in the same selector.
web: https://www.istockphoto.com/en/search/2/image-film?phrase=water%20drink
https://github.com/user-attachments/assets/f86b0f93-26ac-4df1-b2d7-664fe364154e
import "~/assets/tailwind.css";
import ReactDOM from "react-dom/client";
export default defineContentScript({
matches: ["https://www.istockphoto.com/*"],
cssInjectionMode: "ui",
runAt: "document_end",
async main(ctx) {
const ui = await createShadowRootUi(ctx, {
name: "button-analyze-on-article",
position: "inline",
append: "first",
anchor: "[data-testid='galleryContainer']",
onMount: (container) => {
const app = document.createElement("div");
container.append(app);
const root = ReactDOM.createRoot(app);
root.render(
<button className="bg-blue-500 text-white p-2 rounded-md">
Analyze
</button>
);
return root;
},
onRemove: (root) => {
root?.unmount();
},
});
ui.autoMount();
},
});
Reproduction
Steps to reproduce
run dev
System Info
System:
OS: Windows 11 10.0.26100
CPU: (16) x64 AMD Ryzen 7 7840HS w/ Radeon 780M Graphics
Memory: 3.43 GB / 31.19 GB
Binaries:
Node: 22.14.0 - C:\Program Files\nodejs\node.EXE
npm: 10.9.2 - C:\Program Files\nodejs\npm.CMD
pnpm: 10.14.0 - ~\AppData\Local\pnpm\pnpm.CMD
bun: 1.2.12 - ~\.bun\bin\bun.EXE
Browsers:
Edge: Chromium (140.0.3485.54)
npmPackages:
wxt: ^0.20.11 => 0.20.11
Used Package Manager
bun
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the supplied defineContentScript reproduction and the createShadowRootUi lifecycle, then run it with bun against the stated iStockphoto URL. Done means the mounted Analyze button remains visible after the content script UI appears; no repository file or test path is named in the report.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100