Puppeteer vs. Playwright: A Field Manual from Install to Enterprise E2E
Choosing between Puppeteer and Playwright is a recurring infrastructure decision for any team doing browser automation, scraping, PDF generation, or E2E testing. Getting the install right — especially in Docker and CI — and knowing which framework ships auto-waiting, visual regression, and trace debugging out of the box directly determines how much flakiness and boilerplate a project absorbs.
Puppeteer (Google) and Playwright (Microsoft) are the two dominant browser-automation libraries in the Node.js ecosystem, but their install footprints, API ergonomics, and testing capabilities diverge sharply. This guide walks through every supported installation method for both — standard, core-only, system-Chrome, Docker, and mirror-accelerated — along with the exact system dependencies each requires on Linux. It then catalogues the full command surface: launching browsers, page navigation, locator strategies, network interception, cookie and storage management, multi-tab and iframe handling, screenshot and PDF generation, and performance tracing.
Playwright’s built-in test framework gets its own section, with configuration, assertions, parallel projects, and CI integration spelled out. The debugging stack — Codegen, Trace Viewer, Inspector, and UI Mode — is documented with CLI invocations. A side-by-side quick-reference table maps common automation tasks to the equivalent Puppeteer and Playwright calls, and a decision flowchart at the end matches use cases (lightweight scripting vs. cross-browser E2E vs. enterprise test platforms) to the right tool.
The installation complexity gap between the two tools is underappreciated: Playwright’s wizard and `install-deps` command collapse what is a multi-step, distro-specific manual process for Puppeteer into a single CLI invocation.
Playwright’s locator philosophy — role, label, text, test-id — is not just an API preference; it encodes an opinion that selectors should survive DOM refactors, which directly reduces flaky-test triage time in large suites.
Puppeteer’s `puppeteer-core` package is a deliberate design for headless environments, but the guide’s explicit warning against mixing `puppeteer` and `puppeteer-core` in the same project highlights a footgun that new users routinely hit.
The side-by-side quick-reference table reveals that for basic operations (screenshot, PDF, click, type, evaluate) the APIs are nearly identical, suggesting that the real switching cost is not syntax but the surrounding test infrastructure and debugging tooling.
Playwright’s `storageState` mechanism and project dependencies in the config file solve the ‘log in once, reuse across tests’ problem declaratively; Puppeteer requires manual cookie serialization with `fs.writeFileSync`, which is fragile across browser versions.