Puppeteer overview
The Puppeteer library provides a high-level API to control Chromium-based browsers, including Microsoft Edge, by using the DevTools Protocol.
Puppeteer launches headless browsers by default. Headless browsers don't display a user interface (UI), so you must use the command line. You can also configure Puppeteer to run full (non-headless) Microsoft Edge.
By default, when you install Puppeteer, the installer downloads a recent version of Chromium, the open-source browser that Microsoft Edge is also built upon.
If you have Microsoft Edge installed, you can use puppeteer-core. puppeteer-core
is a lightweight version of Puppeteer that launches an existing browser installation, like Microsoft Edge. To download Microsoft Edge, go to Download Microsoft Edge Insider Channels.
Puppeteer is a Node library.
Installing puppeteer-core
You can add puppeteer-core
to your website or app by using one of the following commands:
npm i puppeteer-core
yarn add puppeteer-core
Launch Microsoft Edge with puppeteer-core
puppeteer-core
is similar to other browser-testing-frameworks, such as WebDriver. You create an instance of the browser, open a webpage, and then manipulate the webpage by using the Puppeteer API.
To use puppeteer-core
to launch Microsoft Edge:
puppeteer-core
requires Node v8.9.0 or later. Make sure you have a compatible version of Node.js. To do this, runnode -v
from the command line. Also, the example below usesasync
/await
, which is only supported in Node v7.6.0 or later.In the following code sample,
puppeteer-core
launches Microsoft Edge, goes tohttps://www.microsoft.com/edge/download/insider
, and saves a screenshot asexample.png
. Copy the following code snippet and save it asexample.js
:const puppeteer = require('puppeteer-core'); (async () => { const browser = await puppeteer.launch({ executablePath: 'C:\\Program Files (x86)\\Microsoft\\Edge Dev\\Application\\msedge.exe' }); const page = await browser.newPage(); await page.goto('https://www.microsoft.com/edge/download/insider'); await page.screenshot({path: 'example.png'}); await browser.close(); })();
Follow the next steps to find the executable path and then change
executablePath
to point to your installation of Microsoft Edge. For example, on macOS, theexecutablePath
for Microsoft Edge Canary should be set to/Applications/Microsoft\ Edge\ Canary.app/
.To find the
executablePath
, a simple manual approach is to go toedge://version
and copy the Executable path on that page.Or, to programmatically find the executable path, first install the edge-paths package by running one of the following commands:
npm i edge-paths
yarn add edge-paths
Then, if you're using
edge-paths
to find the executable path, run code like the following sample. It uses the edge-paths package to programmatically find the path to your installation of Microsoft Edge on your OS:const edgePaths = require("edge-paths"); const EDGE_PATH = edgePaths.getEdgePath();
Now that you've found the executable path (either manually or programmatically), in
example.js
, setexecutablePath: EDGE_PATH
. Save your changes.Run
example.js
from the command line:node example.js
puppeteer-core
launches Microsoft Edge, goes tohttps://www.microsoft.com/edge/download/insider
, and saves a screenshot of the webpage. You can customize the screenshot size by calling page.setViewport().The following
example.png
file is produced byexample.js
:
The preceding example demonstrates basic automation and testing scenarios that you can cover using Puppeteer and puppeteer-core
. For more information about Puppeteer and how it works, check out Puppeteer.
See also
Local articles
- WebDriver
- Contact the Microsoft Edge DevTools team to send feedback about using Puppeteer, puppeteer-core, and Microsoft Edge.
- Chrome DevTools Protocol (CDP) in Overview of WebView2 features and APIs
- Use the Chrome DevTools Protocol (CDP) in WebView2 apps
Archive
Blog posts
Tools
- Download Microsoft Edge Insider Channels
- Chromium on The Chromium Projects
- Node.js
- Puppeteer
- puppeteer vs. puppeteer-core
- page.setViewport() on Puppeteer