AGENT SKILL

canary-scripting

The Canary sandbox scripting API for browser automation. Use when writing or debugging a Canary script — looking up how to open a page, click, fill, extract text, observe an unknown page with snapshotForAI, evaluate in the page, take a screenshot, persist data between steps, or understand sandbox limits (no imports, timeouts). Trigger phrases — "how do I click in canary", "canary page API", "what's on this page", "explore a page in canary", "snapshotForAI", "saveScreenshot signature", "get text from the page", "why is my canary script timing out", "open a new tab in canary".

License 许可
MIT
最近更新
2026-09-09
Stars
★ 1
Forks
0

01 前言 Front Matter

name
canary-scripting
license
MIT
metadata
{ "tags": [ "canary", "browser-automation", "playwright", "scripting" ], "author": "usecanary", "version": "0.4.4", "category": "reference" }
description
The Canary sandbox scripting API for browser automation. Use when writing or debugging a Canary script — looking up how to open a page, click, fill, extract text, observe an unknown page with snapshotForAI, evaluate in the page, take a screenshot, persist data between steps, or understand sandbox limits (no imports, timeouts). Trigger phrases — "how do I click in canary", "canary page API", "what's on this page", "explore a page in canary", "snapshotForAI", "saveScreenshot signature", "get text from the page", "why is my canary script timing out", "open a new tab in canary".

02 资源文件 1

03 SKILL.md 正文

Canary scripting API

Canary scripts are plain async JavaScript run in a QuickJS sandbox with a Playwright-like API. Both canary-browser run (one-off) and canary run --session (recorded step) execute the same way: top-level await, with browser, console, and the file helpers available as globals.

When to use

  • Writing a script to drive a browser with Canary
  • Looking up a page or locator method (goto, locator, evaluate, waitForSelector, screenshot)
  • Persisting a page or a file between steps of a session
  • Debugging a timeout, a missing global, or a "page closed" error

Examples

Example 1: open a page and read it

User says: "navigate to a site and get the title in canary" or "how do I read text off the page?" Use a named page so it persists across steps, then goto and evaluate/locator. See Quick start.

Example 2: click / fill / extract

User says: "click the login button", "fill the search box", "scrape the headlines" page.locator(selector) then .click() / .fill(value) / .textContent(); or page.evaluate(fn) to pull structured data in one round-trip.

Example 3: screenshot

User says: "take a screenshot" or "what's the saveScreenshot signature?" const buf = await page.screenshot({ fullPage: true }); await saveScreenshot(buf, "home.png"); — note buffer first, and that saveScreenshot is a top-level global, not browser.saveScreenshot.

Example 4: observe an unknown page

User says: "I don't know the selectors", "what's on this page?", "explore before acting" (await page.snapshotForAI()).full → an aria outline of the page. Read it to pick a role/text selector, then act. See Observing the page.

Quick start

<!-- canary:snippet ex-quickstart fenced=js -->

const page = await browser.getPage("main");          // named, persistent page
await page.goto("https://example.com", { waitUntil: "domcontentloaded" });
console.log(await page.title());

const headings = await page.evaluate(() =>
  [...document.querySelectorAll("h1, h2")].map((h) => h.textContent.trim())
);
console.log(JSON.stringify(headings));

await page.locator("a.more").click();
const buf = await page.screenshot({ fullPage: false });
await saveScreenshot(buf, "page.png");               // saveScreenshot(buffer, name)

<!-- canary:end ex-quickstart -->

Observing the page

<!-- canary:snippet ex-snapshot fenced=js -->

const page = await browser.getPage("main");
const snap = await page.snapshotForAI(); // { full, incremental? }
console.log(page.url(), await page.title());
console.log(snap.full); // aria outline — pick a role/text selector from this
// then act: await page.getByRole("button", { name: "Continue" }).click();
// after changes, page.snapshotForAI({ track: "main" }) returns just the incremental diff

<!-- canary:end ex-snapshot -->

<!-- canary:snippet api-snapshot -->

  • page.snapshotForAI() returns { full, incremental? } — full is an aria outline of the page: roles, accessible names, [ref=eN] markers on actionable nodes. Read it to pick a semantic selector — page.getByRole("button", { name: "Continue" }), page.getByText("Sign in") — then act.
  • Options { track?, depth?, timeout? }: re-run page.snapshotForAI({ track: "main" }) after the page changes to get just the incremental diff; { depth: N } caps the tree on huge pages; timeout bounds the walk.
  • page.locator("aria-ref=e12") works for an immediate action in the same script only — refs go stale across steps and after navigations. Prefer re-deriving a semantic selector. <!-- canary:end api-snapshot -->

<!-- canary:snippet rule-observe-first -->

  • Unknown page? Snapshot first, then act: read (await page.snapshotForAI()).full to see what is there, pick a semantic selector from it (getByRole, getByText), then interact. Never guess selectors blind.

  • Known page or selectors? Skip the snapshot and use direct selectors — faster and more reliable. <!-- canary:end rule-observe-first -->

  • End each script by logging the state you need for the next decision — stdout is your observation channel.

The essentials

