Skip to content

docs: add runnable example scripts#23

Open
ntegrals wants to merge 1 commit intomasterfrom
docs/examples
Open

docs: add runnable example scripts#23
ntegrals wants to merge 1 commit intomasterfrom
docs/examples

Conversation

@ntegrals
Copy link
Copy Markdown
Owner

@ntegrals ntegrals commented Apr 1, 2026

Summary

Adds an examples/ directory with 6 runnable scripts demonstrating core Open Browser features. Each example is self-contained, type-checked, and includes usage instructions in a doc comment.

Examples

Example What it demonstrates
basic-agent.ts Simplest possible usage — give a task, get a result
extract-data.ts Extract structured data from a web page
multi-provider.ts Switch between OpenAI, Anthropic, and Google with a CLI arg
step-callbacks.ts Monitor agent progress with onStepStart/onStepEnd/onDone hooks
headless-vs-visible.ts Run headless or with a visible browser window
url-security.ts Restrict navigation with allowedUrls on Viewport

Running

# Set an API key
export ANTHROPIC_API_KEY=sk-...

# Run any example
bun run examples/basic-agent.ts
bun run examples/multi-provider.ts openai
bun run examples/headless-vs-visible.ts visible

Design choices

  • All examples use claude-haiku-4-5-20251001 for low cost
  • Every example includes try/finally with browser.close() for clean shutdown
  • Examples import from open-browser (the workspace package), so they work immediately after bun install
  • No external dependencies beyond what's already in the monorepo

Test plan

  • All 6 examples pass tsc --noEmit type checking
  • Manual: bun run examples/basic-agent.ts completes successfully
  • Manual: bun run examples/multi-provider.ts anthropic works

Six examples demonstrating core features: basic agent usage, data
extraction, multi-provider support, step callbacks, headless vs
visible mode, and URL security policies.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants