| name | puppeteer |
| description | Puppeteer headless Chrome automation. Use for browser automation. |
Puppeteer
Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the DevTools Protocol.
When to Use
- Chrome Specific: If testing cross-browser isn't a priority (or you only care about Chromium).
- Web Scraping: Excellent for scraping SPAs because it renders JS.
- PDF/Screenshots: The industry standard for "HTML to PDF" generation.
Quick Start
import puppeteer from "puppeteer";
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto("https://developer.chrome.com/");
await page.pdf({ path: "dv.pdf", format: "A4" });
await browser.close();
})();
Core Concepts
DevTools Protocol (CDP)
Puppeteer talks directly to Chrome via CDP. This allows deeper control (intercepting network at a low level, CPU profiling) than WebDriver.