skills/frontend-with-playwright/SKILL.md
框架無關的前端開發協議 + Playwright 驗證 + 跨領域 Stream 操作架構:DOM topology 先於 CSS、CSS / JS 邊界辨識、Playwright 三個位置(假設 / 行為 / 互動驗證)、寫成 layout 測試、framework-managed DOM 共處、Reactive 效能盤點、a11y 三道防線、Filter × Source 層錯位 + 五策略合成(適用前端 / 後端 / 演算法 / DB)。Triggers: 寫 CSS, selector 精準, CSS layers, CSS-only vs JS, class toggle, MutationObserver, observer scope, polling, framework 共處, 外部組件客製, custom UI 邊界外, playwright 驗證, browser_evaluate, layout test, focus management, aria-live, keyboard a11y, reactive 效能, runtime cost, layout reflow, lazy loading, 前端網頁開發, vanilla, vue, react, jquery, filter × source, 層錯位, paginated source, post-filter, 自動續抓, 推進 query, 誠實進度 UX, 演算法 pipeline, middleware filter, materialized view, map-reduce.
npx skillsauth add tarrragon/claude frontend-with-playwrightInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
框架無關的前端開發協議 + Playwright 驗證。原則適用於 vanilla HTML/CSS/JS、Vue、React、jQuery — 因為核心是「DOM / CSS / JS 三者的本質行為」加上「Playwright 用 live DOM 量測驗證」、不依賴特定框架的渲染機制。
協議的核心命題:先讀真實狀態、再寫規則;先量再改、不要靠假設。前端 bug 多半來自「寫 CSS 時假設的 DOM 結構與實際不符」、「JS 改完元素被 framework 還原」、「listener 觸發頻率失控」。Playwright 把這些假設變成可驗證的量測值。
| 支柱 | 意義 |
| ------------------------------------------- | ----------------------------------------------------------------------- |
| Read Before Write 先讀真實狀態 | 寫 CSS 前用 playwright/DevTools 量真實 DOM;寫 JS 前確認 framework 邊界 |
| CSS-First, JS-Augment CSS 為主、JS 補強 | 能 build-time 算的進 CSS、必須 runtime 量測的進 JS、邊界清楚不混搭 |
| Measure, Don't Assume 量測、不要假設 | Layout / 行為 / 互動三層、用 playwright browser_evaluate 把假設變已知 |
讀者在本區塊能完成大方向判斷;具體展開(步驟 / 範例)依下方「觸發路由」進對應 reference。
Class name 是約定、不是結構保證。寫 CSS 規則之前、用 playwright browser_evaluate 讀目標元素的 ancestor chain — 確認它在 DOM tree 的哪個位置、parent / sibling / 共用的 grid cell 是什麼。
Selector 設計三維度:起點(document / 元件根 / 函式參數 / closest)+ 範圍(直接子節點 / 子孫)+ 過濾(attribute / 已處理標記)。預設用最精準的、有證據再放寬。
能在 build time 算出來的值(design token、固定 breakpoint、靜態尺寸)→ 寫進 CSS variable / static rule。必須 runtime 才能知道的值(form 高度、scroll 位置、container 寬度)→ JS 量測後寫回 CSS variable、CSS 仍然只讀變數。
JS 的職責是 toggle class / 寫 var、不是設 inline style。!important / inline display: none 是 anti-pattern — 改用 class toggle 把樣式留在 CSS。Vendor CSS 用 @layer 包起來、自家 unlayered 自動贏 specificity。
位置 1:假設驗證(寫 CSS 前)— 讀 ancestor chain、確認結構符合假設。 位置 2:行為驗證(規則寫完後)— 讀 bounding rect / computed style、確認 layout 結果。 位置 3:互動驗證(dispatch event 後讀 state)— 模擬 input / click、量化驗證互動結果。
第 2 次同個版型 bug → 把 query 寫成 playwright 測試固化、CI 防回歸。
把 framework 子樹當「禁區」、客製 UI 注入到 framework 邊界外、用 CSS 控制視覺位置(absolute / margin / grid)。框架重渲染時、邊界外的客製 UI 不被 reconcile 清掉。
JS 操作的邊界穩定性(從穩到不穩):reparent 整節點 > 改 inline style > 改 attribute > 改 textContent > 改 innerHTML > 改 framework 子節點。穩定性低的需要 MutationObserver 重做、或乾脆別碰。
外部組件客製的合作層次(穩定性梯度):CSS variable / API > class hook > boundary DOM > 內部結構。離公共介面越近、升級越穩。
MutationObserver 三維度:root(最窄)、options(最少)、debounce(最長可接受)。預設 observer.observe(scope, { childList: true })、不寫 subtree: true 除非有 case。
Polling(setTimeout / setInterval)有事件可監聽就替換成 MutationObserver — 0 latency / 0 idle CPU。Reactive perf debug 從 console.count(callbackName) 起、確認觸發頻率符合預期。
效能風險點四面向:iteration 成本(500 results × regex test)、reflow 成本(>16ms 觸發 jank)、listener 頻率(如上)、resource 載入時序(lazy chunk vs critical path)。
鍵盤可達性:visible focus indicator、邏輯 tab 順序、modal 有 escape 路徑。三者缺一不可。
動態 a11y:JS reparent / hide 時保存並還原 focus;變動內容用 aria-live="polite" 廣播給 screen reader。
Native > ARIA:能用 <button> / <fieldset> / <dialog> 就不要自己組 ARIA role — native HTML 自帶 keyboard / focus / a11y tree、ARIA 是補強不是替代。
| 觸發情境 | 讀哪份 reference |
| --------------------------------------------------------------------- | ---------------------------------------------------------------- |
| 要寫 CSS 規則、需要先確認 DOM 結構 / selector 該怎麼寫 | references/dom-topology-first.md |
| 不確定 selector 該多寬、命中其他元素 | references/dom-topology-first.md |
| 不確定值該寫進 CSS 還是 JS、CSS layers / variable / class toggle 取捨 | references/css-js-boundary.md |
| 用 !important / inline style 解 specificity | references/css-js-boundary.md |
| 要用 playwright 驗證 layout / 假設 / 互動 | references/playwright-in-loop.md |
| Layout bug 第 2 次出現、想寫成測試 | references/playwright-in-loop.md |
| 客製 UI 被 framework 還原、不知道該注入到哪 | references/framework-coexistence.md |
| 要客製外部組件(pagefind / vendor library) | references/framework-coexistence.md |
| 使用者反映卡頓、CPU 100%、scroll lag、resize jank | references/reactive-performance.md |
| 要設計 MutationObserver / event listener 範圍 | references/reactive-performance.md |
| 要驗收鍵盤 / screen reader / motor / 視覺 a11y | references/accessibility-and-focus.md |
| JS reparent 後 focus 跑掉、aria-live 沒朗讀 | references/accessibility-and-focus.md |
| 設計 filter / sort / count 操作、source 是分批 / streaming | references/data-flow-and-filter-composition.md |
| 「Load more 後畫面閃但內容沒變」的 silent 缺口 | references/data-flow-and-filter-composition.md(層錯位) |
| Backend / 演算法 / map-reduce 的 post-filter 漏項 | references/data-flow-and-filter-composition.md(跨領域同結構) |
每份 reference 自包含:以該情境為核心、把六大原則翻譯成可直接套用的協議步驟與範例。閱讀任一 reference 不需要回來看其他 reference。
| Metric | 定義 | 目標 | | ------ | ----------------------------------------------------- | ---- | | M1 | 從 SKILL.md 出發、解決一個觸發情境需要開幾個檔案 | ≤ 2 | | M2 | 隨機抽一份 reference、不讀其他 reference 能否獨立套用 | 100% |
frontend-with-playwright/
├── SKILL.md # 本檔:六大原則速查 + 觸發路由
└── references/
├── dom-topology-first.md # 情境 1:寫 CSS 前用 playwright/DevTools 量真實 DOM、selector 設計
├── css-js-boundary.md # 情境 2:CSS-only vs JS-assisted、class toggle、layers、variable 單一位置、檔案拆分
├── playwright-in-loop.md # 情境 3:playwright 三個位置(假設 / 行為 / 互動驗證)+ 寫成 layout test
├── framework-coexistence.md # 情境 4:custom UI 留 framework 邊界外、外部組件四層合作、JS 操作邊界辨識
├── reactive-performance.md # 情境 5:observer scope、polling→observer、頻率盤點、iteration / regex / reflow
├── accessibility-and-focus.md # 情境 6:focus on DOM move、keyboard 三要素、aria-live、native HTML > ARIA
└── data-flow-and-filter-composition.md # 情境 7:Filter × Source 層錯位 + 五策略 + 跨領域(前端 / 後端 / 演算法 / DB)
requirement-protocol 是上層的「對話協議」(澄清需求、失敗轉折、覆寫成本、工具切換時機);本 skill 是下層的「前端執行協議」(DOM / CSS / JS / Playwright 的具體做法)。
當情境是「不確定該怎麼跟使用者溝通」 → 讀 requirement-protocol。
當情境是「知道要做什麼、不確定前端該怎麼實作驗證」 → 讀本 skill。
兩個 skill 的 playwright 段落互補:requirement-protocol/tool-switching-timing 講「何時切」、本 skill 的 playwright-in-loop 講「切了之後具體寫什麼 query」。
requirement-protocol/clarifying-ambiguous-instructions 的「類型 5:篩選類」跟本 skill 的 data-flow-and-filter-composition 互補:上層講「該怎麼澄清」、本層講「澄清完該怎麼實作」。
本 skill 的協議建立在幾條抽象層原則上(檔案位置:references/principles/):
Last Updated: 2026-04-26
Version: 0.3.0 — 接入 #79 決策對話五維度(對應 #74-#78 系列);協助前端設計取捨段落的呈現格式對齊 user-facing 決策協議
Version: 0.2.0 — 接入 #55-#68 系列:新增第 7 份 reference data-flow-and-filter-composition(涵蓋 Filter × Source 層錯位 + 五策略 + 跨前端 / 後端 / 演算法 / DB 領域範例);description 補跨領域 stream 操作觸發詞;SKILL.md 加「相關抽象層原則」段(#42-45 + #64 + #67-68);強調「不只前端、stream 操作通用」
Version: 0.1.0 — 從 50+ 篇事後檢討萃取「前端網頁開發 + Playwright 驗證」這條主軸;六份 references 對應「DOM topology / CSS-JS 邊界 / Playwright 三位置 / framework 共處 / Reactive 效能 / A11y」六個情境
development
Use when the user wants to design, redesign, shape, critique, audit, polish, clarify, distill, harden, optimize, adapt, animate, colorize, extract, or otherwise improve a frontend interface. Covers websites, landing pages, dashboards, product UI, app shells, components, forms, settings, onboarding, and empty states. Handles UX review, visual hierarchy, information architecture, cognitive load, accessibility, performance, responsive behavior, theming, anti-patterns, typography, fonts, spacing, layout, alignment, color, motion, micro-interactions, UX copy, error states, edge cases, i18n, and reusable design systems or tokens. Also use for bland designs that need to become bolder or more delightful, loud designs that should become quieter, live browser iteration on UI elements, or ambitious visual effects that should feel technically extraordinary. Not for backend-only or non-UI tasks.
development
Claude Code release notes 框架影響評估工具。比對 last-reviewed 版本篩出新版本,逐項分類(對框架有幫助 / 需評估 / 無影響 / 不適用),對採用項引導建 ANA + WRAP + spawn 落地。Use when: 執行 /release-notes 看到新版本、定期檢查 CC 更新、評估新功能對專案框架的影響時。Triggers: release notes, release-notes, CC 更新, claude code 更新, 版本更新評估, 新功能評估, 框架影響評估。
development
Assertion design judgment framework for flaky and design-quality issues. Use when writing tests, reviewing assertions, diagnosing flaky tests, or deciding if a timing/float/cache assertion is appropriate. Do NOT use for API syntax or refactoring.
tools
Chrome Extension 實機測試與 debug 工作流,以 chrome-devtools-mcp 為核心工具。Use when: (1) 完成功能後實機驗證 / manual test / 試看看 / 跑看看 / verify feature, (2) extension debug / popup 不作動 / content script 不注入 / service worker 報錯 / background 出問題, (3) 安裝 unpacked extension / load unpacked / 載入未封裝, (4) 看 console / 看 network / 看 log / view console / inspect requests, (5) 功能更新後重新載入 extension / rebuild reload / reload extension。涵蓋 Manifest V3 service worker / content script / popup / options page 的 chrome-devtools-mcp 工具呼叫流程。不取代 Puppeteer / Playwright 自動化 E2E(CI 用),定位為開發期手動驗證與 LLM-assisted debug。