Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from bundle
Inject DOM or CSS into live pages with Playwright and screenshot the result before editing source code.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/injection-patterns.md
1# Injection Patterns23Use plain browser JavaScript for injected files. The script runs inside the page after navigation, so there is no `require`, no filesystem access, and no Node globals.45## Minimal pattern67```js8(() => {9const target = [...document.querySelectorAll("section")].find((node) =>10node.textContent.includes("Search when the task needs capability"),11);12if (!target) return;1314target.setAttribute("data-proto-section", "catalog");1516const style = document.createElement("style");17style.textContent = `18[data-proto-section="catalog"] {19border: 1px solid rgba(251, 146, 60, 0.24);20border-radius: 28px;21background: linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0.01));22}23`;24document.head.appendChild(style);25})();26```2728## Reliable selection2930Use this order of preference:31321. Visible headings, labels, and placeholder text.332. Stable landmarks such as `main`, `header`, `section`, forms, or search inputs.343. Temporary `data-proto-*` attributes that your injected script adds itself.354. Existing class selectors only when the page offers nothing more stable.3637## CSS-only changes3839Prefer CSS injection when the experiment is purely visual:4041- spacing42- panel backgrounds43- borders and shadows44- typography scale45- section emphasis46- responsive layout tweaks4748Inject one style tag instead of scattering many inline styles across nodes.4950## DOM restructuring5152Use JavaScript injection only when the layout must change structurally:5354- reorder cards55- wrap content in a new shell56- move badges near headings57- insert helper labels before inputs5859Keep DOM edits idempotent. If the script runs twice, it should not duplicate badges, wrappers, or style tags.6061## Review loop62631. Capture a baseline screenshot.642. Inject the smallest experiment that answers the current design question.653. Capture the prototype at desktop and mobile widths.664. Write down what improved, what regressed, and what should become a real code change.6768## Worked example6970On `https://forgedemy.org/skills`, a good first pass was:7172- strengthen the hero with a larger shell and sharper headline scale73- frame the catalog section as the main action zone74- give cards more separation and a stronger top accent75- add a small search caption above the input to clarify the intended flow7677That experiment was achieved entirely by annotating sections with `data-proto-*` attributes, injecting one style block, and screenshotting the result without touching app source.78