Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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 a preview channel of Microsoft Edge (Beta, Dev, or Canary), go to Become a Microsoft Edge Insider.
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-corerequires Node v8.9.0 or later. Make sure you have a compatible version of Node.js. To do this, runnode -vfrom 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-corelaunches 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
executablePathto point to your installation of Microsoft Edge. For example, on macOS, theexecutablePathfor Microsoft Edge Canary should be set to/Applications/Microsoft\ Edge\ Canary.app/.To find the
executablePath, a simple manual approach is to go toedge://versionand 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-pathsyarn add edge-pathsThen, if you're using
edge-pathsto 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.jsfrom the command line:node example.jspuppeteer-corelaunches 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.pngfile 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
- Use WebDriver to automate Microsoft Edge
- 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 APIs
- Use the Chrome DevTools Protocol (CDP) in WebView2 apps
Archive
Blog posts
Tools
- Become a Microsoft Edge Insider - download a preview channel of Microsoft Edge (Beta, Dev, or Canary).
- Chromium on The Chromium Projects
- Node.js
- Puppeteer
- puppeteer vs. puppeteer-core
- page.setViewport() on Puppeteer