Move Puppeteer scripts and tests to Playwright: launch, contexts, viewport, network idle, $eval, clicks, typing, uploads, cookies and request interception mapped to Playwright code, with a checklist, gotchas and live numbers for both tools.
Puppeteer (live data): 95,892 GitHub stars. 16,010,870 weekly npm downloads (puppeteer), +38% over 4 weeks. 7 GitHub releases in the last 60 days, latest v25.18.1. last GitHub activity 2026-11-22
Playwright (live data): 100,863 GitHub stars. 138,786,046 weekly npm downloads (@playwright/test), +68% over 4 weeks. 4 GitHub releases in the last 60 days, latest v1.65.1. last GitHub activity 2026-11-22
Launch a browser: Puppeteer: const browser = await puppeteer.launch() → Playwright: const browser = await chromium.launch() // in Playwright Test, use the page fixture instead
Other browsers: Puppeteer: await puppeteer.launch({ browser: 'firefox' }) // WebKit: not supported → Playwright: await firefox.launch() await webkit.launch()
Isolated context: Puppeteer: const context = await browser.createBrowserContext() → Playwright: const context = await browser.newContext() (Playwright's migration table shows the older createIncognitoBrowserContext; current Puppeteer calls it createBrowserContext.)
Viewport: Puppeteer: await page.setViewport({ width: 1280, height: 800 }) → Playwright: await page.setViewportSize({ width: 1280, height: 800 })
Wait for network idle: Puppeteer: await page.goto(url, { waitUntil: 'networkidle2' }) await page.waitForNetworkIdle() → Playwright: await page.goto(url, { waitUntil: 'networkidle' }) await page.waitForLoadState('networkidle') (Playwright marks networkidle as discouraged for testing; prefer a web-first assertion on what you expect to see.)
Read text and assert: Puppeteer: await page.waitForSelector('.hero__title') const text = await page.$eval('.hero__title', e => e.textContent) expect(text).toContain('Playwright enables reliable end-to-end testing') → Playwright: await expect(page.locator('.hero__title')).toContainText( 'Playwright enables reliable end-to-end testing')
Query elements: Puppeteer: await page.$('button') await page.$('li') → Playwright: page.locator('button') page.locator('li') (Playwright discourages ElementHandle in favour of locators. Puppeteer's docs also recommend its own page.locator().)
Click, hover, focus: Puppeteer: await page.click(selector) await page.hover(selector) await page.focus(selector) → Playwright: await page.locator(selector).click() await page.locator(selector).hover() await page.locator(selector).focus()
Type and select: Puppeteer: await page.type(selector, 'text') await page.select(selector, 'value') → Playwright: await page.locator(selector).fill('text') await page.locator(selector).selectOption('value') (page.type sends key presses; fill sets the value. Use pressSequentially when the page reacts to each key.)
Checkboxes: Puppeteer: await page.click('#agree') // no dedicated check method → Playwright: await page.locator('#agree').check() await page.locator('#agree').uncheck()
File upload: Puppeteer: const [chooser] = await Promise.all([ page.waitForFileChooser(), page.click('#upload'), ]) await chooser.accept(['file.pdf']) → Playwright: await page.locator('#upload').setInputFiles('file.pdf') (setInputFiles needs an <input type="file">. If #upload is a button that opens the chooser, wait for page.waitForEvent('filechooser') while clicking it, then call setFiles('file.pdf') on the chooser.)
Cookies: Puppeteer: await browser.cookies() await browser.setCookie(...cookies) → Playwright: await browserContext.cookies() await browserContext.addCookies(cookies) await browserContext.clearCookies() (Puppeteer has deprecated its page-level cookie methods in favour of Browser and BrowserContext.)
Block or mock requests: Puppeteer: await page.setRequestInterception(true) page.on('request', req => { if (/\.(png|jpe?g)$/.test(req.url())) req.abort() else req.continue() }) → Playwright: await page.route('**/*.{png,jpg,jpeg}', route => route.abort()) (Only matching requests are routed; the rest continue untouched. route.fulfill mocks a response.)
Evaluate and screenshot: Puppeteer: await page.evaluate(() => document.location.href) await page.screenshot({ path: 'example.png' }) → Playwright: await page.evaluate(() => document.location.href) await page.screenshot({ path: 'example.png' }) (Same names and shape.)
Test runner: Puppeteer: beforeAll(async () => { browser = await puppeteer.launch() page = await browser.newPage() }) afterAll(() => browser.close()) → Playwright: import { test, expect } from '@playwright/test' test('contains hero title', async ({ page }) => { await page.goto('https://playwright.dev/') }) (Playwright Test gives each test a fresh page; no launch or close code.)
Checked against: puppeteer 25.17.0, playwright 1.65.0, @playwright/test 1.65.0 (npm registry, 2026-11-10)