migration

Migrer de Puppeteer vers Playwright

Licence et conditions

Puppeteer
Apache-2.0, Open source
Playwright
Apache-2.0, Open source
Type de remplacement
Remplacement complet The same style of browser automation, across Chromium, Firefox and WebKit.

Cette page est rédigée en anglais.

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

Guide officiel

Guide de migration de Playwright ↗

Relue le 2026-09-29.

Sources

Autres alternatives à Puppeteer →