Automate Browser Interactions with Playwright
Reliable browser automation with Playwright and Puppeteer - user-facing locators, auto-wait, stealth scraping, and parallel execution patterns.
Why it matters
Master browser automation for robust web testing, efficient data scraping, and seamless AI agent interactions. Learn to build reliable systems using Playwright and Puppeteer, avoiding common pitfalls.
Outcomes
What it gets done
Implement Playwright and Puppeteer for browser automation.
Develop strategies for web scraping and bot detection evasion.
Write resilient end-to-end tests for web applications.
Utilize user-facing locators and auto-wait patterns for stable scripts.
Install
Add it to your toolbox
Run in your project directory:
curl -fsSL https://spark.entire.vc/get/ag-browser-automation | bash Overview
Browser Automation
Covers reliable browser automation patterns with Playwright and Puppeteer - user-facing locators, auto-wait, test isolation, error recovery, parallel execution, and stealth techniques for bot-protected sites. Use when building E2E tests, scrapers, or agent browser control that needs to survive CI, redesigns, or anti-bot detection rather than a one-off script.
What it does
Skill covering reliable browser automation with Playwright (the recommended default: 96% success rate, roughly 4.5s average execution, cross-browser, Microsoft-backed) and Puppeteer (Chrome-only, 75% success rate at scale, but the stronger stealth-plugin ecosystem), plus a nod to Selenium for legacy systems needing specific language bindings. It draws a hard line between testing automation (predictable apps you control) and scraping or agent automation (unpredictable sites that actively fight back) as fundamentally different problems needing different tactics. Core patterns: user-facing locators in strict priority order (getByRole, then getByText, getByLabel, getByTestId, and CSS/XPath only as a last resort) instead of brittle CSS classes or XPath; Playwright's built-in auto-wait, never adding waitForTimeout or manual sleeps and instead waiting on specific conditions like waitForResponse or waitForURL; full test isolation via fresh browser contexts, with a shared-authentication pattern that saves login state once via storageState and reuses it across tests; error recovery via automatic screenshot-on-failure, retained traces and video on failure, and exponential-backoff retries; parallel execution across isolated browser contexts with concurrency limits via p-limit; and network interception to block images, fonts, and analytics for faster scraping or to mock API responses for deterministic tests. For anti-bot-protected sites it documents stealth techniques - puppeteer-extra-plugin-stealth, playwright-extra, undetected-chromedriver, hiding navigator.webdriver, randomized delays and human-like mouse movement, proxy and user-agent rotation - and managed cloud-browser services (Browserbase, BrowserStack) as an alternative to self-maintained stealth.
The skill also catalogs recurring failure modes: waitForTimeout causing flaky, slow tests; CSS selectors breaking on redesigns; navigator.webdriver triggering instant blocks; shared test state causing order-dependent failures; missing CI traces making failures undebuggable; headless-versus-headed rendering differences; rate-limiting after bursts of requests; unhandled popups and new windows; and iframe content requiring an explicit frameLocator rather than the page's default locator scope.
When to use - and when NOT to
Use for building or hardening E2E tests, web scrapers, or browser-driving AI agents where reliability, not just "it worked once," matters. Choose Playwright by default in 2025 unless Puppeteer's stealth ecosystem or a Chrome-only constraint applies. This skill is not for API testing, load testing, accessibility testing, or visual regression testing - it explicitly delegates those to backend, performance-thinker, accessibility-specialist, and ui-design skills respectively, and hands off desktop automation beyond the browser to computer-use-agents.
Inputs and outputs
Input is a target URL plus a set of user-facing selectors (role, text, label) or, for scraping, an unpredictable third-party page. Output is either a pass/fail test result with attached screenshot, trace, and video artifacts on failure, or extracted structured data (with a success flag and captured debug info on error) for scraping tasks.
// By role - THE BEST CHOICE
await page.getByRole('button', { name: 'Submit' }).click();
await page.getByRole('link', { name: 'Sign up' }).click();
await page.getByRole('heading', { name: 'Dashboard' }).isVisible();
await page.getByRole('textbox', { name: 'Search' }).fill('query');
Integrations
Playwright and Puppeteer as the core frameworks, with puppeteer-extra-plugin-stealth, playwright-extra, and undetected-chromedriver for anti-detection; p-limit for concurrency-limited parallel scraping; and Browserbase or BrowserStack as managed cloud-browser alternatives to running stealth infrastructure yourself.
Who it's for
QA engineers writing E2E test suites, data engineers building scrapers against sites with anti-bot protection, and developers giving an AI agent browser-control tools - anyone who needs the difference between a flaky script and a reliable automation system spelled out as concrete patterns and fixes.
FAQ
Common questions
Discussion
Questions & comments · 0
Sign In Sign in to leave a comment.