https://github.com/checkly/puppeteer-to-playwright
Puppeteer to Playwright conversion script
https://github.com/checkly/puppeteer-to-playwright
Last synced: about 1 year ago
JSON representation
Puppeteer to Playwright conversion script
- Host: GitHub
- URL: https://github.com/checkly/puppeteer-to-playwright
- Owner: checkly
- License: mit
- Created: 2021-12-16T10:51:36.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-05-09T13:32:59.000Z (about 3 years ago)
- Last Synced: 2025-04-11T16:07:36.799Z (about 1 year ago)
- Language: JavaScript
- Size: 133 KB
- Stars: 141
- Watchers: 5
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
puppeteer-to-playwright
`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](https://github.com/facebook/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](#strict-mode))
- 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](#-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]((https://github.com/facebook/jscodeshift)).
### 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](https://github.com/facebook/jscodeshift) - without which this project wouldn't be possible.
- [ASTExplorer](https://astexplorer.net/) - useful debugging tool in case you would like to modify the transform file of this project to tweak its output.
## License
[MIT](https://github.com/checkly/puppeteer-to-playwright/blob/main/LICENSE)
Code, test, and deploy synthetic monitoring at scale
From Checkly with ♥️