capture
Generic primitive for capturing a screenshot (image) or short walkthrough (video) of a URL, on either Playwright (primary) or system Chrome via CDP (config-driven fallback). Use whenever something needs a page rendered to a file on disk — not just previewed in an in-app browser tool. ALWAYS invoke this skill first when asked to "capture", "screenshot", "take a screenshot of", or "record" a URL or page, including pages that only render client-side, before writing any command: it supplies the configured viewport, output directory and file name, and the headless CDP recipe. Engine, browser, viewport, output type, and output directory are all config-driven (see Config resolution below), not hardcoded per call.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- capture
- license
- MIT
- metadata
- { "version": "0.1.0" }
- description
- Generic primitive for capturing a screenshot (image) or short walkthrough (video) of a URL, on either Playwright (primary) or system Chrome via CDP (config-driven fallback). Use whenever something needs a page rendered to a file on disk — not just previewed in an in-app browser tool. ALWAYS invoke this skill first when asked to "capture", "screenshot", "take a screenshot of", or "record" a URL or page, including pages that only render client-side, before writing any command: it supplies the configured viewport, output directory and file name, and the headless CDP recipe. Engine, browser, viewport, output type, and output directory are all config-driven (see Config resolution below), not hardcoded per call.
03 SKILL.md 正文
Screen capture
Contract
- Input: a URL to render, with engine, viewport, output type, and output directory resolved from config (see "Config resolution").
- Output: an image or video file on disk, at a path the caller can hand to
screen-capture:attach. - Does not: decide what happens to the file afterwards, or start a dev server.
A generic page-capture primitive: given a URL, produce an image or video file on disk. Two engines are supported; which one runs is config, not a per-call choice you make in prose.
This is the mechanics skill for producing the file. It has no opinion on
what the caller does with it afterwards (attach to a PR, embed in a doc,
etc.) — for the PR/issue-attachment workflow specifically (before/after
tables, GitHub upload, responsive/Lighthouse passes), see
screen-capture:compare, screen-capture:attach, and
screen-capture:lighthouse.
Config resolution
Resolve each setting in this order — first source that defines the key wins, otherwise fall through to the next:
second-brain:config(vault-global config, from the siblingsecond-brainplugin) — read via that skill under ascreen-capture.*namespace. This dependency may not be installed yet (it ships from a separate epic issue); if the skill isn't available, skip straight to step 2 rather than failing..claude/settings.jsonin the current project, under ascreenCaptureobject.SCREEN_CAPTURE_*environment variables.- Built-in default, listed below.
| Setting | second-brain:config key |
settings.json key |
env var | default |
|---|---|---|---|---|
| engine | screen-capture.engine |
screenCapture.engine |
SCREEN_CAPTURE_ENGINE |
playwright |
| browser | screen-capture.browser |
screenCapture.browser |
SCREEN_CAPTURE_BROWSER |
chromium |
| viewport | screen-capture.viewport |
screenCapture.viewport |
SCREEN_CAPTURE_VIEWPORT |
1280x900 |
| output_type | screen-capture.output_type |
screenCapture.outputType |
SCREEN_CAPTURE_OUTPUT_TYPE |
image |
| output_dir | screen-capture.output_dir |
screenCapture.outputDir |
SCREEN_CAPTURE_OUTPUT_DIR |
this session's scratchpad directory |
engine is the only key that changes which section below you follow;
viewport is WIDTHxHEIGHT (CSS pixels); output_type is image or
video.
Engine: Playwright (default)
Check for an already-installed Playwright before reaching for npx —
node_modules/.bin/playwright or playwright/@playwright/test in the
current project's package.json means the project already owns the
dependency and version; use that binary instead of pulling a possibly
different version via npx. Otherwise npx --yes playwright ... runs it
one-off with no project install needed. Either way, Chromium's own browser
binary is a one-time install if missing:
npx --yes playwright install chromium
output_type: image
The CLI covers a plain screenshot, including a client-rendered SPA — unlike
raw headless Chrome's --screenshot flag (see the CDP path below), Playwright
waits for the load event and JS execution by default:
width="${viewport%x*}"; height="${viewport#*x}"
npx --yes playwright screenshot \
--browser="$browser" \
--viewport-size="${width},${height}" \
--full-page \
"$url" "$output_dir/capture.png"
If the page needs more readiness than load (a specific selector, a fetch
that resolves after paint), don't reach for a fixed sleep — drop to the short
Node script below and poll before calling page.screenshot().
output_type: video
The CLI has no video mode; use a short Node script — Playwright records video per browser context, and the file is only finalized once that context closes:
const { chromium, firefox, webkit } = require('playwright');
const engines = { chromium, firefox, webkit };
(async () => {
const [, , browserName, width, height, url, outputDir] = process.argv;
const browser = await engines[browserName].launch();
const context = await browser.newContext({
viewport: { width: Number(width), height: Number(height) },
recordVideo: { dir: outputDir, size: { width: Number(width), height: Number(height) } },
});
const page = await context.newPage();
await page.goto(url, { waitUntil: 'load' });
// Add any interaction/wait steps here (page.click, page.waitForSelector, …)
// before closing — the recording covers everything up to context.close().
await context.close(); // finalizes the video file; the path is only known now
const video = await page.video().path();
console.log(video);
await browser.close();
})();
Run it with node script.js "$browser" "$width" "$height" "$url" "$output_dir"
and move/rename the printed path to your expected output filename — Playwright
names the file with an internal UUID, not something you choose up front.
Engine: Chrome + CDP (fallback)
Use this engine when engine resolves to chrome-cdp — e.g. a machine
without Playwright's browser binaries available, or a project that already
standardizes on system Chrome. Mechanics below are a condensed
recipe; for Lighthouse/responsive passes see screen-capture:lighthouse.
macOS-only paths below (/Applications/Google Chrome.app/...); on Linux
substitute google-chrome/chromium.
output_type: image, server-rendered page
A page that paints on the initial HTML works with a plain headless screenshot:
width="${viewport%x*}"; height="${viewport#*x}"
rm -f "$output_dir/capture.png"
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
--headless=new --disable-gpu \
--window-size="$width,$height" --force-device-scale-factor=2 \
--screenshot="$output_dir/capture.png" \
"$url" &
chrome_pid=$!
for _ in $(seq 1 100); do
[ -s "$output_dir/capture.png" ] && break
kill -0 "$chrome_pid" 2>/dev/null || { echo "chrome exited before writing a screenshot" >&2; exit 1; }
sleep 0.2
done
[ -s "$output_dir/capture.png" ] || { echo "timed out waiting for the screenshot" >&2; exit 1; }
kill -9 "$chrome_pid" 2>/dev/null
--window-size is the CSS viewport; with --force-device-scale-factor=2 the
output image is 2W×2H. If --headless=new hangs on the installed Chrome,
fall back to --headless=old.
output_type: image, client-rendered page (SPA)
Plain --screenshot fires before a client-rendered page's JS paints anything,
producing a blank image — drive Chrome over CDP instead (Node's built-in
WebSocket speaks CDP directly, no extra dependency):
- Launch with an ephemeral debug port:
profile_dir=$(mktemp -d) "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \ --headless=new --disable-gpu --user-data-dir="$profile_dir" \ --remote-debugging-port=0 & chrome_pid=$! - Poll (bounded, checking the process is still alive) for
$profile_dir/DevToolsActivePort, then read the port from its first line. Target.createTargeta new tab,Target.attachToTargetwith{flatten: true}to get asessionId— every following command must carry it.Page.enable, then register aPage.loadEventFiredlistener before navigating.Emulation.setDeviceMetricsOverridewith the resolved viewport — required; CDP-created tabs ignore--window-size.Page.navigateto$url, wait forPage.loadEventFired, then poll viaRuntime.evaluatefor a concrete readiness signal (a selector, a value) —document.readyState === 'complete'is a floor, not a guarantee. Stop and report if the poll times out; don't capture a still-loading page.Page.captureScreenshot, then look at the result before trusting it.- Teardown, unconditionally, including on a failure path:
kill "$chrome_pid"; rm -rf "$profile_dir".
If Chrome rejects the CDP websocket connection, retry with
--remote-allow-origins=http://127.0.0.1:<port> (the exact debugging origin, using the
port Chrome reports for --remote-debugging-port=0).
Use the * wildcard only as a last resort: it lets any page that can reach the
debugging port drive the capture browser, so keep the throwaway profile and
ephemeral port, and tear the browser down as soon as the capture finishes.
output_type: video (either Chrome path)
Chrome/CDP has no built-in video capture, so build the video from stills:
capture one PNG per step with the recipe above (numbered
frame-001.png, frame-002.png, …), then stitch with ffmpeg.
Generate the concat-demuxer input list (each still held for frame_seconds):
frame_seconds=1
python3 - "$output_dir" "$frame_seconds" > "$output_dir/frames.txt" <<'PY'
import glob, os, sys
frames_dir, duration = sys.argv[1], sys.argv[2]
files = sorted(glob.glob(os.path.join(frames_dir, "frame-*.png")))
if not files:
sys.exit(f"no frame-*.png files found in {frames_dir}")
def esc(path):
return "'" + path.replace("'", "'\\''") + "'"
for f in files:
print(f"file {esc(f)}")
print(f"duration {duration}")
# The concat demuxer ignores the last entry's duration, so repeat the final
# file line once more with nothing after it.
print(f"file {esc(files[-1])}")
PY
ffmpeg -f concat -safe 0 -i "$output_dir/frames.txt" -vf "fps=30,format=yuv420p" \
-c:v h264_videotoolbox -b:v 5M "$output_dir/capture.mp4"
On macOS, use h264_videotoolbox if the system ffmpeg build has no
libx264 support for -preset; on Linux, -c:v libx264 is the normal
choice.
Output
Write to output_dir (default: this session's scratchpad directory) as
capture.png or capture.mp4 unless the caller names a specific filename.
Confirm the file is non-empty before reporting success — an interrupted
capture can leave a zero-byte or partial file.
When visual verification is required
When a PR or issue changes what gets visually rendered (UI components, generated
images or diagrams, styled documents, anything a human looks at rather than reads as
code), provide before/after screenshots in its description, not just prose. Skip it
for backend logic, config, migrations, scripts, tests, types, docs, and tooling. Do
this proactively, as part of finishing the PR, then run compare and attach.
For a change to layout, CSS, or responsive behavior, one fixed width is not proof:
overflow, clipping, or dead space shows up at other widths. Do a manual resize pass
across representative breakpoints plus a Lighthouse mobile/desktop pass (see
screen-capture:lighthouse).
04 同仓库更多 Skills
youtube-transcript
ALWAYS invoke before fetching a transcript, captions or description for a YouTube video, even when only asked how you would get them. Given a YouTube URL (youtube.com/watch, youtu.be, shorts), save the video's English auto-captions as plain text and its description to files with `yt-dlp`, and print the title, channel and duration. Use when asked to "get the transcript for this video", "grab the captions", "summarize this YouTube video", "put these videos' transcripts in an artifact", or when a YouTube link is pasted and its spoken content is needed. Do not drive the browser's transcript panel or try `youtube-transcript-api` first: both were tried and are slower or empty.
git-worktree-usage
Load this before pushing to, or opening a PR from, a branch whose earlier PR already merged (a squash merge leaves its commits off the default branch, so a new PR from it shows stale history), even when only advising: it defines the fresh-branch and cherry-pick fix. Create worktrees with the `EnterWorktree` tool, never raw `git worktree add`. Git worktree and branch mechanics for isolating non-trivial work: locking and the stale-worktree sweep, picking what to parallelize by file surface, the repo-wide `git stash` collision hazard and its `git restore` alternative, branch naming, catching a branch up to a moved `main` via merge (not rebase), CI/coverage gotchas after a merge, conflict-resolution escalation levels, and PR-splitting sequencing. Also ships two SessionStart hooks that self-heal a project's own symlinked-worktree-directory convention and auto-prune merged worktrees, and a commit-branch guard hook that asks before a git commit lands on the default or an unrelated checked-out branch. Use when creating, entering, or cleaning up a git worktree, including before starting work in an existing worktree that another session may be using; deciding how to parallelize agent sessions across a repo; hitting a `git stash` collision between sessions; resolving a merge/rebase conflict; splitting an already-written diff into multiple PRs; or a stale or wrongly-linked worktree directory needs diagnosing. Do not use for a plain `git stash` in a single clone with no other worktrees or sessions, for rewriting an unpushed branch's history, or for running commands in a worktree the user just created.
url-to-audio
ALWAYS invoke before answering any request to narrate or convert a URL or article to audio, even when only asked what you would do or which backend you would use (including when `OPENAI_API_KEY` is unset and the fallback is `say`). Turn a web article into a narrated audio file: fetch the page, extract the clean reading text, and synthesize it with macOS `say` by default (free, local, already installed, no API key) or OpenAI TTS optionally (when `OPENAI_API_KEY` is set and a `say` voice isn't good enough). Voice and speed are configurable per call, with env var defaults. Produces a `.m4a`/`.mp3` file at a predictable path and prints it. Use when asked to "read this article to me", "convert this page/URL to audio", "make an audio version of this link", or "text-to-speech this article" — including when asked only for the commands or plan, or when `OPENAI_API_KEY` is unset.
subagent-orchestration
Use FIRST, before answering or planning, whenever the user hands over a list of two or more separate tasks ("do A, B and C", numbered or in no order) that each need real exploration, even if they only ask how you would tackle them: it triages which can run as parallel sub-agents and which must stay serial. Also use when asked how to configure a sub-agent already chosen for a large search or exploration (agent type, model tier), and when about to spawn a sub-agent, fan out with the Workflow tool, or run a task that would put large tool output (more than ~50 lines, or ~3 file reads) into the main context. Routes the work to the main context, a single Agent call, or a Workflow; defines the compact handback a delegated agent should return; and picks the model tier. Use for "should I delegate this", "which agent do I use", or "keep my context small".
config
Internal primitive that reads YAML frontmatter from vault config files via mcp__obsidian__* tools, and returns it as merged key-value data. Not a user-facing slash command — this skill is never triggered by a user request directly; other agent-config skills (screen-capture, and second-brain's own capture/query skills) invoke it to load their own settings. Degrades to an empty config, never a hard failure, when the Obsidian MCP is disconnected or the config file doesn't exist. Parse `$ARGUMENTS` as `<skill-name> [project-name]`.
lighthouse
Run a Lighthouse CLI pass (mobile + desktop) against a URL and store the results in the second-brain vault under knowledge/lighthouse/<project>/. ALWAYS invoke this skill first when asked to run, repeat or script a Lighthouse pass or performance/accessibility audit against a URL, before writing any `lighthouse` command, including when the config disables it (it defines the no-op behaviour). Complements, not replaces, a manual responsive resize-and-look pass. Not for advice about fixing a Lighthouse finding. Config-driven: which form factors run, whether the skill runs at all, and where results land are all controlled by lighthouse_enabled, lighthouse_form_factors, and lighthouse_output_dir.