Puppeteer overview

Puppeteer is a Node library that provides a high-level API to control Microsoft Edge (Chromium) using the DevTools Protocol. Puppeteer launches headless browsers by default. Headless browsers do not display a UI, so instead you must use the command line. You may also configure Puppeteer to run full (non-headless) Microsoft Edge as well.

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 (Chromium) installed, you may use puppeteer-core. puppeteer-core is a lightweight version of Puppeteer that launches an existing browser installation, like Microsoft Edge (Chromium). To download Microsoft Edge (Chromium), navigate to Download Microsoft Edge Insider Channels.

Installing puppeteer-core

You may add puppeteer-core to your website or app with one of the following commands.

npm i puppeteer-core
yarn add puppeteer-core

Launch Microsoft Edge with puppeteer-core

Note

puppeteer-core relies on Node v8.9.0 or later. The example below uses async/await which is only supported in Node v7.6.0 or later. Run node -v from the command-line to ensure you have a compatible version of Node.js.

puppeteer-core should be familiar to users of other browser-testing-frameworks like WebDriver. You create an instance of the browser, open a page, and then manipulate it with the Puppeteer API. In the following code sample, puppeteer-core launches Microsoft Edge (Chromium), navigates to https://www.microsoftedgeinsider.com, and saves a screenshot as example.png.

Copy the following code snippet and save it as example.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.microsoftedgeinsider.com');
  await page.screenshot({path: 'example.png'});

  await browser.close();
})();

Change executablePath to point to your installation of Microsoft Edge (Chromium). For example, on macOS, the executablePath for Microsoft Edge Canary should be set to /Applications/Microsoft\ Edge\ Canary.app/. To find the executablePath, navigate to edge://version and copy the Executable path on that page or install the edge-paths package with one of the following commands.

npm i edge-paths
yarn add edge-paths

The code sample below uses the edge-paths package to programmatically find the path to your installation of Microsoft Edge (Chromium) on your OS.

const edgePaths = require("edge-paths");

const EDGE_PATH = edgePaths.getEdgePath();

Finally, set executablePath: EDGE_PATH in example.js. Save your changes.

Note

Microsoft Edge (EdgeHTML) does not work with puppeteer-core. You must install the Microsoft Edge Insider channels to continue following this example.

Now, run example.js from the command line.

node example.js

puppeteer-core launches Microsoft Edge, navigates to https://www.microsoftedgeinsider.com, and saves a screenshot of the webpage. Customize the screenshot size with page.setViewport().

The example.png file produced by example.js

This is just a simple example of the automation and testing scenarios enabled by Puppeteer and puppeteer-core. For more information about Puppeteer and how it works, navigate to Puppeteer.

Getting in touch with the Microsoft Edge DevTools team

The Microsoft Edge Developer team is eager to hear your feedback about using Puppeteer, puppeteer-core, and Microsoft Edge. Use the Send Feedback icon in the Microsoft Edge DevTools or tweet @EdgeDevTools to let the Microsoft Edge team know what you think.

The Send Feedback icon in the Microsoft Edge DevTools