diff --git a/docs/api/index.md b/docs/api/index.md index 4a1e020e62b..4bbe55fc3a0 100644 --- a/docs/api/index.md +++ b/docs/api/index.md @@ -9,7 +9,7 @@ sidebar_label: API | Class | Description | | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | [Accessibility](./puppeteer.accessibility.md) | The Accessibility class provides methods for inspecting the browser'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) | A Browser is created when Puppeteer connects to a browser instance, either through [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md) or [Puppeteer.connect()](./puppeteer.puppeteer.connect.md). | +| [Browser](./puppeteer.browser.md) |
[Browser](./puppeteer.browser.md) represents a browser instance that is either:
- connected to via [Puppeteer.connect()](./puppeteer.puppeteer.connect.md) or - launched by [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md).
[Browser](./puppeteer.browser.md) [emits](./puppeteer.eventemitter.md) various events which are documented in the [BrowserEvent](./puppeteer.browserevent.md) enum.
| | [BrowserContext](./puppeteer.browsercontext.md) | BrowserContexts provide a way to operate multiple independent browser sessions. When a browser is launched, it has a single BrowserContext used by default. The method [Browser.newPage](./puppeteer.browser.newpage.md) creates a page in the default browser context. | | [CDPSession](./puppeteer.cdpsession.md) | TheCDPSession
instances are used to talk raw Chrome Devtools Protocol. |
| [Connection](./puppeteer.connection.md) | |
@@ -73,7 +73,7 @@ sidebar_label: API
| [BoxModel](./puppeteer.boxmodel.md) | |
| [BrowserConnectOptions](./puppeteer.browserconnectoptions.md) | Generic browser options that can be passed when launching any browser or when connecting to an existing browser instance. |
| [BrowserContextEvents](./puppeteer.browsercontextevents.md) | |
-| [BrowserContextOptions](./puppeteer.browsercontextoptions.md) | BrowserContext options. |
+| [BrowserContextOptions](./puppeteer.browsercontextoptions.md) | |
| [BrowserEvents](./puppeteer.browserevents.md) | |
| [BrowserLaunchArgumentOptions](./puppeteer.browserlaunchargumentoptions.md) | Launcher options that only apply to Chrome. |
| [CDPSessionEvents](./puppeteer.cdpsessionevents.md) | |
diff --git a/docs/api/puppeteer.browser.browsercontexts.md b/docs/api/puppeteer.browser.browsercontexts.md
index 1e81e41eb0f..1db6858fcdb 100644
--- a/docs/api/puppeteer.browser.browsercontexts.md
+++ b/docs/api/puppeteer.browser.browsercontexts.md
@@ -4,13 +4,15 @@ sidebar_label: Browser.browserContexts
# 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).
+Gets a list of open [browser contexts](./puppeteer.browsercontext.md).
+
+In a newly-created [browser](./puppeteer.browser.md), this will return a single instance of [BrowserContext](./puppeteer.browsercontext.md).
#### Signature:
```typescript
class Browser {
- browserContexts(): BrowserContext[];
+ abstract browserContexts(): BrowserContext[];
}
```
diff --git a/docs/api/puppeteer.browser.close.md b/docs/api/puppeteer.browser.close.md
index b7c30033e6d..5955b67162b 100644
--- a/docs/api/puppeteer.browser.close.md
+++ b/docs/api/puppeteer.browser.close.md
@@ -4,13 +4,13 @@ sidebar_label: Browser.close
# Browser.close() method
-Closes the browser 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.
+Closes this [browser](./puppeteer.browser.md) and all associated [pages](./puppeteer.page.md).
#### Signature:
```typescript
class Browser {
- close(): Promisedisconnect
, 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) | | Promise which resolves to a new [Page](./puppeteer.page.md) object. The Page is created in a 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 null
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). |
+| Method | Modifiers | Description |
+| ---------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [browserContexts()](./puppeteer.browser.browsercontexts.md) | | Gets a list of open [browser contexts](./puppeteer.browsercontext.md).
In a newly-created [browser](./puppeteer.browser.md), this will return a single instance of [BrowserContext](./puppeteer.browsercontext.md).
| +| [close()](./puppeteer.browser.close.md) | | Closes this [browser](./puppeteer.browser.md) and all associated [pages](./puppeteer.page.md). | +| [createIncognitoBrowserContext(options)](./puppeteer.browser.createincognitobrowsercontext.md) | |Creates a new incognito [browser context](./puppeteer.browsercontext.md).
This won't share cookies/cache with other [browser contexts](./puppeteer.browsercontext.md).
| +| [defaultBrowserContext()](./puppeteer.browser.defaultbrowsercontext.md) | | Gets the default [browser context](./puppeteer.browsercontext.md). | +| [disconnect()](./puppeteer.browser.disconnect.md) | | Disconnects Puppeteer from this [browser](./puppeteer.browser.md), but leaves the process running. | +| [isConnected()](./puppeteer.browser.isconnected.md) | | Whether Puppeteer is connected to this [browser](./puppeteer.browser.md). | +| [newPage()](./puppeteer.browser.newpage.md) | | Creates a new [page](./puppeteer.page.md) in the [default browser context](./puppeteer.browser.defaultbrowsercontext.md). | +| [pages()](./puppeteer.browser.pages.md) | |Gets a list of all open [pages](./puppeteer.page.md) inside this .
If there ar multiple [browser contexts](./puppeteer.browsercontext.md), this returns all [pages](./puppeteer.page.md) in all [browser contexts](./puppeteer.browsercontext.md).
| +| [process()](./puppeteer.browser.process.md) | | Gets the associated [ChildProcess](https://nodejs.org/api/child_process.html#class-childprocess). | +| [target()](./puppeteer.browser.target.md) | | Gets the [target](./puppeteer.target.md) associated with the [default browser context](./puppeteer.browser.defaultbrowsercontext.md)). | +| [targets()](./puppeteer.browser.targets.md) | |Gets all active [targets](./puppeteer.target.md).
In case of multiple [browser contexts](./puppeteer.browsercontext.md), this returns all [targets](./puppeteer.target.md) in all [browser contexts](./puppeteer.browsercontext.md).
| +| [userAgent()](./puppeteer.browser.useragent.md) | |Gets this [browser's](./puppeteer.browser.md) original user agent.
[Pages](./puppeteer.page.md) can override the user agent with [Page.setUserAgent()](./puppeteer.page.setuseragent.md).
| +| [version()](./puppeteer.browser.version.md) | |Gets a string representing this [browser's](./puppeteer.browser.md) name and version.
For headless browser, this is similar to "HeadlessChrome/61.0.3153.0"
. For non-headless or new-headless, this is similar to "Chrome/61.0.3153.0"
. For Firefox, it is similar to "Firefox/116.0a1"
.
The format of [Browser.version()](./puppeteer.browser.version.md) might change with future releases of browsers.
| +| [waitForTarget(predicate, options)](./puppeteer.browser.waitfortarget.md) | |Waits until a [target](./puppeteer.target.md) matching the given predicate
appears and returns it.
This will look all open [browser contexts](./puppeteer.browsercontext.md).
| +| [wsEndpoint()](./puppeteer.browser.wsendpoint.md) | |Gets the WebSocket URL to connect to this [browser](./puppeteer.browser.md).
This is usually used with [Puppeteer.connect()](./puppeteer.puppeteer.connect.md).
You can find the debugger URL (webSocketDebuggerUrl
) from http://${host}:${port}/json/version
.
See [browser endpoint](https://chromedevtools.github.io/devtools-protocol/#how-do-i-access-the-browser-target) for more information.
| diff --git a/docs/api/puppeteer.browser.newpage.md b/docs/api/puppeteer.browser.newpage.md index 4f659e3f851..9be04d72dae 100644 --- a/docs/api/puppeteer.browser.newpage.md +++ b/docs/api/puppeteer.browser.newpage.md @@ -4,13 +4,13 @@ sidebar_label: Browser.newPage # Browser.newPage() method -Promise which resolves to a new [Page](./puppeteer.page.md) object. The Page is created in a default browser context. +Creates a new [page](./puppeteer.page.md) in the [default browser context](./puppeteer.browser.defaultbrowsercontext.md). #### Signature: ```typescript class Browser { - newPage(): Promise"disconnected"
| Emitted when Puppeteer gets disconnected from the browser instance. This might happen because of one of the following:
- browser is closed or crashed
- The [browser.disconnect](./puppeteer.browser.disconnect.md) method was called.
| -| TargetChanged |"targetchanged"
| Emitted when the url of a target changes. Contains a [Target](./puppeteer.target.md) instance. |
+| Disconnected | "disconnected"
| Emitted when Puppeteer gets disconnected from the browser instance. This might happen because either:
- The browser closes/crashes or - [Browser.disconnect()](./puppeteer.browser.disconnect.md) was called.
| +| TargetChanged |"targetchanged"
| Emitted when the URL of a target changes. Contains a [Target](./puppeteer.target.md) instance. |
| TargetCreated | "targetcreated"
| Emitted when a target is created, for example when a new page is opened by [window.open](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) or by [browser.newPage](./puppeteer.browser.newpage.md)
Contains a [Target](./puppeteer.target.md) instance.
| | TargetDestroyed |"targetdestroyed"
| Emitted when a target is destroyed, for example when a page is closed. Contains a [Target](./puppeteer.target.md) instance. |
diff --git a/packages/puppeteer-core/src/api/Browser.ts b/packages/puppeteer-core/src/api/Browser.ts
index 27b4c5393fd..7c1ca47db7b 100644
--- a/packages/puppeteer-core/src/api/Browser.ts
+++ b/packages/puppeteer-core/src/api/Browser.ts
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-/* eslint-disable @typescript-eslint/no-unused-vars */
-
import {type ChildProcess} from 'child_process';
import {type Protocol} from 'devtools-protocol';
@@ -30,8 +28,6 @@ import type {Page} from './Page.js';
import type {Target} from './Target.js';
/**
- * BrowserContext options.
- *
* @public
*/
export interface BrowserContextOptions {
@@ -120,6 +116,7 @@ export type Permission =
export interface WaitForTargetOptions {
/**
* Maximum wait time in milliseconds. Pass `0` to disable the timeout.
+ *
* @defaultValue `30_000`
*/
timeout?: number;
@@ -133,19 +130,18 @@ export interface WaitForTargetOptions {
export const enum BrowserEvent {
/**
* Emitted when Puppeteer gets disconnected from the browser instance. This
- * might happen because of one of the following:
+ * might happen because either:
*
- * - browser is closed or crashed
- *
- * - The {@link Browser.disconnect | browser.disconnect } method was called.
+ * - The browser closes/crashes or
+ * - {@link Browser.disconnect} was called.
*/
Disconnected = 'disconnected',
/**
- * Emitted when the url of a target changes. Contains a {@link Target} instance.
+ * Emitted when the URL of a target changes. Contains a {@link Target}
+ * instance.
*
- * @remarks
- *
- * Note that this includes target changes in incognito browser contexts.
+ * @remarks Note that this includes target changes in incognito browser
+ * contexts.
*/
TargetChanged = 'targetchanged',
/**
@@ -155,18 +151,16 @@ export const enum BrowserEvent {
*
* Contains a {@link Target} instance.
*
- * @remarks
- *
- * Note that this includes target creations in incognito browser contexts.
+ * @remarks Note that this includes target creations in incognito browser
+ * contexts.
*/
TargetCreated = 'targetcreated',
/**
* Emitted when a target is destroyed, for example when a page is closed.
* Contains a {@link Target} instance.
*
- * @remarks
- *
- * Note that this includes target destructions in incognito browser contexts.
+ * @remarks Note that this includes target destructions in incognito browser
+ * contexts.
*/
TargetDestroyed = 'targetdestroyed',
/**
@@ -197,51 +191,45 @@ export interface BrowserEvents extends Record