Browser Automation with Claude Code

Browser Automation with Claude Code

The pattern of connecting a browser automation CLI (Playwright) to Claude Code so it can control a real browser — navigating, clicking, filling forms, taking screenshots, and running QA loops — as part of an agentic workflow.

Key points

  • Setup: install Playwright CLI in a project, run /init to create CLAUDE.md, then prompt Claude to write and iterate automation scripts in JavaScript [src-011]
  • Each automation task gets its own bot script; scripts accumulate and improve across runs as Claude learns which selectors work for a given UI [src-011]
  • Headed mode (visible browser) for debugging; headless mode for production scheduled tasks [src-011]
  • Self-QA loop: Claude builds, runs a Playwright test, reads bug output, patches code, re-runs — until tests pass without human input [src-011]
  • Authenticated automation: launch browser using existing Chrome user-data directory so Claude inherits active login sessions (no re-login) [src-011]
  • Adaptive learning: when Google blocked the scraper, Claude autonomously switched to DuckDuckGo mid-run [src-011]
  • Pairing automations with skills makes them consistently repeatable via a single natural-language invocation [src-011]
  • Token efficiency: use CLI over MCP — Chrome DevTools MCP loads hundreds of tool definitions into context; CLI avoids this entirely [src-011]
  • The 10-hour course places browser automation in the advanced Claude Code stack, after fundamentals like project structure, APIs, MCPs, skills, sub-agents, permissions, and context management [src-016]
  • OpenAI's Codex Chrome extension adds the Codex version of the pattern: the agent can work in the user's real Chrome profile, with existing cookies, logged-in apps, multiple tabs, tab groups, plugins, and code execution [src-084].
  • The source distinguishes connector-first from browser-first work: use structured plugins when available, and use Chrome when the task requires the full web app, current logged-in session, or UI-only capabilities [src-084].

Production use case: community engagement bot

Nate's AIS agent bot runs via Claude Code scheduled tasks and Playwright headless to autonomously manage his School.com community — posting daily AI news roundups, liking posts, replying to comments, and voting on polls. The bot built the "vote on poll" capability on its own after encountering an unseen UI pattern. [src-011]

Related entities

Related concepts

Source references

  • [src-011] Nate Herk — Claude Code power features cluster (2026-04-20 to 2026-04-27)
  • [src-016] Nate Herk — "Build & Sell with Claude Code (10+ Hour Course)" (2026-03-12)
  • [src-084] OpenAI Codex, Workspace Agents, Prompt Caching, and Superintelligence Policy cluster (2026-02-09 to 2026-05-08)