<!-- canary:snippet api-globals --> Every script gets these globals:

  • browser — pre-connected browser handle (see the script API)
  • console — log / info / warn / error, captured per run
  • setTimeout / clearTimeout — basic timers
  • saveScreenshot(buffer, name) — save a screenshot buffer (async — await it)
  • writeFile(name, data) / readFile(name) — small-file persistence (async — await them) <!-- canary:end api-globals -->

<!-- canary:snippet rule-data-passing -->

  • Browser state persists across steps: named pages (and their cookies) stay open between scripts within a session — reuse the same page name so each step picks up where the last left off.

  • Anonymous newPage() tabs are closed when each script ends.

  • To pass values between steps: writeFile("state.json", JSON.stringify(x)) in one step, JSON.parse(await readFile("state.json")) in the next. <!-- canary:end rule-data-passing -->

  • One primary named page per step keeps the per-step report screenshot correct (the full rule is in references/REFERENCE.md).

  • No module system — no import/require. Inline any helpers.

  • Timeouts — both CPU and wall-clock are enforced; long loops or unresolved promises abort the script.

For the complete API — every page/locator/browser method, signatures, the per-step screenshot rule, and sandbox limits — see references/REFERENCE.md.

04 同仓库更多 Skills

davidanthonyn
davidanthonyn/agent-skills

zustand-state-management

Production-tested setup for Zustand state management in React applications with TypeScript. This skill provides comprehensive patterns for building scalable, type-safe global state. Use when: setting up global state in React, migrating from Redux or Context API, implementing state persistence with localStorage, configuring TypeScript with Zustand, using slices pattern for modular stores, adding devtools middleware for debugging, handling Next.js SSR hydration, or encountering hydration errors, TypeScript inference issues, or persist middleware problems. Prevents 5 documented issues: Next.js hydration mismatches, TypeScript double parentheses syntax errors, persist middleware export errors, infinite render loops, and slices pattern type inference failures. Keywords: zustand, state management, React state, TypeScript state, persist middleware, devtools, slices pattern, global state, React hooks, create store, useBoundStore, StateCreator, hydration error, text content mismatch, infinite render, localStorage, sessionStorage, immer middleware, shallow equality, selector pattern, zustand v5

★ 1
davidanthonyn
davidanthonyn/agent-skills

zetic-mlange

Help users integrate the ZETIC Melange (MLange) on-device AI SDK into Android (Kotlin/Java) and iOS (Swift) mobile apps. Use this skill whenever the user mentions Zetic, MLange, Melange, ZeticMLangeModel, ZeticMLangeLLMModel, ZeticMLangeHFModel, on-device NPU inference for mobile, or deploying ML models to Android/iOS with NPU acceleration. Also trigger when users ask about running LLMs on-device with GGUF quantization, mobile NPU model deployment, or converting PyTorch/ONNX models for mobile inference. Covers general model inference, LLM inference (streaming token generation), and HuggingFace model loading.

★ 1
davidanthonyn
davidanthonyn/agent-skills

youtube-downloader

Download videos, audio, playlists, and channels from YouTube and 1000+ websites using yt-dlp. Supports quality selection, format conversion, subtitle download, playlist filtering, metadata extraction, thumbnail download, and batch operations. Use when downloading YouTube videos in any quality (4K, 8K, HDR), extracting audio as MP3/M4A/FLAC, downloading entire playlists/channels, getting subtitles in multiple languages, converting to specific formats, downloading live streams, archiving content, or batch processing multiple URLs. Optimized for reliability with automatic retries, rate limiting, and error handling.

★ 1
davidanthonyn
davidanthonyn/agent-skills

wordpress-plugin-core

This skill provides comprehensive knowledge for WordPress plugin development, covering core patterns, security best practices, database interactions, hooks/filters, Settings API, custom post types, REST API, and AJAX. This skill should be used when creating WordPress plugins, troubleshooting security issues, implementing custom post types/taxonomies, building admin interfaces, or working with the WordPress database. Use when: Creating new WordPress plugins, implementing nonces/sanitization/escaping, working with $wpdb and prepared statements, building Settings API pages, registering custom post types or taxonomies, implementing REST API endpoints, handling AJAX requests, debugging plugin activation/deactivation issues, preventing SQL injection/XSS/CSRF vulnerabilities. Keywords: wordpress plugin development, wordpress security, wordpress hooks, wordpress filters, wordpress database, wpdb prepare, sanitize_text_field, esc_html, wp_nonce, custom post type, register_post_type, settings api, rest api, admin-ajax, wordpress sql injection, wordpress xss, wordpress csrf, plugin header, activation hook, deactivation hook, wordpress coding standards, wordpress plugin architecture

★ 1
davidanthonyn
davidanthonyn/agent-skills

webapp-testing

Test local web applications with Playwright. Use when asked to verify frontend functionality, debug UI behavior, capture browser screenshots, or inspect browser logs.

★ 1
davidanthonyn
davidanthonyn/agent-skills

web-performance-audit

Audit web performance using Chrome DevTools MCP. Use when asked to audit, profile, debug, or optimize page load performance, Lighthouse scores, or site speed.

★ 1