This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Always use Node.js/npm instead of Bun.
# Install dependencies (from skills/dev-browser/ directory)
cd skills/dev-browser && npm install
# Start the dev-browser server
cd skills/dev-browser && npm run start-server
# Run dev mode with watch
cd skills/dev-browser && npm run dev
# Run tests (uses vitest)
cd skills/dev-browser && npm test
# Run TypeScript check
cd skills/dev-browser && npx tsc --noEmitAlways run these checks before considering a task complete:
- TypeScript check:
npx tsc --noEmit- Ensure no type errors - Tests:
npm test- Ensure all tests pass
Common TypeScript issues in this codebase:
- Use
import type { ... }for type-only imports (required byverbatimModuleSyntax) - Browser globals (
document,window) inpage.evaluate()callbacks needdeclare const document: any;since DOM lib is not included
This is a browser automation tool designed for developers and AI agents. It solves the problem of maintaining browser state across multiple script executions - unlike Playwright scripts that start fresh each time, dev-browser keeps pages alive and reusable.
All source code lives in skills/dev-browser/:
src/index.ts- Server: launches persistent Chromium context, exposes HTTP API for page managementsrc/client.ts- Client: connects to server, retrieves pages by name via CDPsrc/types.ts- Shared TypeScript types for API requests/responsessrc/dom/- DOM tree extraction utilities for LLM-friendly page inspectionscripts/start-server.ts- Entry point to start the servertmp/- Directory for temporary automation scripts
The project uses @/ as a path alias to ./src/. This is configured in both package.json (via imports) and tsconfig.json (via paths).
// Import from src/client.ts
import { connect } from "@/client.js";
// Import from src/index.ts
import { serve } from "@/index.js";-
Server (
serve()insrc/index.ts):- Launches Chromium with
launchPersistentContext(preserves cookies, localStorage) - Exposes HTTP API on port 9222 for page management
- Exposes CDP WebSocket endpoint on port 9223
- Pages are registered by name and persist until explicitly closed
- Launches Chromium with
-
Client (
connect()insrc/client.ts):- Connects to server's HTTP API
- Uses CDP
targetIdto reliably find pages across reconnections - Returns standard Playwright
Pageobjects for automation
-
Key API Endpoints:
GET /- Returns CDP WebSocket endpointGET /pages- Lists all named pagesPOST /pages- Gets or creates a page by name (body:{ name: string })DELETE /pages/:name- Closes a page
import { connect } from "@/client.js";
const client = await connect("http://localhost:9222");
const page = await client.page("my-page"); // Gets existing or creates new
await page.goto("https://example.com");
// Page persists for future scripts
await client.disconnect(); // Disconnects CDP but page stays alive on server- Use
npx tsxfor running TypeScript files - Use
dotenvor similar if you need to load.envfiles - Use
node:fsfor file system operations