docs(new): migrate Browser docs to TSDoc (#6070)
This commit is contained in:
parent
28797dee41
commit
ccae54644c
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_closeCallback](./puppeteer.browser._closecallback.md)
|
||||
|
||||
## Browser.\_closeCallback property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_closeCallback: BrowserCloseCallback;
|
||||
```
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_connection](./puppeteer.browser._connection.md)
|
||||
|
||||
## Browser.\_connection property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_connection: Connection;
|
||||
```
|
@ -1,25 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [(constructor)](./puppeteer.browser._constructor_.md)
|
||||
|
||||
## Browser.(constructor)
|
||||
|
||||
Constructs a new instance of the `Browser` class
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
constructor(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport, process?: ChildProcess, closeCallback?: BrowserCloseCallback);
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| connection | [Connection](./puppeteer.connection.md) | |
|
||||
| contextIds | string\[\] | |
|
||||
| ignoreHTTPSErrors | boolean | |
|
||||
| defaultViewport | Viewport | |
|
||||
| process | ChildProcess | |
|
||||
| closeCallback | BrowserCloseCallback | |
|
||||
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_contexts](./puppeteer.browser._contexts.md)
|
||||
|
||||
## Browser.\_contexts property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_contexts: Map<string, BrowserContext>;
|
||||
```
|
@ -1,22 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_createPageInContext](./puppeteer.browser._createpageincontext.md)
|
||||
|
||||
## Browser.\_createPageInContext() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_createPageInContext(contextId?: string): Promise<Page>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| contextId | string | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<[Page](./puppeteer.page.md)<!-- -->>
|
||||
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_defaultContext](./puppeteer.browser._defaultcontext.md)
|
||||
|
||||
## Browser.\_defaultContext property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_defaultContext: BrowserContext;
|
||||
```
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_defaultViewport](./puppeteer.browser._defaultviewport.md)
|
||||
|
||||
## Browser.\_defaultViewport property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_defaultViewport?: Viewport;
|
||||
```
|
@ -1,22 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_disposeContext](./puppeteer.browser._disposecontext.md)
|
||||
|
||||
## Browser.\_disposeContext() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_disposeContext(contextId?: string): Promise<void>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| contextId | string | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<void>
|
||||
|
@ -1,15 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_getVersion](./puppeteer.browser._getversion.md)
|
||||
|
||||
## Browser.\_getVersion() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_getVersion(): Promise<Protocol.Browser.getVersionReturnValue>;
|
||||
```
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<Protocol.Browser.getVersionReturnValue>
|
||||
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_ignoreHTTPSErrors](./puppeteer.browser._ignorehttpserrors.md)
|
||||
|
||||
## Browser.\_ignoreHTTPSErrors property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_ignoreHTTPSErrors: boolean;
|
||||
```
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_process](./puppeteer.browser._process.md)
|
||||
|
||||
## Browser.\_process property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_process?: ChildProcess;
|
||||
```
|
@ -1,22 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_targetCreated](./puppeteer.browser._targetcreated.md)
|
||||
|
||||
## Browser.\_targetCreated() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_targetCreated(event: Protocol.Target.targetCreatedPayload): Promise<void>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| event | Protocol.Target.targetCreatedPayload | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<void>
|
||||
|
@ -1,24 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_targetDestroyed](./puppeteer.browser._targetdestroyed.md)
|
||||
|
||||
## Browser.\_targetDestroyed() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_targetDestroyed(event: {
|
||||
targetId: string;
|
||||
}): Promise<void>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| event | { targetId: string; } | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<void>
|
||||
|
@ -1,22 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_targetInfoChanged](./puppeteer.browser._targetinfochanged.md)
|
||||
|
||||
## Browser.\_targetInfoChanged() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_targetInfoChanged(event: Protocol.Target.targetInfoChangedPayload): void;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| event | Protocol.Target.targetInfoChangedPayload | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
void
|
||||
|
@ -1,11 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [\_targets](./puppeteer.browser._targets.md)
|
||||
|
||||
## Browser.\_targets property
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
_targets: Map<string, Target>;
|
||||
```
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.browserContexts() method
|
||||
|
||||
Returns an array of all open browser contexts. In a newly created browser, this will return a single instance of [BrowserContext](./puppeteer.browsercontext.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.close() method
|
||||
|
||||
Closes Chromium and all of its pages (if any were opened). The [Browser](./puppeteer.browser.md) object itself is considered to be disposed and cannot be used anymore.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -1,27 +0,0 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [Browser](./puppeteer.browser.md) > [create](./puppeteer.browser.create.md)
|
||||
|
||||
## Browser.create() method
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
static create(connection: Connection, contextIds: string[], ignoreHTTPSErrors: boolean, defaultViewport?: Viewport, process?: ChildProcess, closeCallback?: BrowserCloseCallback): Promise<Browser>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| connection | [Connection](./puppeteer.connection.md) | |
|
||||
| contextIds | string\[\] | |
|
||||
| ignoreHTTPSErrors | boolean | |
|
||||
| defaultViewport | Viewport | |
|
||||
| process | ChildProcess | |
|
||||
| closeCallback | BrowserCloseCallback | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<[Browser](./puppeteer.browser.md)<!-- -->>
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.createIncognitoBrowserContext() method
|
||||
|
||||
Creates a new incognito browser context. This won't share cookies/cache with other browser contexts.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
@ -13,3 +15,19 @@ createIncognitoBrowserContext(): Promise<BrowserContext>;
|
||||
|
||||
Promise<[BrowserContext](./puppeteer.browsercontext.md)<!-- -->>
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
```js
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch();
|
||||
// Create a new incognito browser context.
|
||||
const context = await browser.createIncognitoBrowserContext();
|
||||
// Create a new page in a pristine context.
|
||||
const page = await context.newPage();
|
||||
// Do stuff
|
||||
await page.goto('https://example.com');
|
||||
})();
|
||||
|
||||
```
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.defaultBrowserContext() method
|
||||
|
||||
Returns the default browser context. The default browser context cannot be closed.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.disconnect() method
|
||||
|
||||
Disconnects Puppeteer from the browser, but leaves the Chromium process running. After calling `disconnect`<!-- -->, the [Browser](./puppeteer.browser.md) object is considered disposed and cannot be used anymore.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.isConnected() method
|
||||
|
||||
Indicates that the browser is connected.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser class
|
||||
|
||||
A Browser is created when Puppeteer connects to a Chromium instance, either through [Puppeteer.launch()](./puppeteer.puppeteer.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
@ -11,49 +13,65 @@ export declare class Browser extends EventEmitter
|
||||
```
|
||||
<b>Extends:</b> [EventEmitter](./puppeteer.eventemitter.md)
|
||||
|
||||
## Constructors
|
||||
## Remarks
|
||||
|
||||
| Constructor | Modifiers | Description |
|
||||
| --- | --- | --- |
|
||||
| [(constructor)(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback)](./puppeteer.browser._constructor_.md) | | Constructs a new instance of the <code>Browser</code> class |
|
||||
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `Browser` class.
|
||||
|
||||
## Properties
|
||||
## Example 1
|
||||
|
||||
| Property | Modifiers | Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| [\_closeCallback](./puppeteer.browser._closecallback.md) | | BrowserCloseCallback | |
|
||||
| [\_connection](./puppeteer.browser._connection.md) | | [Connection](./puppeteer.connection.md) | |
|
||||
| [\_contexts](./puppeteer.browser._contexts.md) | | Map<string, [BrowserContext](./puppeteer.browsercontext.md)<!-- -->> | |
|
||||
| [\_defaultContext](./puppeteer.browser._defaultcontext.md) | | [BrowserContext](./puppeteer.browsercontext.md) | |
|
||||
| [\_defaultViewport](./puppeteer.browser._defaultviewport.md) | | Viewport | |
|
||||
| [\_ignoreHTTPSErrors](./puppeteer.browser._ignorehttpserrors.md) | | boolean | |
|
||||
| [\_process](./puppeteer.browser._process.md) | | ChildProcess | |
|
||||
| [\_targets](./puppeteer.browser._targets.md) | | Map<string, [Target](./puppeteer.target.md)<!-- -->> | |
|
||||
An example of using a [Browser](./puppeteer.browser.md) to create a [Page](./puppeteer.page.md)<!-- -->:
|
||||
|
||||
```js
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch();
|
||||
const page = await browser.newPage();
|
||||
await page.goto('https://example.com');
|
||||
await browser.close();
|
||||
})();
|
||||
|
||||
```
|
||||
|
||||
## Example 2
|
||||
|
||||
An example of disconnecting from and reconnecting to a [Browser](./puppeteer.browser.md)<!-- -->:
|
||||
|
||||
```js
|
||||
const puppeteer = require('puppeteer');
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch();
|
||||
// Store the endpoint to be able to reconnect to Chromium
|
||||
const browserWSEndpoint = browser.wsEndpoint();
|
||||
// Disconnect puppeteer from Chromium
|
||||
browser.disconnect();
|
||||
|
||||
// Use the endpoint to reestablish a connection
|
||||
const browser2 = await puppeteer.connect({browserWSEndpoint});
|
||||
// Close Chromium
|
||||
await browser2.close();
|
||||
})();
|
||||
|
||||
```
|
||||
|
||||
## Methods
|
||||
|
||||
| Method | Modifiers | Description |
|
||||
| --- | --- | --- |
|
||||
| [\_createPageInContext(contextId)](./puppeteer.browser._createpageincontext.md) | | |
|
||||
| [\_disposeContext(contextId)](./puppeteer.browser._disposecontext.md) | | |
|
||||
| [\_getVersion()](./puppeteer.browser._getversion.md) | | |
|
||||
| [\_targetCreated(event)](./puppeteer.browser._targetcreated.md) | | |
|
||||
| [\_targetDestroyed(event)](./puppeteer.browser._targetdestroyed.md) | | |
|
||||
| [\_targetInfoChanged(event)](./puppeteer.browser._targetinfochanged.md) | | |
|
||||
| [browserContexts()](./puppeteer.browser.browsercontexts.md) | | |
|
||||
| [close()](./puppeteer.browser.close.md) | | |
|
||||
| [create(connection, contextIds, ignoreHTTPSErrors, defaultViewport, process, closeCallback)](./puppeteer.browser.create.md) | <code>static</code> | |
|
||||
| [createIncognitoBrowserContext()](./puppeteer.browser.createincognitobrowsercontext.md) | | |
|
||||
| [defaultBrowserContext()](./puppeteer.browser.defaultbrowsercontext.md) | | |
|
||||
| [disconnect()](./puppeteer.browser.disconnect.md) | | |
|
||||
| [isConnected()](./puppeteer.browser.isconnected.md) | | |
|
||||
| [newPage()](./puppeteer.browser.newpage.md) | | |
|
||||
| [pages()](./puppeteer.browser.pages.md) | | |
|
||||
| [process()](./puppeteer.browser.process.md) | | |
|
||||
| [target()](./puppeteer.browser.target.md) | | |
|
||||
| [targets()](./puppeteer.browser.targets.md) | | |
|
||||
| [userAgent()](./puppeteer.browser.useragent.md) | | |
|
||||
| [version()](./puppeteer.browser.version.md) | | |
|
||||
| [waitForTarget(predicate, options)](./puppeteer.browser.waitfortarget.md) | | |
|
||||
| [wsEndpoint()](./puppeteer.browser.wsendpoint.md) | | |
|
||||
| [browserContexts()](./puppeteer.browser.browsercontexts.md) | | Returns an array of all open browser contexts. In a newly created browser, this will return a single instance of [BrowserContext](./puppeteer.browsercontext.md)<!-- -->. |
|
||||
| [close()](./puppeteer.browser.close.md) | | Closes Chromium and all of its pages (if any were opened). The [Browser](./puppeteer.browser.md) object itself is considered to be disposed and cannot be used anymore. |
|
||||
| [createIncognitoBrowserContext()](./puppeteer.browser.createincognitobrowsercontext.md) | | Creates a new incognito browser context. This won't share cookies/cache with other browser contexts. |
|
||||
| [defaultBrowserContext()](./puppeteer.browser.defaultbrowsercontext.md) | | Returns the default browser context. The default browser context cannot be closed. |
|
||||
| [disconnect()](./puppeteer.browser.disconnect.md) | | Disconnects Puppeteer from the browser, but leaves the Chromium process running. After calling <code>disconnect</code>, the [Browser](./puppeteer.browser.md) object is considered disposed and cannot be used anymore. |
|
||||
| [isConnected()](./puppeteer.browser.isconnected.md) | | Indicates that the browser is connected. |
|
||||
| [newPage()](./puppeteer.browser.newpage.md) | | Creates a [Page](./puppeteer.page.md) in the default browser context. |
|
||||
| [pages()](./puppeteer.browser.pages.md) | | An array of all open pages inside the Browser. |
|
||||
| [process()](./puppeteer.browser.process.md) | | The spawned browser process. Returns <code>null</code> if the browser instance was created with [Puppeteer.connect()](./puppeteer.puppeteer.connect.md)<!-- -->. |
|
||||
| [target()](./puppeteer.browser.target.md) | | The target associated with the browser. |
|
||||
| [targets()](./puppeteer.browser.targets.md) | | All active targets inside the Browser. In case of multiple browser contexts, returns an array with all the targets in all browser contexts. |
|
||||
| [userAgent()](./puppeteer.browser.useragent.md) | | The browser's original user agent. Pages can override the browser user agent with [Page.setUserAgent()](./puppeteer.page.setuseragent.md)<!-- -->. |
|
||||
| [version()](./puppeteer.browser.version.md) | | A string representing the browser name and version. |
|
||||
| [waitForTarget(predicate, options)](./puppeteer.browser.waitfortarget.md) | | Searches for a target in all browser contexts. |
|
||||
| [wsEndpoint()](./puppeteer.browser.wsendpoint.md) | | The browser websocket endpoint which can be used as an argument to [Puppeteer.connect()](./puppeteer.puppeteer.connect.md)<!-- -->. |
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.newPage() method
|
||||
|
||||
Creates a [Page](./puppeteer.page.md) in the default browser context.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.pages() method
|
||||
|
||||
An array of all open pages inside the Browser.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
@ -13,3 +15,7 @@ pages(): Promise<Page[]>;
|
||||
|
||||
Promise<[Page](./puppeteer.page.md)<!-- -->\[\]>
|
||||
|
||||
## Remarks
|
||||
|
||||
In case of multiple browser contexts, returns an array with all the pages in all browser contexts. Non-visible pages, such as `"background_page"`<!-- -->, will not be listed here. You can find them using [Target.page()](./puppeteer.target.page.md)<!-- -->.
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.process() method
|
||||
|
||||
The spawned browser process. Returns `null` if the browser instance was created with [Puppeteer.connect()](./puppeteer.puppeteer.connect.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.target() method
|
||||
|
||||
The target associated with the browser.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.targets() method
|
||||
|
||||
All active targets inside the Browser. In case of multiple browser contexts, returns an array with all the targets in all browser contexts.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.userAgent() method
|
||||
|
||||
The browser's original user agent. Pages can override the browser user agent with [Page.setUserAgent()](./puppeteer.page.setuseragent.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.version() method
|
||||
|
||||
A string representing the browser name and version.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
@ -13,3 +15,9 @@ version(): Promise<string>;
|
||||
|
||||
Promise<string>
|
||||
|
||||
## Remarks
|
||||
|
||||
For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`<!-- -->. For non-headless, this is similar to `Chrome/61.0.3153.0`<!-- -->.
|
||||
|
||||
The format of browser.version() might change with future releases of Chromium.
|
||||
|
||||
|
@ -4,24 +4,34 @@
|
||||
|
||||
## Browser.waitForTarget() method
|
||||
|
||||
Searches for a target in all browser contexts.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
waitForTarget(predicate: (x: Target) => boolean, options?: {
|
||||
timeout?: number;
|
||||
}): Promise<Target>;
|
||||
waitForTarget(predicate: (x: Target) => boolean, options?: WaitForTargetOptions): Promise<Target>;
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
| Parameter | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| predicate | (x: [Target](./puppeteer.target.md)<!-- -->) => boolean | |
|
||||
| options | { timeout?: number; } | |
|
||||
| predicate | (x: [Target](./puppeteer.target.md)<!-- -->) => boolean | A function to be run for every target. |
|
||||
| options | [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) | |
|
||||
|
||||
<b>Returns:</b>
|
||||
|
||||
Promise<[Target](./puppeteer.target.md)<!-- -->>
|
||||
|
||||
{<!-- -->!Promise<!-- --><<!-- -->!Target<!-- -->><!-- -->}
|
||||
The first target found that matches the `predicate` function.
|
||||
|
||||
## Example
|
||||
|
||||
An example of finding a target for a page opened via `window.open`<!-- -->:
|
||||
|
||||
```js
|
||||
await page.evaluate(() => window.open('https://www.example.com/'));
|
||||
const newWindowTarget = await browser.waitForTarget(target => target.url() === 'https://www.example.com/');
|
||||
|
||||
```
|
||||
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
## Browser.wsEndpoint() method
|
||||
|
||||
The browser websocket endpoint which can be used as an argument to [Puppeteer.connect()](./puppeteer.puppeteer.connect.md)<!-- -->.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
@ -13,3 +15,11 @@ wsEndpoint(): string;
|
||||
|
||||
string
|
||||
|
||||
The Browser websocket url.
|
||||
|
||||
## Remarks
|
||||
|
||||
The format is `ws://${host}:${port}/devtools/browser/<id>`<!-- -->.
|
||||
|
||||
You can find the `webSocketDebuggerUrl` from `http://${host}:${port}/json/version`<!-- -->. Learn more about the [devtools protocol](https://chromedevtools.github.io/devtools-protocol) and the [browser endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target)<!-- -->.
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
| Class | Description |
|
||||
| --- | --- |
|
||||
| [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting Chromium's accessibility tree. The accessibility tree is used by assistive technology such as [screen readers](https://en.wikipedia.org/wiki/Screen_reader) or [switches](https://en.wikipedia.org/wiki/Switch_access)<!-- -->. |
|
||||
| [Browser](./puppeteer.browser.md) | |
|
||||
| [Browser](./puppeteer.browser.md) | A Browser is created when Puppeteer connects to a Chromium instance, either through [Puppeteer.launch()](./puppeteer.puppeteer.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md)<!-- -->. |
|
||||
| [BrowserContext](./puppeteer.browsercontext.md) | |
|
||||
| [BrowserFetcher](./puppeteer.browserfetcher.md) | |
|
||||
| [CDPSession](./puppeteer.cdpsession.md) | The <code>CDPSession</code> instances are used to talk raw Chrome Devtools Protocol. |
|
||||
@ -56,6 +56,7 @@
|
||||
| [PressOptions](./puppeteer.pressoptions.md) | |
|
||||
| [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. |
|
||||
| [SnapshotOptions](./puppeteer.snapshotoptions.md) | |
|
||||
| [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) | |
|
||||
|
||||
## Variables
|
||||
|
||||
|
19
new-docs/puppeteer.waitfortargetoptions.md
Normal file
19
new-docs/puppeteer.waitfortargetoptions.md
Normal file
@ -0,0 +1,19 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md)
|
||||
|
||||
## WaitForTargetOptions interface
|
||||
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
export interface WaitForTargetOptions
|
||||
```
|
||||
|
||||
## Properties
|
||||
|
||||
| Property | Type | Description |
|
||||
| --- | --- | --- |
|
||||
| [timeout](./puppeteer.waitfortargetoptions.timeout.md) | number | Maximum wait time in milliseconds. Pass <code>0</code> to disable the timeout. |
|
||||
|
13
new-docs/puppeteer.waitfortargetoptions.timeout.md
Normal file
13
new-docs/puppeteer.waitfortargetoptions.timeout.md
Normal file
@ -0,0 +1,13 @@
|
||||
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
|
||||
|
||||
[Home](./index.md) > [puppeteer](./puppeteer.md) > [WaitForTargetOptions](./puppeteer.waitfortargetoptions.md) > [timeout](./puppeteer.waitfortargetoptions.timeout.md)
|
||||
|
||||
## WaitForTargetOptions.timeout property
|
||||
|
||||
Maximum wait time in milliseconds. Pass `0` to disable the timeout.
|
||||
|
||||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
timeout?: number;
|
||||
```
|
@ -27,7 +27,61 @@ import { Viewport } from './PuppeteerViewport';
|
||||
|
||||
type BrowserCloseCallback = () => Promise<void> | void;
|
||||
|
||||
/**
|
||||
* @public
|
||||
*/
|
||||
export interface WaitForTargetOptions {
|
||||
/**
|
||||
* Maximum wait time in milliseconds. Pass `0` to disable the timeout.
|
||||
* @defaultValue 30 seconds.
|
||||
*/
|
||||
timeout?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* A Browser is created when Puppeteer connects to a Chromium instance, either through
|
||||
* {@link Puppeteer.launch} or {@link Puppeteer.connect}.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* An example of using a {@link Browser} to create a {@link Page}:
|
||||
* ```js
|
||||
* const puppeteer = require('puppeteer');
|
||||
*
|
||||
* (async () => {
|
||||
* const browser = await puppeteer.launch();
|
||||
* const page = await browser.newPage();
|
||||
* await page.goto('https://example.com');
|
||||
* await browser.close();
|
||||
* })();
|
||||
* ```
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* An example of disconnecting from and reconnecting to a {@link Browser}:
|
||||
* ```js
|
||||
* const puppeteer = require('puppeteer');
|
||||
*
|
||||
* (async () => {
|
||||
* const browser = await puppeteer.launch();
|
||||
* // Store the endpoint to be able to reconnect to Chromium
|
||||
* const browserWSEndpoint = browser.wsEndpoint();
|
||||
* // Disconnect puppeteer from Chromium
|
||||
* browser.disconnect();
|
||||
*
|
||||
* // Use the endpoint to reestablish a connection
|
||||
* const browser2 = await puppeteer.connect({browserWSEndpoint});
|
||||
* // Close Chromium
|
||||
* await browser2.close();
|
||||
* })();
|
||||
* ```
|
||||
*
|
||||
* @public
|
||||
*/
|
||||
export class Browser extends EventEmitter {
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
static async create(
|
||||
connection: Connection,
|
||||
contextIds: string[],
|
||||
@ -47,15 +101,22 @@ export class Browser extends EventEmitter {
|
||||
await connection.send('Target.setDiscoverTargets', { discover: true });
|
||||
return browser;
|
||||
}
|
||||
_ignoreHTTPSErrors: boolean;
|
||||
_defaultViewport?: Viewport;
|
||||
_process?: ChildProcess;
|
||||
_connection: Connection;
|
||||
_closeCallback: BrowserCloseCallback;
|
||||
_defaultContext: BrowserContext;
|
||||
_contexts: Map<string, BrowserContext>;
|
||||
private _ignoreHTTPSErrors: boolean;
|
||||
private _defaultViewport?: Viewport;
|
||||
private _process?: ChildProcess;
|
||||
private _connection: Connection;
|
||||
private _closeCallback: BrowserCloseCallback;
|
||||
private _defaultContext: BrowserContext;
|
||||
private _contexts: Map<string, BrowserContext>;
|
||||
/**
|
||||
* @internal
|
||||
* Used in Target.ts directly so cannot be marked private.
|
||||
*/
|
||||
_targets: Map<string, Target>;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(
|
||||
connection: Connection,
|
||||
contextIds: string[],
|
||||
@ -94,10 +155,31 @@ export class Browser extends EventEmitter {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The spawned browser process. Returns `null` if the browser instance was created with
|
||||
* {@link Puppeteer.connect}.
|
||||
*/
|
||||
process(): ChildProcess | null {
|
||||
return this._process;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new incognito browser context. This won't share cookies/cache with other
|
||||
* browser contexts.
|
||||
*
|
||||
* @example
|
||||
* ```js
|
||||
* (async () => {
|
||||
* const browser = await puppeteer.launch();
|
||||
* // Create a new incognito browser context.
|
||||
* const context = await browser.createIncognitoBrowserContext();
|
||||
* // Create a new page in a pristine context.
|
||||
* const page = await context.newPage();
|
||||
* // Do stuff
|
||||
* await page.goto('https://example.com');
|
||||
* })();
|
||||
* ```
|
||||
*/
|
||||
async createIncognitoBrowserContext(): Promise<BrowserContext> {
|
||||
const { browserContextId } = await this._connection.send(
|
||||
'Target.createBrowserContext'
|
||||
@ -111,16 +193,24 @@ export class Browser extends EventEmitter {
|
||||
return context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of all open browser contexts. In a newly created browser, this will
|
||||
* return a single instance of {@link BrowserContext}.
|
||||
*/
|
||||
browserContexts(): BrowserContext[] {
|
||||
return [this._defaultContext, ...Array.from(this._contexts.values())];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default browser context. The default browser context cannot be closed.
|
||||
*/
|
||||
defaultBrowserContext(): BrowserContext {
|
||||
return this._defaultContext;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {?string} contextId
|
||||
* @internal
|
||||
* Used by BrowserContext directly so cannot be marked private.
|
||||
*/
|
||||
async _disposeContext(contextId?: string): Promise<void> {
|
||||
await this._connection.send('Target.disposeBrowserContext', {
|
||||
@ -129,7 +219,7 @@ export class Browser extends EventEmitter {
|
||||
this._contexts.delete(contextId);
|
||||
}
|
||||
|
||||
async _targetCreated(
|
||||
private async _targetCreated(
|
||||
event: Protocol.Target.targetCreatedPayload
|
||||
): Promise<void> {
|
||||
const targetInfo = event.targetInfo;
|
||||
@ -158,10 +248,7 @@ export class Browser extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {{targetId: string}} event
|
||||
*/
|
||||
async _targetDestroyed(event: { targetId: string }): Promise<void> {
|
||||
private async _targetDestroyed(event: { targetId: string }): Promise<void> {
|
||||
const target = this._targets.get(event.targetId);
|
||||
target._initializedCallback(false);
|
||||
this._targets.delete(event.targetId);
|
||||
@ -174,10 +261,9 @@ export class Browser extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {!Protocol.Target.targetInfoChangedPayload} event
|
||||
*/
|
||||
_targetInfoChanged(event: Protocol.Target.targetInfoChangedPayload): void {
|
||||
private _targetInfoChanged(
|
||||
event: Protocol.Target.targetInfoChangedPayload
|
||||
): void {
|
||||
const target = this._targets.get(event.targetInfo.targetId);
|
||||
assert(target, 'target should exist before targetInfoChanged');
|
||||
const previousURL = target.url();
|
||||
@ -189,14 +275,38 @@ export class Browser extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The browser websocket endpoint which can be used as an argument to
|
||||
* {@link Puppeteer.connect}.
|
||||
*
|
||||
* @returns The Browser websocket url.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* The format is `ws://${host}:${port}/devtools/browser/<id>`.
|
||||
*
|
||||
* You can find the `webSocketDebuggerUrl` from `http://${host}:${port}/json/version`.
|
||||
* Learn more about the
|
||||
* {@link https://chromedevtools.github.io/devtools-protocol | devtools protocol} and
|
||||
* the {@link
|
||||
* https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target
|
||||
* | browser endpoint}.
|
||||
*/
|
||||
wsEndpoint(): string {
|
||||
return this._connection.url();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Page} in the default browser context.
|
||||
*/
|
||||
async newPage(): Promise<Page> {
|
||||
return this._defaultContext.newPage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* Used by BrowserContext directly so cannot be marked private.
|
||||
*/
|
||||
async _createPageInContext(contextId?: string): Promise<Page> {
|
||||
const { targetId } = await this._connection.send('Target.createTarget', {
|
||||
url: 'about:blank',
|
||||
@ -211,24 +321,40 @@ export class Browser extends EventEmitter {
|
||||
return page;
|
||||
}
|
||||
|
||||
/**
|
||||
* All active targets inside the Browser. In case of multiple browser contexts, returns
|
||||
* an array with all the targets in all browser contexts.
|
||||
*/
|
||||
targets(): Target[] {
|
||||
return Array.from(this._targets.values()).filter(
|
||||
(target) => target._isInitialized
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The target associated with the browser.
|
||||
*/
|
||||
target(): Target {
|
||||
return this.targets().find((target) => target.type() === 'browser');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {function(!Target):boolean} predicate
|
||||
* @param {{timeout?: number}=} options
|
||||
* @returns {!Promise<!Target>}
|
||||
* Searches for a target in all browser contexts.
|
||||
*
|
||||
* @param predicate - A function to be run for every target.
|
||||
* @returns The first target found that matches the `predicate` function.
|
||||
*
|
||||
* @example
|
||||
*
|
||||
* An example of finding a target for a page opened via `window.open`:
|
||||
* ```js
|
||||
* await page.evaluate(() => window.open('https://www.example.com/'));
|
||||
* const newWindowTarget = await browser.waitForTarget(target => target.url() === 'https://www.example.com/');
|
||||
* ```
|
||||
*/
|
||||
async waitForTarget(
|
||||
predicate: (x: Target) => boolean,
|
||||
options: { timeout?: number } = {}
|
||||
options: WaitForTargetOptions = {}
|
||||
): Promise<Target> {
|
||||
const { timeout = 30000 } = options;
|
||||
const existingTarget = this.targets().find(predicate);
|
||||
@ -254,6 +380,15 @@ export class Browser extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of all open pages inside the Browser.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* In case of multiple browser contexts, returns an array with all the pages in all
|
||||
* browser contexts. Non-visible pages, such as `"background_page"`, will not be listed
|
||||
* here. You can find them using {@link Target.page}.
|
||||
*/
|
||||
async pages(): Promise<Page[]> {
|
||||
const contextPages = await Promise.all(
|
||||
this.browserContexts().map((context) => context.pages())
|
||||
@ -262,30 +397,56 @@ export class Browser extends EventEmitter {
|
||||
return contextPages.reduce((acc, x) => acc.concat(x), []);
|
||||
}
|
||||
|
||||
/**
|
||||
* A string representing the browser name and version.
|
||||
*
|
||||
* @remarks
|
||||
*
|
||||
* For headless Chromium, this is similar to `HeadlessChrome/61.0.3153.0`. For
|
||||
* non-headless, this is similar to `Chrome/61.0.3153.0`.
|
||||
*
|
||||
* The format of browser.version() might change with future releases of Chromium.
|
||||
*/
|
||||
async version(): Promise<string> {
|
||||
const version = await this._getVersion();
|
||||
return version.product;
|
||||
}
|
||||
|
||||
/**
|
||||
* The browser's original user agent. Pages can override the browser user agent with
|
||||
* {@link Page.setUserAgent}.
|
||||
*/
|
||||
async userAgent(): Promise<string> {
|
||||
const version = await this._getVersion();
|
||||
return version.userAgent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Closes Chromium and all of its pages (if any were opened). The {@link Browser} object
|
||||
* itself is considered to be disposed and cannot be used anymore.
|
||||
*/
|
||||
async close(): Promise<void> {
|
||||
await this._closeCallback.call(null);
|
||||
this.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnects Puppeteer from the browser, but leaves the Chromium process running.
|
||||
* After calling `disconnect`, the {@link Browser} object is considered disposed and
|
||||
* cannot be used anymore.
|
||||
*/
|
||||
disconnect(): void {
|
||||
this._connection.dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates that the browser is connected.
|
||||
*/
|
||||
isConnected(): boolean {
|
||||
return !this._connection._closed;
|
||||
}
|
||||
|
||||
_getVersion(): Promise<Protocol.Browser.getVersionReturnValue> {
|
||||
private _getVersion(): Promise<Protocol.Browser.getVersionReturnValue> {
|
||||
return this._connection.send('Browser.getVersion');
|
||||
}
|
||||
}
|
||||
|
@ -664,6 +664,13 @@ function compareDocumentations(actual, expected) {
|
||||
expectedName: 'SnapshotOptions',
|
||||
},
|
||||
],
|
||||
[
|
||||
'Method Browser.waitForTarget() options',
|
||||
{
|
||||
actualName: 'Object',
|
||||
expectedName: 'WaitForTargetOptions',
|
||||
},
|
||||
],
|
||||
[
|
||||
'Method EventEmitter.emit() event',
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user