chore: release main (#9115)
This commit is contained in:
parent
8f4902eed9
commit
dc66207f25
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"packages/puppeteer": "18.2.1",
|
"packages/puppeteer": "19.0.0",
|
||||||
"packages/puppeteer-core": "18.2.1",
|
"packages/puppeteer-core": "19.0.0",
|
||||||
"packages/testserver": "0.6.0"
|
"packages/testserver": "0.6.0"
|
||||||
}
|
}
|
||||||
|
12
package-lock.json
generated
12
package-lock.json
generated
@ -8488,21 +8488,21 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/puppeteer": {
|
"packages/puppeteer": {
|
||||||
"version": "18.2.1",
|
"version": "19.0.0",
|
||||||
"hasInstallScript": true,
|
"hasInstallScript": true,
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"https-proxy-agent": "5.0.1",
|
"https-proxy-agent": "5.0.1",
|
||||||
"progress": "2.0.3",
|
"progress": "2.0.3",
|
||||||
"proxy-from-env": "1.1.0",
|
"proxy-from-env": "1.1.0",
|
||||||
"puppeteer-core": "18.2.1"
|
"puppeteer-core": "19.0.0"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=14.1.0"
|
"node": ">=14.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"packages/puppeteer-core": {
|
"packages/puppeteer-core": {
|
||||||
"version": "18.2.1",
|
"version": "19.0.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"cross-fetch": "3.1.5",
|
"cross-fetch": "3.1.5",
|
||||||
@ -8542,9 +8542,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"glob": "8.0.3",
|
"glob": "8.0.3",
|
||||||
"mocha": "10.0.0"
|
"mocha": "10.0.0"
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"cross-env": "7.0.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -9555,7 +9552,6 @@
|
|||||||
"@puppeteer-test/installation": {
|
"@puppeteer-test/installation": {
|
||||||
"version": "file:test/installation",
|
"version": "file:test/installation",
|
||||||
"requires": {
|
"requires": {
|
||||||
"cross-env": "7.0.3",
|
|
||||||
"glob": "8.0.3",
|
"glob": "8.0.3",
|
||||||
"mocha": "10.0.0"
|
"mocha": "10.0.0"
|
||||||
}
|
}
|
||||||
@ -13350,7 +13346,7 @@
|
|||||||
"https-proxy-agent": "5.0.1",
|
"https-proxy-agent": "5.0.1",
|
||||||
"progress": "2.0.3",
|
"progress": "2.0.3",
|
||||||
"proxy-from-env": "1.1.0",
|
"proxy-from-env": "1.1.0",
|
||||||
"puppeteer-core": "18.2.1"
|
"puppeteer-core": "19.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"puppeteer-core": {
|
"puppeteer-core": {
|
||||||
|
@ -2,6 +2,33 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
## [19.0.0](https://github.com/puppeteer/puppeteer/compare/puppeteer-core-v18.2.1...puppeteer-core-v19.0.0) (2022-10-14)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* use `~/.cache/puppeteer` for browser downloads (#9095)
|
||||||
|
* deprecate `createBrowserFetcher` in favor of `BrowserFetcher` (#9079)
|
||||||
|
* refactor custom query handler API (#9078)
|
||||||
|
* remove `puppeteer.devices` in favor of `KnownDevices` (#9075)
|
||||||
|
* deprecate indirect network condition imports (#9074)
|
||||||
|
* deprecate indirect error imports (#9072)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* add ability to collect JS code coverage at the function level ([#9027](https://github.com/puppeteer/puppeteer/issues/9027)) ([a032583](https://github.com/puppeteer/puppeteer/commit/a032583b6c9b469bda699bca200b180206d61247))
|
||||||
|
* deprecate `createBrowserFetcher` in favor of `BrowserFetcher` ([#9079](https://github.com/puppeteer/puppeteer/issues/9079)) ([7294dfe](https://github.com/puppeteer/puppeteer/commit/7294dfe9c6c3b224f95ba6d59b5ef33d379fd09a)), closes [#8999](https://github.com/puppeteer/puppeteer/issues/8999)
|
||||||
|
* use `~/.cache/puppeteer` for browser downloads ([#9095](https://github.com/puppeteer/puppeteer/issues/9095)) ([3df375b](https://github.com/puppeteer/puppeteer/commit/3df375baedad64b8773bb1e1e6f81b604ed18989))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* deprecate indirect error imports ([#9072](https://github.com/puppeteer/puppeteer/issues/9072)) ([9f4f43a](https://github.com/puppeteer/puppeteer/commit/9f4f43a28b06787a1cf97efe904ccfe7237dffdd))
|
||||||
|
* deprecate indirect network condition imports ([#9074](https://github.com/puppeteer/puppeteer/issues/9074)) ([41d0122](https://github.com/puppeteer/puppeteer/commit/41d0122b94f41b308536c48ced345dec8c272a49))
|
||||||
|
* refactor custom query handler API ([#9078](https://github.com/puppeteer/puppeteer/issues/9078)) ([1847704](https://github.com/puppeteer/puppeteer/commit/1847704789e2888c755de8c739d567364b8ad645))
|
||||||
|
* remove `puppeteer.devices` in favor of `KnownDevices` ([#9075](https://github.com/puppeteer/puppeteer/issues/9075)) ([87c08fd](https://github.com/puppeteer/puppeteer/commit/87c08fd86a79b63308ad8d46c5f7acd1927505f8))
|
||||||
|
* remove viewport conditions in `waitForSelector` ([#9087](https://github.com/puppeteer/puppeteer/issues/9087)) ([acbc599](https://github.com/puppeteer/puppeteer/commit/acbc59999bf800eeac75c4045b75a32b4357c79e))
|
||||||
|
|
||||||
## [18.2.1](https://github.com/puppeteer/puppeteer/compare/puppeteer-core-v18.2.0...puppeteer-core-v18.2.1) (2022-10-06)
|
## [18.2.1](https://github.com/puppeteer/puppeteer/compare/puppeteer-core-v18.2.0...puppeteer-core-v18.2.1) (2022-10-06)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "puppeteer-core",
|
"name": "puppeteer-core",
|
||||||
"version": "18.2.1",
|
"version": "19.0.0",
|
||||||
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
|
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"puppeteer",
|
"puppeteer",
|
||||||
|
@ -2,6 +2,36 @@
|
|||||||
|
|
||||||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
||||||
|
|
||||||
|
## [19.0.0](https://github.com/puppeteer/puppeteer/compare/v18.2.1...v19.0.0) (2022-10-14)
|
||||||
|
|
||||||
|
|
||||||
|
### ⚠ BREAKING CHANGES
|
||||||
|
|
||||||
|
* use `~/.cache/puppeteer` for browser downloads (#9095)
|
||||||
|
* deprecate `createBrowserFetcher` in favor of `BrowserFetcher` (#9079)
|
||||||
|
* refactor custom query handler API (#9078)
|
||||||
|
* remove `puppeteer.devices` in favor of `KnownDevices` (#9075)
|
||||||
|
* deprecate indirect network condition imports (#9074)
|
||||||
|
|
||||||
|
### Features
|
||||||
|
|
||||||
|
* deprecate `createBrowserFetcher` in favor of `BrowserFetcher` ([#9079](https://github.com/puppeteer/puppeteer/issues/9079)) ([7294dfe](https://github.com/puppeteer/puppeteer/commit/7294dfe9c6c3b224f95ba6d59b5ef33d379fd09a)), closes [#8999](https://github.com/puppeteer/puppeteer/issues/8999)
|
||||||
|
* use `~/.cache/puppeteer` for browser downloads ([#9095](https://github.com/puppeteer/puppeteer/issues/9095)) ([3df375b](https://github.com/puppeteer/puppeteer/commit/3df375baedad64b8773bb1e1e6f81b604ed18989))
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* deprecate indirect network condition imports ([#9074](https://github.com/puppeteer/puppeteer/issues/9074)) ([41d0122](https://github.com/puppeteer/puppeteer/commit/41d0122b94f41b308536c48ced345dec8c272a49))
|
||||||
|
* refactor custom query handler API ([#9078](https://github.com/puppeteer/puppeteer/issues/9078)) ([1847704](https://github.com/puppeteer/puppeteer/commit/1847704789e2888c755de8c739d567364b8ad645))
|
||||||
|
* remove `puppeteer.devices` in favor of `KnownDevices` ([#9075](https://github.com/puppeteer/puppeteer/issues/9075)) ([87c08fd](https://github.com/puppeteer/puppeteer/commit/87c08fd86a79b63308ad8d46c5f7acd1927505f8))
|
||||||
|
|
||||||
|
|
||||||
|
### Dependencies
|
||||||
|
|
||||||
|
* The following workspace dependencies were updated
|
||||||
|
* dependencies
|
||||||
|
* puppeteer-core bumped from 18.2.1 to ^19.0.0
|
||||||
|
|
||||||
## [18.2.1](https://github.com/puppeteer/puppeteer/compare/v18.2.0...v18.2.1) (2022-10-06)
|
## [18.2.1](https://github.com/puppeteer/puppeteer/compare/v18.2.0...v18.2.1) (2022-10-06)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "puppeteer",
|
"name": "puppeteer",
|
||||||
"version": "18.2.1",
|
"version": "19.0.0",
|
||||||
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
|
"description": "A high-level API to control headless Chrome over the DevTools Protocol",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"puppeteer",
|
"puppeteer",
|
||||||
@ -138,6 +138,6 @@
|
|||||||
"https-proxy-agent": "5.0.1",
|
"https-proxy-agent": "5.0.1",
|
||||||
"progress": "2.0.3",
|
"progress": "2.0.3",
|
||||||
"proxy-from-env": "1.1.0",
|
"proxy-from-env": "1.1.0",
|
||||||
"puppeteer-core": "18.2.1"
|
"puppeteer-core": "19.0.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: clearCustomQueryHandlers
|
|
||||||
---
|
|
||||||
|
|
||||||
# clearCustomQueryHandlers() function
|
|
||||||
|
|
||||||
Clears all registered handlers.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare function clearCustomQueryHandlers(): void;
|
|
||||||
```
|
|
||||||
|
|
||||||
**Returns:**
|
|
||||||
|
|
||||||
void
|
|
@ -1,12 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: connect
|
|
||||||
---
|
|
||||||
|
|
||||||
# connect variable
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
connect: (options: import('./types').ConnectOptions) =>
|
|
||||||
Promise<import('./types').Browser>;
|
|
||||||
```
|
|
@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: CustomError.(constructor)
|
|
||||||
---
|
|
||||||
|
|
||||||
# CustomError.(constructor)
|
|
||||||
|
|
||||||
Constructs a new instance of the `CustomError` class
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class CustomError {
|
|
||||||
constructor(message?: string);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | ------ | ----------------- |
|
|
||||||
| message | string | <i>(Optional)</i> |
|
|
@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: CustomError
|
|
||||||
---
|
|
||||||
|
|
||||||
# CustomError class
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare class CustomError extends Error
|
|
||||||
```
|
|
||||||
|
|
||||||
**Extends:** Error
|
|
||||||
|
|
||||||
## Constructors
|
|
||||||
|
|
||||||
| Constructor | Modifiers | Description |
|
|
||||||
| ------------------------------------------------------------------ | --------- | --------------------------------------------------------------- |
|
|
||||||
| [(constructor)(message)](./puppeteer.customerror._constructor_.md) | | Constructs a new instance of the <code>CustomError</code> class |
|
|
@ -1,19 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Device
|
|
||||||
---
|
|
||||||
|
|
||||||
# Device interface
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export interface Device
|
|
||||||
```
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
|
|
||||||
| Property | Modifiers | Type | Description |
|
|
||||||
| -------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------- | ----------- |
|
|
||||||
| [name](./puppeteer.device.name.md) | | string | |
|
|
||||||
| [userAgent](./puppeteer.device.useragent.md) | | string | |
|
|
||||||
| [viewport](./puppeteer.device.viewport.md) | | { width: number; height: number; deviceScaleFactor: number; isMobile: boolean; hasTouch: boolean; isLandscape: boolean; } | |
|
|
@ -1,13 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Device.name
|
|
||||||
---
|
|
||||||
|
|
||||||
# Device.name property
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
interface Device {
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
```
|
|
@ -1,20 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Device.viewport
|
|
||||||
---
|
|
||||||
|
|
||||||
# Device.viewport property
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
interface Device {
|
|
||||||
viewport: {
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
deviceScaleFactor: number;
|
|
||||||
isMobile: boolean;
|
|
||||||
hasTouch: boolean;
|
|
||||||
isLandscape: boolean;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
```
|
|
@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: devices
|
|
||||||
---
|
|
||||||
|
|
||||||
# devices variable
|
|
||||||
|
|
||||||
A list of devices to be used with `page.emulate(options)`. Actual list of devices can be found in [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts).
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
devices: DevicesMap;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
const iPhone = puppeteer.devices['iPhone 6'];
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.emulate(iPhone);
|
|
||||||
await page.goto('https://www.google.com');
|
|
||||||
// other actions...
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
@ -1,15 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: DevicesMap
|
|
||||||
---
|
|
||||||
|
|
||||||
# DevicesMap type
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare type DevicesMap = {
|
|
||||||
[name: string]: Device;
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
**References:** [Device](./puppeteer.device.md)
|
|
@ -1,29 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: errors
|
|
||||||
---
|
|
||||||
|
|
||||||
# errors variable
|
|
||||||
|
|
||||||
Puppeteer methods might throw errors if they are unable to fulfill a request. For example, `page.waitForSelector(selector[, options])` might fail if the selector doesn't match any nodes during the given timeframe.
|
|
||||||
|
|
||||||
For certain types of errors Puppeteer uses specific error classes. These classes are available via `puppeteer.errors`.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
errors: PuppeteerErrors;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
An example of handling a timeout error:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
try {
|
|
||||||
await page.waitForSelector('.foo');
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof puppeteer.errors.TimeoutError) {
|
|
||||||
// Do something if this is a timeout.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
@ -1,32 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: networkConditions
|
|
||||||
---
|
|
||||||
|
|
||||||
# networkConditions variable
|
|
||||||
|
|
||||||
A list of network conditions to be used with `page.emulateNetworkConditions(networkConditions)`. Actual list of predefined conditions can be found in [src/common/NetworkConditions.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/NetworkConditions.ts).
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
networkConditions: Readonly<{
|
|
||||||
'Slow 3G': NetworkConditions;
|
|
||||||
'Fast 3G': NetworkConditions;
|
|
||||||
}>;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
const slow3G = puppeteer.networkConditions['Slow 3G'];
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.emulateNetworkConditions(slow3G);
|
|
||||||
await page.goto('https://www.google.com');
|
|
||||||
// other actions...
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
@ -1,44 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Page.emulate
|
|
||||||
---
|
|
||||||
|
|
||||||
# Page.emulate() method
|
|
||||||
|
|
||||||
Emulates given device metrics and user agent.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class Page {
|
|
||||||
emulate(options: {viewport: Viewport; userAgent: string}): Promise<void>;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | --------------------------------------------------------------------- | ----------- |
|
|
||||||
| options | { viewport: [Viewport](./puppeteer.viewport.md); userAgent: string; } | |
|
|
||||||
|
|
||||||
**Returns:**
|
|
||||||
|
|
||||||
Promise<void>
|
|
||||||
|
|
||||||
## Remarks
|
|
||||||
|
|
||||||
List of all available devices is available in the source code: [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts).
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
const iPhone = puppeteer.devices['iPhone 6'];
|
|
||||||
(async () => {
|
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.emulate(iPhone);
|
|
||||||
await page.goto('https://www.google.com');
|
|
||||||
// other actions...
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
@ -1,23 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Puppeteer.devices
|
|
||||||
---
|
|
||||||
|
|
||||||
# Puppeteer.devices property
|
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class Puppeteer {
|
|
||||||
get devices(): typeof devices;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {devices} from 'puppeteer';
|
|
||||||
```
|
|
@ -1,23 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Puppeteer.errors
|
|
||||||
---
|
|
||||||
|
|
||||||
# Puppeteer.errors property
|
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class Puppeteer {
|
|
||||||
get errors(): typeof errors;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {errors} from 'puppeteer';
|
|
||||||
```
|
|
@ -1,37 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Puppeteer
|
|
||||||
---
|
|
||||||
|
|
||||||
# Puppeteer class
|
|
||||||
|
|
||||||
The main Puppeteer class.
|
|
||||||
|
|
||||||
IMPORTANT: if you are using Puppeteer in a Node environment, you will get an instance of [PuppeteerNode](./puppeteer.puppeteernode.md) when you import or require `puppeteer`. That class extends `Puppeteer`, so has all the methods documented below as well as all that are defined on [PuppeteerNode](./puppeteer.puppeteernode.md).
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare class Puppeteer
|
|
||||||
```
|
|
||||||
|
|
||||||
## Remarks
|
|
||||||
|
|
||||||
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Puppeteer` class.
|
|
||||||
|
|
||||||
## Properties
|
|
||||||
|
|
||||||
| Property | Modifiers | Type | Description |
|
|
||||||
| --------------------------------------------------------------- | --------------------- | ------------------------------------------------------------ | ----------- |
|
|
||||||
| [devices](./puppeteer.puppeteer.devices.md) | <code>readonly</code> | typeof [devices](./puppeteer.devices.md) | |
|
|
||||||
| [errors](./puppeteer.puppeteer.errors.md) | <code>readonly</code> | typeof [errors](./puppeteer.errors.md) | |
|
|
||||||
| [networkConditions](./puppeteer.puppeteer.networkconditions.md) | <code>readonly</code> | typeof [networkConditions](./puppeteer.networkconditions.md) | |
|
|
||||||
|
|
||||||
## Methods
|
|
||||||
|
|
||||||
| Method | Modifiers | Description |
|
|
||||||
| ----------------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------- |
|
|
||||||
| [clearCustomQueryHandlers()](./puppeteer.puppeteer.clearcustomqueryhandlers.md) | | |
|
|
||||||
| [connect(options)](./puppeteer.puppeteer.connect.md) | | This method attaches Puppeteer to an existing browser instance. |
|
|
||||||
| [customQueryHandlerNames()](./puppeteer.puppeteer.customqueryhandlernames.md) | | |
|
|
||||||
| [registerCustomQueryHandler(name, queryHandler)](./puppeteer.puppeteer.registercustomqueryhandler.md) | | |
|
|
||||||
| [unregisterCustomQueryHandler(name)](./puppeteer.puppeteer.unregistercustomqueryhandler.md) | | |
|
|
@ -1,23 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Puppeteer.networkConditions
|
|
||||||
---
|
|
||||||
|
|
||||||
# Puppeteer.networkConditions property
|
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class Puppeteer {
|
|
||||||
get networkConditions(): typeof networkConditions;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {networkConditions} from 'puppeteer';
|
|
||||||
```
|
|
@ -1,37 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: Puppeteer.registerCustomQueryHandler
|
|
||||||
---
|
|
||||||
|
|
||||||
# Puppeteer.registerCustomQueryHandler() method
|
|
||||||
|
|
||||||
> Warning: This API is now obsolete.
|
|
||||||
>
|
|
||||||
> Import directly puppeteer.
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
class Puppeteer {
|
|
||||||
registerCustomQueryHandler(
|
|
||||||
name: string,
|
|
||||||
queryHandler: CustomQueryHandler
|
|
||||||
): void;
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| ------------ | ------------------------------------------------------- | ----------- |
|
|
||||||
| name | string | |
|
|
||||||
| queryHandler | [CustomQueryHandler](./puppeteer.customqueryhandler.md) | |
|
|
||||||
|
|
||||||
**Returns:**
|
|
||||||
|
|
||||||
void
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```ts
|
|
||||||
import {registerCustomQueryHandler} from 'puppeteer';
|
|
||||||
```
|
|
@ -1,38 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: registerCustomQueryHandler
|
|
||||||
---
|
|
||||||
|
|
||||||
# registerCustomQueryHandler() function
|
|
||||||
|
|
||||||
Registers a [custom query handler](./puppeteer.customqueryhandler.md).
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare function registerCustomQueryHandler(
|
|
||||||
name: string,
|
|
||||||
handler: CustomQueryHandler
|
|
||||||
): void;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | ------------------------------------------------------- | ---------------------------------------------------------------- |
|
|
||||||
| name | string | The name that the custom query handler will be registered under. |
|
|
||||||
| handler | [CustomQueryHandler](./puppeteer.customqueryhandler.md) | |
|
|
||||||
|
|
||||||
**Returns:**
|
|
||||||
|
|
||||||
void
|
|
||||||
|
|
||||||
## Remarks
|
|
||||||
|
|
||||||
After registration, the handler can be used everywhere where a selector is expected by prepending the selection string with `<name>/`. The name is only allowed to consist of lower- and upper case latin letters.
|
|
||||||
|
|
||||||
## Example
|
|
||||||
|
|
||||||
```
|
|
||||||
puppeteer.registerCustomQueryHandler('text', { … });
|
|
||||||
const aHandle = await page.$('text/…');
|
|
||||||
```
|
|
@ -1,21 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_label: unregisterCustomQueryHandler
|
|
||||||
---
|
|
||||||
|
|
||||||
# unregisterCustomQueryHandler() function
|
|
||||||
|
|
||||||
**Signature:**
|
|
||||||
|
|
||||||
```typescript
|
|
||||||
export declare function unregisterCustomQueryHandler(name: string): void;
|
|
||||||
```
|
|
||||||
|
|
||||||
## Parameters
|
|
||||||
|
|
||||||
| Parameter | Type | Description |
|
|
||||||
| --------- | ------ | ---------------------------------------------- |
|
|
||||||
| name | string | The name of the query handler to unregistered. |
|
|
||||||
|
|
||||||
**Returns:**
|
|
||||||
|
|
||||||
void
|
|
@ -1,419 +0,0 @@
|
|||||||
---
|
|
||||||
sidebar_position: 1
|
|
||||||
---
|
|
||||||
|
|
||||||
# Puppeteer
|
|
||||||
|
|
||||||
<!-- [START badges] -->
|
|
||||||
|
|
||||||
[![Build status](https://github.com/puppeteer/puppeteer/workflows/CI/badge.svg)](https://github.com/puppeteer/puppeteer/actions?query=workflow%3ACI) [![npm puppeteer package](https://img.shields.io/npm/v/puppeteer.svg)](https://npmjs.org/package/puppeteer)
|
|
||||||
|
|
||||||
<!-- [END badges] -->
|
|
||||||
|
|
||||||
<img src="https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png" height="200" align="right"/>
|
|
||||||
|
|
||||||
###### [API](https://pptr.dev/api) | [FAQ](https://pptr.dev/faq) | [Contributing](https://pptr.dev/contributing) | [Troubleshooting](https://pptr.dev/troubleshooting)
|
|
||||||
|
|
||||||
> Puppeteer is a Node library which provides a high-level API to control Chrome or Chromium over the [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). Puppeteer runs [headless](https://developers.google.com/web/updates/2017/04/headless-chrome) by default, but can be configured to run full (non-headless) Chrome or Chromium.
|
|
||||||
|
|
||||||
<!-- [START usecases] -->
|
|
||||||
|
|
||||||
##### What can I do?
|
|
||||||
|
|
||||||
Most things that you can do manually in the browser can be done using Puppeteer! Here are a few examples to get you started:
|
|
||||||
|
|
||||||
- Generate screenshots and PDFs of pages.
|
|
||||||
- Crawl a SPA (Single-Page Application) and generate pre-rendered content (i.e. "SSR" (Server-Side Rendering)).
|
|
||||||
- Automate form submission, UI testing, keyboard input, etc.
|
|
||||||
- Create an up-to-date, automated testing environment. Run your tests directly in the latest version of Chrome using the latest JavaScript and browser features.
|
|
||||||
- Capture a [timeline trace](https://developers.google.com/web/tools/chrome-devtools/evaluate-performance/reference) of your site to help diagnose performance issues.
|
|
||||||
- Test Chrome Extensions.
|
|
||||||
<!-- [END usecases] -->
|
|
||||||
|
|
||||||
<!-- [START getstarted] -->
|
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
### Installation
|
|
||||||
|
|
||||||
To use Puppeteer in your project, run:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
npm i puppeteer
|
|
||||||
# or "yarn add puppeteer"
|
|
||||||
```
|
|
||||||
|
|
||||||
When you install Puppeteer, it downloads a recent version of Chromium (~170MB Mac, ~282MB Linux, ~280MB Win) that is guaranteed to work with the API (customizable through [Environment Variables](#environment-variables)). For a version of Puppeteer purely for connection, see [`puppeteer-core`](#puppeteer-core).
|
|
||||||
|
|
||||||
#### Environment Variables
|
|
||||||
|
|
||||||
Puppeteer looks for certain [environment variables](https://en.wikipedia.org/wiki/Environment_variable) to aid its operations.
|
|
||||||
If Puppeteer doesn't find them in the environment during the installation step, a lowercased variant of these variables will be used from the [npm config](https://docs.npmjs.com/cli/config).
|
|
||||||
|
|
||||||
- `HTTP_PROXY`, `HTTPS_PROXY`, `NO_PROXY` - defines HTTP proxy settings that are used to download and run the browser.
|
|
||||||
- `PUPPETEER_SKIP_CHROMIUM_DOWNLOAD` - do not download bundled Chromium during installation step.
|
|
||||||
- `PUPPETEER_TMP_DIR` - defines the directory to be used by Puppeteer for creating temporary files. Defaults to [`os.tmpdir()`](https://nodejs.org/api/os.html#os_os_tmpdir).
|
|
||||||
- `PUPPETEER_DOWNLOAD_HOST` - overwrite URL prefix that is used to download Chromium. Note: this includes protocol and might even include path prefix. Defaults to `https://storage.googleapis.com`.
|
|
||||||
- `PUPPETEER_DOWNLOAD_PATH` - overwrite the path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is Puppeteer's package root.
|
|
||||||
- `PUPPETEER_CHROMIUM_REVISION` - specify a certain version of Chromium you'd like Puppeteer to use. See [`puppeteer.launch`](https://pptr.dev/api/puppeteer.puppeteernode.launch) on how executable path is inferred.
|
|
||||||
- `PUPPETEER_EXECUTABLE_PATH` - specify an executable path to be used in [`puppeteer.launch`](https://pptr.dev/api/puppeteer.puppeteernode.launch).
|
|
||||||
- `PUPPETEER_PRODUCT` - specify which browser you'd like Puppeteer to use. Must be one of `chrome` or `firefox`. This can also be used during installation to fetch the recommended browser binary. Setting `product` programmatically in [`puppeteer.launch`](https://pptr.dev/api/puppeteer.puppeteernode.launch) supersedes this environment variable. The product is exposed in [`puppeteer.product`](https://pptr.dev/api/puppeteer.product)
|
|
||||||
- `PUPPETEER_EXPERIMENTAL_CHROMIUM_MAC_ARM` — specify Puppeteer download Chromium for Apple M1. On Apple M1 devices Puppeteer by default downloads the version for Intel's processor which runs via Rosetta. It works without any problems, however, with this option, you should get more efficient resource usage (CPU and RAM) that could lead to a faster execution time.
|
|
||||||
|
|
||||||
:::danger
|
|
||||||
|
|
||||||
Puppeteer is only [guaranteed to work](https://pptr.dev/faq#q-why-doesnt-puppeteer-vxxx-work-with-chromium-vyyy) with the bundled Chromium, use at your own risk.
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
:::caution
|
|
||||||
|
|
||||||
`PUPPETEER_*` env variables are not accounted for in [`puppeteer-core`](#puppeteer-core).
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
#### puppeteer-core
|
|
||||||
|
|
||||||
Every release since v1.7.0 we publish two packages:
|
|
||||||
|
|
||||||
- [`puppeteer`](https://www.npmjs.com/package/puppeteer)
|
|
||||||
- [`puppeteer-core`](https://www.npmjs.com/package/puppeteer-core)
|
|
||||||
|
|
||||||
`puppeteer` is a _product_ for browser automation. When installed, it downloads a version of
|
|
||||||
Chromium, which it then drives using `puppeteer-core`. Being an end-user product, `puppeteer` supports a bunch of convenient `PUPPETEER_*` env variables to tweak its behavior.
|
|
||||||
|
|
||||||
`puppeteer-core` is a _library_ to help drive anything that supports DevTools protocol. `puppeteer-core` doesn't download Chromium when installed. Being a library, `puppeteer-core` is fully driven
|
|
||||||
through its programmatic interface and disregards all the `PUPPETEER_*` env variables.
|
|
||||||
|
|
||||||
To sum up, the only differences between `puppeteer-core` and `puppeteer` are:
|
|
||||||
|
|
||||||
- `puppeteer-core` doesn't automatically download Chromium when installed.
|
|
||||||
- `puppeteer-core` ignores all `PUPPETEER_*` env variables.
|
|
||||||
|
|
||||||
In most cases, you'll be fine using the `puppeteer` package.
|
|
||||||
|
|
||||||
However, you should use `puppeteer-core` if:
|
|
||||||
|
|
||||||
- you're building another end-user product or library atop of DevTools protocol. For example, one might build a PDF generator using `puppeteer-core` and write a custom `install.js` script that downloads [`headless_shell`](https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md) instead of Chromium to save disk space.
|
|
||||||
- you're bundling Puppeteer to use in Chrome Extension / browser with the DevTools protocol where downloading an additional Chromium binary is unnecessary.
|
|
||||||
- you're building a set of tools where `puppeteer-core` is one of the ingredients and you want to postpone `install.js` script execution until Chromium is about to be used.
|
|
||||||
|
|
||||||
When using `puppeteer-core`, remember to change the _include_ line:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer-core');
|
|
||||||
```
|
|
||||||
|
|
||||||
You will then need to call [`puppeteer.connect`](https://pptr.dev/api/puppeteer.puppeteer.connect) or [`puppeteer.launch`](https://pptr.dev/api/puppeteer.puppeteernode.launch) with an explicit `executablePath` or `channel` option.
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
|
|
||||||
Puppeteer follows the latest [maintenance LTS](https://github.com/nodejs/Release#release-schedule) version of Node.
|
|
||||||
|
|
||||||
Puppeteer will be familiar to people using other browser testing frameworks. You create an instance
|
|
||||||
of `Browser`, open pages, and then manipulate them with [Puppeteer's API](https://pptr.dev/api).
|
|
||||||
|
|
||||||
**Example** - navigating to https://example.com and saving a screenshot as _example.png_:
|
|
||||||
|
|
||||||
Save file as **example.js**
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.goto('https://example.com');
|
|
||||||
await page.screenshot({path: 'example.png'});
|
|
||||||
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
||||||
|
|
||||||
Execute script on the command line
|
|
||||||
|
|
||||||
```bash
|
|
||||||
node example.js
|
|
||||||
```
|
|
||||||
|
|
||||||
Puppeteer sets an initial page size to 800×600px, which defines the screenshot size. The page size can be customized with [`Page.setViewport()`](https://pptr.dev/api/puppeteer.page.setviewport).
|
|
||||||
|
|
||||||
**Example** - create a PDF.
|
|
||||||
|
|
||||||
Save file as **hn.js**
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.goto('https://news.ycombinator.com', {
|
|
||||||
waitUntil: 'networkidle2',
|
|
||||||
});
|
|
||||||
await page.pdf({path: 'hn.pdf', format: 'a4'});
|
|
||||||
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
||||||
|
|
||||||
Execute script on the command line
|
|
||||||
|
|
||||||
```bash
|
|
||||||
node hn.js
|
|
||||||
```
|
|
||||||
|
|
||||||
See [`Page.pdf`](https://pptr.dev/api/puppeteer.page.pdf) for more information about creating pdfs.
|
|
||||||
|
|
||||||
**Example** - evaluate script in the context of the page
|
|
||||||
|
|
||||||
Save file as **get-dimensions.js**
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const browser = await puppeteer.launch();
|
|
||||||
const page = await browser.newPage();
|
|
||||||
await page.goto('https://example.com');
|
|
||||||
|
|
||||||
// Get the "viewport" of the page, as reported by the page.
|
|
||||||
const dimensions = await page.evaluate(() => {
|
|
||||||
return {
|
|
||||||
width: document.documentElement.clientWidth,
|
|
||||||
height: document.documentElement.clientHeight,
|
|
||||||
deviceScaleFactor: window.devicePixelRatio,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
console.log('Dimensions:', dimensions);
|
|
||||||
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
||||||
|
|
||||||
Execute script on the command line
|
|
||||||
|
|
||||||
```bash
|
|
||||||
node get-dimensions.js
|
|
||||||
```
|
|
||||||
|
|
||||||
See [`Page.evaluate`](https://pptr.dev/api/puppeteer.page.evaluate) and related methods like [`Page.evaluateOnNewDocument`](https://pptr.dev/api/puppeteer.page.evaluateOnNewDocument) and [`Page.exposeFunction`](https://pptr.dev/api/puppeteer.page.exposeFunction).
|
|
||||||
|
|
||||||
<!-- [END getstarted] -->
|
|
||||||
|
|
||||||
### Running in Docker
|
|
||||||
|
|
||||||
Puppeteer offers a Docker image that includes Chromium along with the required dependencies and a pre-installed Puppeteer version. The image is available via the [GitHub Container Registry](https://github.com/puppeteer/puppeteer/pkgs/container/puppeteer). The latest image is tagged as `latest` and other tags match Puppeteer versions. For example,
|
|
||||||
|
|
||||||
```sh
|
|
||||||
docker pull ghcr.io/puppeteer/puppeteer:latest # pulls the latest
|
|
||||||
docker pull ghcr.io/puppeteer/puppeteer:16.1.0 # pulls the image that contains Puppeteer v16.1.0
|
|
||||||
```
|
|
||||||
|
|
||||||
The image is meant for running the browser in the sandbox mode and therefore, running the image requires the `SYS_ADMIN` capability. For example,
|
|
||||||
|
|
||||||
```sh
|
|
||||||
docker run -i --init --cap-add=SYS_ADMIN --rm ghcr.io/puppeteer/puppeteer:latest node -e "`cat docker/test/smoke-test.js`"
|
|
||||||
```
|
|
||||||
|
|
||||||
Replace the path to [`smoke-test.js`](https://raw.githubusercontent.com/puppeteer/puppeteer/main/docker/test/smoke-test.js) with a path to your script.
|
|
||||||
The script can import or require the `puppeteer` module because it's pre-installed inside the image.
|
|
||||||
|
|
||||||
Currently, the image includes the LTS version of Node.js. If you need to build an image based on a different base image, you can use our [`Dockerfile`](https://github.com/puppeteer/puppeteer/blob/main/docker/Dockerfile) as the starting point.
|
|
||||||
|
|
||||||
### Working with Chrome Extensions
|
|
||||||
|
|
||||||
Puppeteer can be used for testing Chrome Extensions.
|
|
||||||
|
|
||||||
:::caution
|
|
||||||
|
|
||||||
Extensions in Chrome / Chromium currently only work in non-headless mode and experimental Chrome headless mode.
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
The following is code for getting a handle to the [background page](https://developer.chrome.com/extensions/background_pages) of an extension whose source is located in `./my-extension`:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const puppeteer = require('puppeteer');
|
|
||||||
|
|
||||||
(async () => {
|
|
||||||
const pathToExtension = require('path').join(__dirname, 'my-extension');
|
|
||||||
const browser = await puppeteer.launch({
|
|
||||||
headless: 'chrome',
|
|
||||||
args: [
|
|
||||||
`--disable-extensions-except=${pathToExtension}`,
|
|
||||||
`--load-extension=${pathToExtension}`,
|
|
||||||
],
|
|
||||||
});
|
|
||||||
const backgroundPageTarget = await browser.waitForTarget(
|
|
||||||
target => target.type() === 'background_page'
|
|
||||||
);
|
|
||||||
const backgroundPage = await backgroundPageTarget.page();
|
|
||||||
// Test the background page as you would any other page.
|
|
||||||
await browser.close();
|
|
||||||
})();
|
|
||||||
```
|
|
||||||
|
|
||||||
:::note
|
|
||||||
|
|
||||||
Chrome Manifest V3 extensions have a background ServiceWorker of type 'service_worker', instead of a page of type 'background_page'.
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
:::note
|
|
||||||
|
|
||||||
It is not yet possible to test extension popups or content scripts.
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
<!-- [START runtimesettings] -->
|
|
||||||
|
|
||||||
## Default runtime settings
|
|
||||||
|
|
||||||
**1. Uses Headless mode**
|
|
||||||
|
|
||||||
Puppeteer launches Chromium in [headless mode](https://developers.google.com/web/updates/2017/04/headless-chrome). To launch a full version of Chromium, set the [`headless` option](https://pptr.dev/api/puppeteer.browserlaunchargumentoptions.headless) when launching a browser:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const browser = await puppeteer.launch({headless: false}); // default is true
|
|
||||||
```
|
|
||||||
|
|
||||||
**2. Runs a bundled version of Chromium**
|
|
||||||
|
|
||||||
By default, Puppeteer downloads and uses a specific version of Chromium so its API
|
|
||||||
is guaranteed to work out of the box. To use Puppeteer with a different version of Chrome or Chromium,
|
|
||||||
pass in the executable's path when creating a `Browser` instance:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const browser = await puppeteer.launch({executablePath: '/path/to/Chrome'});
|
|
||||||
```
|
|
||||||
|
|
||||||
You can also use Puppeteer with Firefox Nightly (experimental support). See [`Puppeteer.launch`](https://pptr.dev/api/puppeteer.puppeteernode.launch) for more information.
|
|
||||||
|
|
||||||
See [`this article`](https://www.howtogeek.com/202825/what%E2%80%99s-the-difference-between-chromium-and-chrome/) for a description of the differences between Chromium and Chrome. [`This article`](https://chromium.googlesource.com/chromium/src/+/refs/heads/main/docs/chromium_browser_vs_google_chrome.md) describes some differences for Linux users.
|
|
||||||
|
|
||||||
**3. Creates a fresh user profile**
|
|
||||||
|
|
||||||
Puppeteer creates its own browser user profile which it **cleans up on every run**.
|
|
||||||
|
|
||||||
<!-- [END runtimesettings] -->
|
|
||||||
|
|
||||||
## Resources
|
|
||||||
|
|
||||||
- [API Documentation](https://pptr.dev/api)
|
|
||||||
- [Examples](https://github.com/puppeteer/puppeteer/tree/main/examples)
|
|
||||||
- [Community list of Puppeteer resources](https://github.com/transitive-bullshit/awesome-puppeteer)
|
|
||||||
|
|
||||||
<!-- [START debugging] -->
|
|
||||||
|
|
||||||
## Debugging tips
|
|
||||||
|
|
||||||
1. Turn off headless mode - sometimes it's useful to see what the browser is
|
|
||||||
displaying. Instead of launching in headless mode, launch a full version of
|
|
||||||
the browser using `headless: false`:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const browser = await puppeteer.launch({headless: false});
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Slow it down - the `slowMo` option slows down Puppeteer operations by the
|
|
||||||
specified amount of milliseconds. It's another way to help see what's going on.
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const browser = await puppeteer.launch({
|
|
||||||
headless: false,
|
|
||||||
slowMo: 250, // slow down by 250ms
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Capture console output - You can listen for the `console` event.
|
|
||||||
This is also handy when debugging code in `page.evaluate()`:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
page.on('console', msg => console.log('PAGE LOG:', msg.text()));
|
|
||||||
|
|
||||||
await page.evaluate(() => console.log(`url is ${location.href}`));
|
|
||||||
```
|
|
||||||
|
|
||||||
4. Use debugger in application code browser
|
|
||||||
|
|
||||||
There are two execution context: node.js that is running test code, and the browser
|
|
||||||
running application code being tested. This lets you debug code in the
|
|
||||||
application code browser; ie code inside `evaluate()`.
|
|
||||||
|
|
||||||
- Use `{devtools: true}` when launching Puppeteer:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
const browser = await puppeteer.launch({devtools: true});
|
|
||||||
```
|
|
||||||
|
|
||||||
- Change default test timeout:
|
|
||||||
|
|
||||||
jest: `jest.setTimeout(100000);`
|
|
||||||
|
|
||||||
jasmine: `jasmine.DEFAULT_TIMEOUT_INTERVAL = 100000;`
|
|
||||||
|
|
||||||
mocha: `this.timeout(100000);` (don't forget to change test to use [function and not '=>'](https://stackoverflow.com/a/23492442))
|
|
||||||
|
|
||||||
- Add an evaluate statement with `debugger` inside / add `debugger` to an existing evaluate statement:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
await page.evaluate(() => {
|
|
||||||
debugger;
|
|
||||||
});
|
|
||||||
```
|
|
||||||
|
|
||||||
The test will now stop executing in the above evaluate statement, and chromium will stop in debug mode.
|
|
||||||
|
|
||||||
5. Use debugger in node.js
|
|
||||||
|
|
||||||
This will let you debug test code. For example, you can step over `await page.click()` in the node.js script and see the click happen in the application code browser.
|
|
||||||
|
|
||||||
Note that you won't be able to run `await page.click()` in
|
|
||||||
DevTools console due to this [Chromium bug](https://bugs.chromium.org/p/chromium/issues/detail?id=833928). So if
|
|
||||||
you want to try something out, you have to add it to your test file.
|
|
||||||
|
|
||||||
- Add `debugger;` to your test, eg:
|
|
||||||
|
|
||||||
```ts
|
|
||||||
debugger;
|
|
||||||
await page.click('a[target=_blank]');
|
|
||||||
```
|
|
||||||
|
|
||||||
- Set `headless` to `false`
|
|
||||||
- Run `node --inspect-brk`, eg `node --inspect-brk node_modules/.bin/jest tests`
|
|
||||||
- In Chrome open `chrome://inspect/#devices` and click `inspect`
|
|
||||||
- In the newly opened test browser, type `F8` to resume test execution
|
|
||||||
- Now your `debugger` will be hit and you can debug in the test browser
|
|
||||||
|
|
||||||
6. Enable verbose logging - internal DevTools protocol traffic
|
|
||||||
will be logged via the [`debug`](https://github.com/visionmedia/debug) module under the `puppeteer` namespace.
|
|
||||||
|
|
||||||
# Basic verbose logging
|
|
||||||
env DEBUG="puppeteer:*" node script.js
|
|
||||||
|
|
||||||
# Protocol traffic can be rather noisy. This example filters out all Network domain messages
|
|
||||||
env DEBUG="puppeteer:*" env DEBUG_COLORS=true node script.js 2>&1 | grep -v '"Network'
|
|
||||||
|
|
||||||
7. Debug your Puppeteer (node) code easily, using [ndb](https://github.com/GoogleChromeLabs/ndb)
|
|
||||||
|
|
||||||
- `npm install -g ndb` (or even better, use [npx](https://github.com/zkat/npx)!)
|
|
||||||
|
|
||||||
- add a `debugger` to your Puppeteer (node) code
|
|
||||||
|
|
||||||
- add `ndb` (or `npx ndb`) before your test command. For example:
|
|
||||||
|
|
||||||
`ndb jest` or `ndb mocha` (or `npx ndb jest` / `npx ndb mocha`)
|
|
||||||
|
|
||||||
- debug your test inside chromium like a boss!
|
|
||||||
|
|
||||||
<!-- [END debugging] -->
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
Check out our [contributing guide](https://pptr.dev/contributing) to get an overview of Puppeteer development.
|
|
||||||
|
|
||||||
## FAQ
|
|
||||||
|
|
||||||
Our [FAQ](https://pptr.dev/faq) has migrated to [our site](https://pptr.dev/faq).
|
|
@ -51,12 +51,12 @@ sidebar_label: API
|
|||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
| Function | Description |
|
| Function | Description |
|
||||||
| -------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
|
| -------------------------------------------------------------------------------------- | ----------- |
|
||||||
| [clearCustomQueryHandlers()](./puppeteer.clearcustomqueryhandlers.md) | Clears all registered handlers. |
|
| [clearCustomQueryHandlers()](./puppeteer.clearcustomqueryhandlers.md) | |
|
||||||
| [customQueryHandlerNames()](./puppeteer.customqueryhandlernames.md) | |
|
| [customQueryHandlerNames()](./puppeteer.customqueryhandlernames.md) | |
|
||||||
| [registerCustomQueryHandler(name, handler)](./puppeteer.registercustomqueryhandler.md) | Registers a [custom query handler](./puppeteer.customqueryhandler.md). |
|
| [registerCustomQueryHandler(name, handler)](./puppeteer.registercustomqueryhandler.md) | |
|
||||||
| [unregisterCustomQueryHandler(name)](./puppeteer.unregistercustomqueryhandler.md) | |
|
| [unregisterCustomQueryHandler(name)](./puppeteer.unregistercustomqueryhandler.md) | |
|
||||||
|
|
||||||
## Interfaces
|
## Interfaces
|
||||||
|
|
||||||
@ -120,18 +120,20 @@ sidebar_label: API
|
|||||||
|
|
||||||
## Variables
|
## Variables
|
||||||
|
|
||||||
| Variable | Description |
|
| Variable | Description |
|
||||||
| --------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| --------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| [connect](./puppeteer.connect.md) | |
|
| [connect](./puppeteer.connect.md) | |
|
||||||
| [createBrowserFetcher](./puppeteer.createbrowserfetcher.md) | |
|
| [createBrowserFetcher](./puppeteer.createbrowserfetcher.md) | |
|
||||||
| [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority |
|
| [DEFAULT_INTERCEPT_RESOLUTION_PRIORITY](./puppeteer.default_intercept_resolution_priority.md) | The default cooperative request interception resolution priority |
|
||||||
| [defaultArgs](./puppeteer.defaultargs.md) | |
|
| [defaultArgs](./puppeteer.defaultargs.md) | |
|
||||||
| [devices](./puppeteer.devices.md) | A list of devices to be used with <code>page.emulate(options)</code>. Actual list of devices can be found in [src/common/DeviceDescriptors.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/DeviceDescriptors.ts). |
|
| [devices](./puppeteer.devices.md) | |
|
||||||
| [errors](./puppeteer.errors.md) | <p>Puppeteer methods might throw errors if they are unable to fulfill a request. For example, <code>page.waitForSelector(selector[, options])</code> might fail if the selector doesn't match any nodes during the given timeframe.</p><p>For certain types of errors Puppeteer uses specific error classes. These classes are available via <code>puppeteer.errors</code>.</p> |
|
| [errors](./puppeteer.errors.md) | |
|
||||||
| [EVALUATION_SCRIPT_URL](./puppeteer.evaluation_script_url.md) | |
|
| [EVALUATION_SCRIPT_URL](./puppeteer.evaluation_script_url.md) | |
|
||||||
| [executablePath](./puppeteer.executablepath.md) | |
|
| [executablePath](./puppeteer.executablepath.md) | |
|
||||||
| [launch](./puppeteer.launch.md) | |
|
| [KnownDevices](./puppeteer.knowndevices.md) | A list of devices to be used with [Page.emulate()](./puppeteer.page.emulate.md). |
|
||||||
| [networkConditions](./puppeteer.networkconditions.md) | A list of network conditions to be used with <code>page.emulateNetworkConditions(networkConditions)</code>. Actual list of predefined conditions can be found in [src/common/NetworkConditions.ts](https://github.com/puppeteer/puppeteer/blob/main/src/common/NetworkConditions.ts). |
|
| [launch](./puppeteer.launch.md) | |
|
||||||
|
| [networkConditions](./puppeteer.networkconditions.md) | |
|
||||||
|
| [PredefinedNetworkConditions](./puppeteer.predefinednetworkconditions.md) | A list of network conditions to be used with [Page.emulateNetworkConditions()](./puppeteer.page.emulatenetworkconditions.md). |
|
||||||
|
|
||||||
## Type Aliases
|
## Type Aliases
|
||||||
|
|
||||||
@ -141,7 +143,6 @@ sidebar_label: API
|
|||||||
| [Awaitable](./puppeteer.awaitable.md) | |
|
| [Awaitable](./puppeteer.awaitable.md) | |
|
||||||
| [ChromeReleaseChannel](./puppeteer.chromereleasechannel.md) | |
|
| [ChromeReleaseChannel](./puppeteer.chromereleasechannel.md) | |
|
||||||
| [ConsoleMessageType](./puppeteer.consolemessagetype.md) | The supported types for console messages. |
|
| [ConsoleMessageType](./puppeteer.consolemessagetype.md) | The supported types for console messages. |
|
||||||
| [DevicesMap](./puppeteer.devicesmap.md) | |
|
|
||||||
| [ErrorCode](./puppeteer.errorcode.md) | |
|
| [ErrorCode](./puppeteer.errorcode.md) | |
|
||||||
| [EvaluateFunc](./puppeteer.evaluatefunc.md) | |
|
| [EvaluateFunc](./puppeteer.evaluatefunc.md) | |
|
||||||
| [EventType](./puppeteer.eventtype.md) | |
|
| [EventType](./puppeteer.eventtype.md) | |
|
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
sidebar_label: BrowserFetcher.(constructor)
|
||||||
|
---
|
||||||
|
|
||||||
|
# BrowserFetcher.(constructor)
|
||||||
|
|
||||||
|
Constructs a browser fetcher for the given options.
|
||||||
|
|
||||||
|
**Signature:**
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
class BrowserFetcher {
|
||||||
|
constructor(options?: BrowserFetcherOptions);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
| Parameter | Type | Description |
|
||||||
|
| --------- | ------------------------------------------------------------- | ----------------- |
|
||||||
|
| options | [BrowserFetcherOptions](./puppeteer.browserfetcheroptions.md) | <i>(Optional)</i> |
|
@ -14,23 +14,25 @@ export declare class BrowserFetcher
|
|||||||
|
|
||||||
## Remarks
|
## Remarks
|
||||||
|
|
||||||
BrowserFetcher operates on revision strings that specify a precise version of Chromium, e.g. `"533271"`. Revision strings can be obtained from [omahaproxy.appspot.com](http://omahaproxy.appspot.com/). In the Firefox case, BrowserFetcher downloads Firefox Nightly and operates on version numbers such as `"75"`.
|
BrowserFetcher is not designed to work concurrently with other instances of BrowserFetcher that share the same downloads directory.
|
||||||
|
|
||||||
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `BrowserFetcher` class.
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
|
|
||||||
An example of using BrowserFetcher to download a specific version of Chromium and running Puppeteer against it:
|
An example of using BrowserFetcher to download a specific version of Chromium and running Puppeteer against it:
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
const browserFetcher = puppeteer.createBrowserFetcher();
|
const browserFetcher = new BrowserFetcher();
|
||||||
const revisionInfo = await browserFetcher.download('533271');
|
const revisionInfo = await browserFetcher.download('533271');
|
||||||
const browser = await puppeteer.launch({
|
const browser = await puppeteer.launch({
|
||||||
executablePath: revisionInfo.executablePath,
|
executablePath: revisionInfo.executablePath,
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
**NOTE** BrowserFetcher is not designed to work concurrently with other instances of BrowserFetcher that share the same downloads directory.
|
## Constructors
|
||||||
|
|
||||||
|
| Constructor | Modifiers | Description |
|
||||||
|
| --------------------------------------------------------------------- | --------- | --------------------------------------------------- |
|
||||||
|
| [(constructor)(options)](./puppeteer.browserfetcher._constructor_.md) | | Constructs a browser fetcher for the given options. |
|
||||||
|
|
||||||
## Methods
|
## Methods
|
||||||
|
|
@ -4,6 +4,8 @@ sidebar_label: BrowserFetcherOptions.host
|
|||||||
|
|
||||||
# BrowserFetcherOptions.host property
|
# BrowserFetcherOptions.host property
|
||||||
|
|
||||||
|
Determines the host that will be used for downloading.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
@ -12,9 +12,9 @@ export interface BrowserFetcherOptions
|
|||||||
|
|
||||||
## Properties
|
## Properties
|
||||||
|
|
||||||
| Property | Modifiers | Type | Description |
|
| Property | Modifiers | Type | Description |
|
||||||
| ---------------------------------------------------------- | --------- | ----------------------------------- | ----------------- |
|
| ---------------------------------------------------------- | --------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------ |
|
||||||
| [host?](./puppeteer.browserfetcheroptions.host.md) | | string | <i>(Optional)</i> |
|
| [host?](./puppeteer.browserfetcheroptions.host.md) | | string | <i>(Optional)</i> Determines the host that will be used for downloading. |
|
||||||
| [path?](./puppeteer.browserfetcheroptions.path.md) | | string | <i>(Optional)</i> |
|
| [path?](./puppeteer.browserfetcheroptions.path.md) | | string | <i>(Optional)</i> Determines the path to download browsers to. |
|
||||||
| [platform?](./puppeteer.browserfetcheroptions.platform.md) | | [Platform](./puppeteer.platform.md) | <i>(Optional)</i> |
|
| [platform?](./puppeteer.browserfetcheroptions.platform.md) | | [Platform](./puppeteer.platform.md) | <i>(Optional)</i> Determines which platform the browser will be suited for. |
|
||||||
| [product?](./puppeteer.browserfetcheroptions.product.md) | | string | <i>(Optional)</i> |
|
| [product?](./puppeteer.browserfetcheroptions.product.md) | | 'chrome' \| 'firefox' | <i>(Optional)</i> Determines which product the [BrowserFetcher](./puppeteer.browserfetcher.md) is for. |
|
@ -4,6 +4,8 @@ sidebar_label: BrowserFetcherOptions.path
|
|||||||
|
|
||||||
# BrowserFetcherOptions.path property
|
# BrowserFetcherOptions.path property
|
||||||
|
|
||||||
|
Determines the path to download browsers to.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
@ -4,6 +4,8 @@ sidebar_label: BrowserFetcherOptions.platform
|
|||||||
|
|
||||||
# BrowserFetcherOptions.platform property
|
# BrowserFetcherOptions.platform property
|
||||||
|
|
||||||
|
Determines which platform the browser will be suited for.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
@ -4,10 +4,12 @@ sidebar_label: BrowserFetcherOptions.product
|
|||||||
|
|
||||||
# BrowserFetcherOptions.product property
|
# BrowserFetcherOptions.product property
|
||||||
|
|
||||||
|
Determines which product the [BrowserFetcher](./puppeteer.browserfetcher.md) is for.
|
||||||
|
|
||||||
**Signature:**
|
**Signature:**
|
||||||
|
|
||||||
```typescript
|
```typescript
|
||||||
interface BrowserFetcherOptions {
|
interface BrowserFetcherOptions {
|
||||||
product?: string;
|
product?: 'chrome' | 'firefox';
|
||||||
}
|
}
|
||||||
```
|
```
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user