1 | # Puppeteer
|
2 |
|
3 | [![build](https://github.com/puppeteer/puppeteer/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/puppeteer/puppeteer/actions/workflows/ci.yml)
|
4 | [![npm puppeteer package](https://img.shields.io/npm/v/puppeteer.svg)](https://npmjs.org/package/puppeteer)
|
5 |
|
6 | <img src="https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png" height="200" align="right"/>
|
7 |
|
8 | > Puppeteer is a JavaScript library which provides a high-level API to control
|
9 | > Chrome or Firefox over the
|
10 | > [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/) or [WebDriver BiDi](https://pptr.dev/webdriver-bidi).
|
11 | > Puppeteer runs in the headless (no visible UI) by default
|
12 |
|
13 | ## [Get started](https://pptr.dev/docs) | [API](https://pptr.dev/api) | [FAQ](https://pptr.dev/faq) | [Contributing](https://pptr.dev/contributing) | [Troubleshooting](https://pptr.dev/troubleshooting)
|
14 |
|
15 | ## Installation
|
16 |
|
17 | ```bash npm2yarn
|
18 | npm i puppeteer # Downloads compatible Chrome during installation.
|
19 | npm i puppeteer-core # Alternatively, install as a library, without downloading Chrome.
|
20 | ```
|
21 |
|
22 | ## Example
|
23 |
|
24 | ```ts
|
25 | import puppeteer from 'puppeteer';
|
26 | // Or import puppeteer from 'puppeteer-core';
|
27 |
|
28 | // Launch the browser and open a new blank page
|
29 | const browser = await puppeteer.launch();
|
30 | const page = await browser.newPage();
|
31 |
|
32 | // Navigate the page to a URL.
|
33 | await page.goto('https://developer.chrome.com/');
|
34 |
|
35 | // Set screen size.
|
36 | await page.setViewport({width: 1080, height: 1024});
|
37 |
|
38 | // Type into search box.
|
39 | await page.locator('.devsite-search-field').fill('automate beyond recorder');
|
40 |
|
41 | // Wait and click on first result.
|
42 | await page.locator('.devsite-result-item-link').click();
|
43 |
|
44 | // Locate the full title with a unique string.
|
45 | const textSelector = await page
|
46 | .locator('text/Customize and automate')
|
47 | .waitHandle();
|
48 | const fullTitle = await textSelector?.evaluate(el => el.textContent);
|
49 |
|
50 | // Print the full title.
|
51 | console.log('The title of this blog post is "%s".', fullTitle);
|
52 |
|
53 | await browser.close();
|
54 | ```
|