migração

Migrar de Puppeteer para Playwright

Licença e termos

Puppeteer
Apache-2.0, Código aberto
Playwright
Apache-2.0, Código aberto
Tipo de substituição
Substituição completa The same style of browser automation, across Chromium, Firefox and WebKit.

Esta página está escrita em inglês.

Compatibility

The Playwright team says most Puppeteer APIs can be used as they are, and the guide covers moving to both the Playwright Library and Playwright Test. Beyond Chromium, Playwright also drives Firefox and WebKit, which Puppeteer does not support.

Before you switch

  1. Import the browser explicitly: const { chromium } = require('playwright'), then chromium.launch(). firefox and webkit work the same way.
  2. Replace browser.createIncognitoBrowserContext(...) with browser.newContext(...), and use browser contexts for state isolation.
  3. Rename the calls the cheat sheet lists: page.setViewport becomes page.setViewportSize, page.waitForNetworkIdle(...) becomes page.waitForLoadState('networkidle'), and waitUntil: 'networkidle2' becomes waitUntil: 'networkidle'.
  4. Move element actions onto locators: page.click(selector) becomes page.locator(selector).click(), and likewise for focus, hover and tap. page.select becomes selectOption, page.type becomes fill, and file uploads through elementHandle.uploadFile(...) become setInputFiles(...).
  5. Cookies move from the page to the context: browserContext.cookies, browserContext.addCookies and browserContext.clearCookies.
  6. For tests, the guide recommends Playwright Test over Jest plus Puppeteer. Import test and expect from @playwright/test, take page from the test’s parameters, and replace page.$eval() checks with web-first assertions such as expect(locator).toContainText(...).

Pitfalls

Guia oficial

Guia de migração de Playwright ↗

Revisado em 2026-09-29.

Fontes

Outras alternativas a Puppeteer →