• Stars
    star
    136
  • Rank 267,670 (Top 6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 3 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Puppeteer to Playwright conversion script

puppeteer-to-playwright

Github Action - CI Test Github package.json Version


puppeteer-to-playwright automatically converts Javascript Puppeteer scripts to Playwright, aiming to reduce the amount of manual work involved in such a migration (ideally reducing it to zero). It is heavily based on jscodeshift.

puppeteer-to-playwright requires Node.js 14 or newer.

Features

puppeteer-to-playwright will convert your existing Puppeteer script to Playwright, including:

  • Converting import statements
  • Converting basic methods to match new API (e.g. setViewport to setViewportSize and similar)
  • Creating browser context explicitly
  • Eliminating explicit waiting (unless Strict mode is enabled)
  • Converting cookies-related commands

Currently unsupported

The following features are not yet supported, meaning that the corresponding instructions won't be converted to Playwright if they are used in your Puppeteer script:

  • File upload
  • File download
  • Request/response interception
  • Multiple contexts / tabs

Still, these might very well be implemented in the near future. If you would like to help, see our how to contribute section.


Getting Started

You can use puppeteer-to-playwright on a script file or multiple scripts at a time.

🚨 It will overwrite the script file when run, so we recommend doing a dry-run first.

Dry run

A dry run will run the conversion without actually writing to the file(s) you point it at.

$ npm run convert -- -d my-puppeteer-script.js

You can add -p to print out the resulting script:

$ npm run convert -- -d -p my-puppeteer-script.js

You can pass additional jscodeshift parameters as described in the project's repository.

Convert script

You can convert scripts one by one...

$ npm run convert my-puppeteer-script.js

...or you can convert entire folders recursively.

$ npm run convert my-puppeteer-folder

puppeteer-to-playwright will ignore files that have any extension other than .js, as well as those that do not import/require Puppeteer.

Strict mode

When converting files, puppeteer-to-playwright will, by default, get rid of likely unnecessary waits that Playwright should handle automatically. If you know that the waits in your Puppeteer script will remain necessary even with Playwright, you can set puppeteer-to-playwright to Strict mode by running export STRICT=true. Alternatively, you can set the flag directly when converting a file or folder, e.g.: STRICT=true npm run convert my-puppeteer-folder


How to contribute

If you would like to improve this codemod, you are very welcome to send a PR. Make sure it contains a test for the specific feature you are trying to add. Testing is currently set up as follows:

  1. In test/base you have the original Puppeteer script
  2. In test/output you have the original Puppeteer script, which will be automatically converted when tests are run then immediately restored to the original
  3. In test/expected you have the expected Playwright script that your result will need to be equal to

You can run npm run test locally, and tests will run automatically for each new PR.


Links

  • jscodeshift - without which this project wouldn't be possible.
  • ASTExplorer - useful debugging tool in case you would like to modify the transform file of this project to tweak its output.

License


MIT

Checkly
Code, test, and deploy synthetic monitoring at scale
From Checkly with ♥️

More Repositories

1

headless-recorder

Chrome extension that records your browser interactions and generates a Playwright or Puppeteer script.
JavaScript
15,032
star
2

puppeteer-examples

Puppeteer example scripts for running Headless Chrome from Node.
JavaScript
2,959
star
3

theheadless.dev

🪖 Learn Puppeteer and Playwright - Tips, tricks and in-depth guides from the trenches.
Vue
397
star
4

checkly-cli

TS/JS native Monitoring as Code workflow
TypeScript
63
star
5

docs.checklyhq.com

Checkly docs
SCSS
55
star
6

terraform-provider-checkly

Terraform provider for the Checkly monitoring service
Go
44
star
7

public-roadmap

Checkly public roadmap. All planned features, updates and tweaks.
37
star
8

headless-benchmarks

Benchmarking scripts for Puppeteer, Playwright, WebDriverIO & Cypress.
JavaScript
34
star
9

jamstack-deploy

Measure cloud providers and check which fits better for your Jamstack App.
Vue
30
star
10

pulumi-checkly

Pulumi provider for the Checkly monitoring service
Python
19
star
11

checkly-go-sdk

Go SDK library for use with the Checkly API
Go
16
star
12

checkly-operator

Kubernetes checkly operator
Go
11
star
13

vitals-tester

CSS
10
star
14

checkly-k8s

Checkly Kubernetes Helm chart and manifests
Smarty
6
star
15

nextjs-conf-performance-demo

JavaScript
6
star
16

handlebars

A simple wrapper for Handlebars that can be used as a drop-in replacement
JavaScript
4
star
17

danube-store

Vue
4
star
18

checkly-ci-test

Vue
3
star
19

browser-checks-starter

Examples and scripts accompanying the getting started docs on writing browser checks
JavaScript
3
star
20

checkly-terraform-getting-started

HCL
3
star
21

browser-checks-starter-mocha

Examples and scripts accompanying the getting started docs on writing browser checks
JavaScript
2
star
22

pingdom-2-checkly

A simple Node script to convert Pingdom HTTP checks to Checkly and import them
JavaScript
2
star
23

next-commerce-demo

TypeScript
2
star
24

serverless-plugin-select-resource

serverless plugin for selecting which resources to be deployed based on region and stage
JavaScript
2
star
25

my-gatsby-blog

JavaScript
1
star
26

guides-monitoring-as-code

JavaScript
1
star
27

mac-demo-repo

JavaScript
1
star
28

dns_debug_script

JavaScript
1
star
29

checkly-sample-pom

TypeScript
1
star