This online tool is built for developers and QA. It will replace existing Puppeteer syntax with Playwright syntax.
You can quickly convert your existing Puppeteer scripts to Playwright, without having to manually do the conversion yourself.
Why should I migrate from Puppeteer scripts to Playwright scripts?
There are multiple reasons why you would want to start using Playwright. One reason is that Playwright runs on non-chromium based browsers, such as Firefox. Another reason might be that you want to use a library or specific Playwright extension.
While both are very similar in the features they offer and even the syntax, there are some subtle differences. Puppeteer uses the CDP protocol to instrument browsers, whereas Playwright uses its own, custom protocol.
How can I manually convert Puppeteer code to Playwright code?
Changing the required package
First, you need to change the require of the Puppeteer package to Playwright. You'll need to replace the code below.
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
With a new require, requiring the Playwright package.
Cookies
Puppeteer handles cookies at the page level, whereas with Playwright you will need to manipulate the cookies at the BrowserContext level. This means that these Puppeteer cookie functions:
page.cookies([...urls])
page.deleteCookie(...cookies)
page.setCookie(...cookies)
will become these functions with Playwright:
browserContext.cookies([urls])
browserContext.clearCookies()
browserContext.addCookies(cookies)
Viewport
Puppeteer's page.setViewport
becomes page.setViewportSize
in Playwright.