UNPKG

2.09 kBMarkdownView Raw
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 Node.js 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> but can be configured to run in a visible ("headful") browser.
13
14## [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)
15
16## Installation
17
18```bash npm2yarn
19npm i puppeteer # Downloads compatible Chrome during installation.
20npm i puppeteer-core # Alternatively, install as a library, without downloading Chrome.
21```
22
23## Example
24
25```ts
26import puppeteer from 'puppeteer';
27// Or import puppeteer from 'puppeteer-core';
28
29// Launch the browser and open a new blank page
30const browser = await puppeteer.launch();
31const page = await browser.newPage();
32
33// Navigate the page to a URL.
34await page.goto('https://developer.chrome.com/');
35
36// Set screen size.
37await page.setViewport({width: 1080, height: 1024});
38
39// Type into search box.
40await page.locator('.devsite-search-field').fill('automate beyond recorder');
41
42// Wait and click on first result.
43await page.locator('.devsite-result-item-link').click();
44
45// Locate the full title with a unique string.
46const textSelector = await page
47 .locator('text/Customize and automate')
48 .waitHandle();
49const fullTitle = await textSelector?.evaluate(el => el.textContent);
50
51// Print the full title.
52console.log('The title of this blog post is "%s".', fullTitle);
53
54await browser.close();
55```