This repo is a fork of main puppeteer project. It creates a version of puppeteer core specialized for use in Cloudflare workers.
The goals of the fork are:
- Support as much of the existing puppeteer core lib as possible.
- Minimize the size of the library for workers developers, since library space is at a premium in workers projects.
- Make library use as seamless as possible in workers.
Note that the main branch in this repo is branched off of version 22.8.2 of the library, to match the currently deployed version of Chromium on the edge.
More information in the developer docs.
Original README follows...
Puppeteer is a Node.js library which provides a high-level API to control Chrome/Chromium over the DevTools Protocol. Puppeteer runs in headless mode by default, but can be configured to run in full ("headful") Chrome/Chromium.
Get started | API | FAQ | Contributing | Troubleshooting
import puppeteer from 'puppeteer';
(async () => {
// Launch the browser and open a new blank page
const browser = await puppeteer.launch();
const page = await browser.newPage();
// Navigate the page to a URL
await page.goto('https://developer.chrome.com/');
// Set screen size
await page.setViewport({width: 1080, height: 1024});
// Type into search box
await page.type('.devsite-search-field', 'automate beyond recorder');
// Wait and click on first result
const searchResultSelector = '.devsite-result-item-link';
await page.waitForSelector(searchResultSelector);
await page.click(searchResultSelector);
// Locate the full title with a unique string
const textSelector = await page.waitForSelector(
'text/Customize and automate'
);
const fullTitle = await textSelector?.evaluate(el => el.textContent);
// Print the full title
console.log('The title of this blog post is "%s".', fullTitle);
await browser.close();
})();
1. Uses Headless mode
By default Puppeteer launches Chrome in old Headless mode.
const browser = await puppeteer.launch();
// Equivalent to
const browser = await puppeteer.launch({headless: true});
Chrome 112 launched a new Headless mode that might cause some differences in behavior compared to the old Headless implementation. In the future Puppeteer will start defaulting to new implementation. We recommend you try it out before the switch:
const browser = await puppeteer.launch({headless: 'new'});
To launch a "headful" version of Chrome, set the
headless
to false
option when launching a browser:
const browser = await puppeteer.launch({headless: false});
2. Runs a bundled version of Chrome
By default, Puppeteer downloads and uses a specific version of Chrome so its
API is guaranteed to work out of the box. To use Puppeteer with a different
version of Chrome or Chromium, pass in the executable's path when creating a
Browser
instance:
const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});
You can also use Puppeteer with Firefox. See status of cross-browser support for more information.
See
this article
for a description of the differences between Chromium and Chrome.
This article
describes some differences for Linux users.
3. Creates a fresh user profile
Puppeteer creates its own browser user profile which it cleans up on every run.
See our Docker guide.
See our Chrome extensions guide.
Check out our contributing guide to get an overview of Puppeteer development.
Our FAQ has migrated to our site.
main