feat: implement BrowserContext.closed (#10928)

This commit is contained in:
jrandolf 2023-09-18 20:11:55 +02:00 committed by GitHub
parent fd72101f7b
commit 2292078969
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 168 additions and 150 deletions

View File

@ -7,10 +7,10 @@ sidebar_label: API
## Classes ## Classes
| Class | Description | | 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). | | [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) | <p>[Browser](./puppeteer.browser.md) represents a browser instance that is either:</p><p>- connected to via [Puppeteer.connect()](./puppeteer.puppeteer.connect.md) or - launched by [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md).</p><p>[Browser](./puppeteer.browser.md) [emits](./puppeteer.eventemitter.md) various events which are documented in the [BrowserEvent](./puppeteer.browserevent.md) enum.</p> | | [Browser](./puppeteer.browser.md) | <p>[Browser](./puppeteer.browser.md) represents a browser instance that is either:</p><p>- connected to via [Puppeteer.connect()](./puppeteer.puppeteer.connect.md) or - launched by [PuppeteerNode.launch()](./puppeteer.puppeteernode.launch.md).</p><p>[Browser](./puppeteer.browser.md) [emits](./puppeteer.eventemitter.md) various events which are documented in the [BrowserEvent](./puppeteer.browserevent.md) enum.</p> |
| [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. | | [BrowserContext](./puppeteer.browsercontext.md) | <p>[BrowserContext](./puppeteer.browsercontext.md) represents individual sessions within a [browser](./puppeteer.browser.md).</p><p>When a [browser](./puppeteer.browser.md) is launched, it has a single [browser context](./puppeteer.browsercontext.md) by default. Others can be created using [Browser.createIncognitoBrowserContext()](./puppeteer.browser.createincognitobrowsercontext.md).</p><p>[BrowserContext](./puppeteer.browsercontext.md) [emits](./puppeteer.eventemitter.md) various events which are documented in the [BrowserContextEvent](./puppeteer.browsercontextevent.md) enum.</p><p>If a [page](./puppeteer.page.md) opens another [page](./puppeteer.page.md), e.g. using <code>window.open</code>, the popup will belong to the parent [page's browser context](./puppeteer.page.browsercontext.md).</p> |
| [CDPSession](./puppeteer.cdpsession.md) | The <code>CDPSession</code> instances are used to talk raw Chrome Devtools Protocol. | | [CDPSession](./puppeteer.cdpsession.md) | The <code>CDPSession</code> instances are used to talk raw Chrome Devtools Protocol. |
| [Connection](./puppeteer.connection.md) | | | [Connection](./puppeteer.connection.md) | |
| [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. | | [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. |

View File

@ -4,13 +4,13 @@ sidebar_label: BrowserContext.browser
# BrowserContext.browser() method # BrowserContext.browser() method
The browser this browser context belongs to. Gets the [browser](./puppeteer.browser.md) associated with this [browser context](./puppeteer.browsercontext.md).
#### Signature: #### Signature:
```typescript ```typescript
class BrowserContext { class BrowserContext {
browser(): Browser; abstract browser(): Browser;
} }
``` ```

View File

@ -4,7 +4,7 @@ sidebar_label: BrowserContext.clearPermissionOverrides
# BrowserContext.clearPermissionOverrides() method # BrowserContext.clearPermissionOverrides() method
Clears all permission overrides for the browser context. Clears all permission overrides for this [browser context](./puppeteer.browsercontext.md).
#### Signature: #### Signature:
@ -20,6 +20,8 @@ Promise&lt;void&gt;
## Example ## Example
Clearing overridden permissions in the [default browser context](./puppeteer.browser.defaultbrowsercontext.md):
```ts ```ts
const context = browser.defaultBrowserContext(); const context = browser.defaultBrowserContext();
context.overridePermissions('https://example.com', ['clipboard-read']); context.overridePermissions('https://example.com', ['clipboard-read']);

View File

@ -4,13 +4,13 @@ sidebar_label: BrowserContext.close
# BrowserContext.close() method # BrowserContext.close() method
Closes the browser context. All the targets that belong to the browser context will be closed. Closes this [browser context](./puppeteer.browsercontext.md) and all associated [pages](./puppeteer.page.md).
#### Signature: #### Signature:
```typescript ```typescript
class BrowserContext { class BrowserContext {
close(): Promise<void>; abstract close(): Promise<void>;
} }
``` ```
@ -20,4 +20,4 @@ Promise&lt;void&gt;
## Remarks ## Remarks
Only incognito browser contexts can be closed. The [default browser context](./puppeteer.browser.defaultbrowsercontext.md) cannot be closed.

View File

@ -4,20 +4,18 @@ sidebar_label: BrowserContext.isIncognito
# BrowserContext.isIncognito() method # BrowserContext.isIncognito() method
Returns whether BrowserContext is incognito. The default browser context is the only non-incognito browser context. Whether this [browser context](./puppeteer.browsercontext.md) is incognito.
The [default browser context](./puppeteer.browser.defaultbrowsercontext.md) is the only non-incognito browser context.
#### Signature: #### Signature:
```typescript ```typescript
class BrowserContext { class BrowserContext {
isIncognito(): boolean; abstract isIncognito(): boolean;
} }
``` ```
**Returns:** **Returns:**
boolean boolean
## Remarks
The default browser context cannot be closed.

View File

@ -4,28 +4,30 @@ sidebar_label: BrowserContext
# BrowserContext class # BrowserContext class
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. [BrowserContext](./puppeteer.browsercontext.md) represents individual sessions within a [browser](./puppeteer.browser.md).
When a [browser](./puppeteer.browser.md) is launched, it has a single [browser context](./puppeteer.browsercontext.md) by default. Others can be created using [Browser.createIncognitoBrowserContext()](./puppeteer.browser.createincognitobrowsercontext.md).
[BrowserContext](./puppeteer.browsercontext.md) [emits](./puppeteer.eventemitter.md) various events which are documented in the [BrowserContextEvent](./puppeteer.browsercontextevent.md) enum.
If a [page](./puppeteer.page.md) opens another [page](./puppeteer.page.md), e.g. using `window.open`, the popup will belong to the parent [page's browser context](./puppeteer.page.browsercontext.md).
#### Signature: #### Signature:
```typescript ```typescript
export declare class BrowserContext extends EventEmitter<BrowserContextEvents> export declare abstract class BrowserContext extends EventEmitter<BrowserContextEvents>
``` ```
**Extends:** [EventEmitter](./puppeteer.eventemitter.md)&lt;[BrowserContextEvents](./puppeteer.browsercontextevents.md)&gt; **Extends:** [EventEmitter](./puppeteer.eventemitter.md)&lt;[BrowserContextEvents](./puppeteer.browsercontextevents.md)&gt;
## Remarks ## Remarks
The Browser class extends from Puppeteer's [EventEmitter](./puppeteer.eventemitter.md) class and will emit various events which are documented in the [BrowserContextEvents](./puppeteer.browsercontextevents.md) enum.
If a page opens another page, e.g. with a `window.open` call, the popup will belong to the parent page's browser context.
Puppeteer allows creation of "incognito" browser contexts with [Browser.createIncognitoBrowserContext](./puppeteer.browser.createincognitobrowsercontext.md) method. "Incognito" browser contexts don't write any browsing data to disk.
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the `BrowserContext` 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 `BrowserContext` class.
## Example ## Example
Creating an incognito [browser context](./puppeteer.browsercontext.md):
```ts ```ts
// Create a new incognito browser context // Create a new incognito browser context
const context = await browser.createIncognitoBrowserContext(); const context = await browser.createIncognitoBrowserContext();
@ -40,19 +42,20 @@ await context.close();
## Properties ## Properties
| Property | Modifiers | Type | Description | | Property | Modifiers | Type | Description |
| -------- | --------------------- | ------------------- | ----------- | | -------- | --------------------- | ------------------- | ------------------------------------------------------------------------ |
| id | <code>readonly</code> | string \| undefined | | | closed | <code>readonly</code> | boolean | Whether this [browser context](./puppeteer.browsercontext.md) is closed. |
| id | <code>readonly</code> | string \| undefined | Identifier for this [browser context](./puppeteer.browsercontext.md). |
## Methods ## Methods
| Method | Modifiers | Description | | Method | Modifiers | Description |
| --------------------------------------------------------------------------------------------- | --------- | ------------------------------------------------------------------------------------------------------------------- | | --------------------------------------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [browser()](./puppeteer.browsercontext.browser.md) | | The browser this browser context belongs to. | | [browser()](./puppeteer.browsercontext.browser.md) | | Gets the [browser](./puppeteer.browser.md) associated with this [browser context](./puppeteer.browsercontext.md). |
| [clearPermissionOverrides()](./puppeteer.browsercontext.clearpermissionoverrides.md) | | Clears all permission overrides for the browser context. | | [clearPermissionOverrides()](./puppeteer.browsercontext.clearpermissionoverrides.md) | | Clears all permission overrides for this [browser context](./puppeteer.browsercontext.md). |
| [close()](./puppeteer.browsercontext.close.md) | | Closes the browser context. All the targets that belong to the browser context will be closed. | | [close()](./puppeteer.browsercontext.close.md) | | Closes this [browser context](./puppeteer.browsercontext.md) and all associated [pages](./puppeteer.page.md). |
| [isIncognito()](./puppeteer.browsercontext.isincognito.md) | | Returns whether BrowserContext is incognito. The default browser context is the only non-incognito browser context. | | [isIncognito()](./puppeteer.browsercontext.isincognito.md) | | <p>Whether this [browser context](./puppeteer.browsercontext.md) is incognito.</p><p>The [default browser context](./puppeteer.browser.defaultbrowsercontext.md) is the only non-incognito browser context.</p> |
| [newPage()](./puppeteer.browsercontext.newpage.md) | | Creates a new page in the browser context. | | [newPage()](./puppeteer.browsercontext.newpage.md) | | Creates a new [page](./puppeteer.page.md) in this [browser context](./puppeteer.browsercontext.md). |
| [overridePermissions(origin, permissions)](./puppeteer.browsercontext.overridepermissions.md) | | | | [overridePermissions(origin, permissions)](./puppeteer.browsercontext.overridepermissions.md) | | Grants this [browser context](./puppeteer.browsercontext.md) the given <code>permissions</code> within the given <code>origin</code>. |
| [pages()](./puppeteer.browsercontext.pages.md) | | An array of all pages inside the browser context. | | [pages()](./puppeteer.browsercontext.pages.md) | | Gets a list of all open [pages](./puppeteer.page.md) inside this [browser context](./puppeteer.browsercontext.md). |
| [targets()](./puppeteer.browsercontext.targets.md) | | An array of all active targets inside the browser context. | | [targets()](./puppeteer.browsercontext.targets.md) | | Gets all active [targets](./puppeteer.target.md) inside this [browser context](./puppeteer.browsercontext.md). |
| [waitForTarget(predicate, options)](./puppeteer.browsercontext.waitfortarget.md) | | This searches for a target in this specific browser context. | | [waitForTarget(predicate, options)](./puppeteer.browsercontext.waitfortarget.md) | | <p>Waits until a [target](./puppeteer.target.md) matching the given <code>predicate</code> appears and returns it.</p><p>This will look all open [browser contexts](./puppeteer.browsercontext.md).</p> |

View File

@ -4,13 +4,13 @@ sidebar_label: BrowserContext.newPage
# BrowserContext.newPage() method # BrowserContext.newPage() method
Creates a new page in the browser context. Creates a new [page](./puppeteer.page.md) in this [browser context](./puppeteer.browsercontext.md).
#### Signature: #### Signature:
```typescript ```typescript
class BrowserContext { class BrowserContext {
newPage(): Promise<Page>; abstract newPage(): Promise<Page>;
} }
``` ```

View File

@ -4,6 +4,8 @@ sidebar_label: BrowserContext.overridePermissions
# BrowserContext.overridePermissions() method # BrowserContext.overridePermissions() method
Grants this [browser context](./puppeteer.browsercontext.md) the given `permissions` within the given `origin`.
#### Signature: #### Signature:
```typescript ```typescript
@ -25,6 +27,8 @@ Promise&lt;void&gt;
## Example ## Example
Overriding permissions in the [default browser context](./puppeteer.browser.defaultbrowsercontext.md):
```ts ```ts
const context = browser.defaultBrowserContext(); const context = browser.defaultBrowserContext();
await context.overridePermissions('https://html5demos.com', ['geolocation']); await context.overridePermissions('https://html5demos.com', ['geolocation']);

View File

@ -4,13 +4,13 @@ sidebar_label: BrowserContext.pages
# BrowserContext.pages() method # BrowserContext.pages() method
An array of all pages inside the browser context. Gets a list of all open [pages](./puppeteer.page.md) inside this [browser context](./puppeteer.browsercontext.md).
#### Signature: #### Signature:
```typescript ```typescript
class BrowserContext { class BrowserContext {
pages(): Promise<Page[]>; abstract pages(): Promise<Page[]>;
} }
``` ```
@ -18,4 +18,6 @@ class BrowserContext {
Promise&lt;[Page](./puppeteer.page.md)\[\]&gt; Promise&lt;[Page](./puppeteer.page.md)\[\]&gt;
Promise which resolves to an array of all open pages. Non visible pages, such as `"background_page"`, will not be listed here. You can find them using [the target page](./puppeteer.target.page.md). ## Remarks
Non-visible [pages](./puppeteer.page.md), such as `"background_page"`, will not be listed here. You can find them using [Target.page()](./puppeteer.target.page.md).

View File

@ -4,7 +4,7 @@ sidebar_label: BrowserContext.targets
# BrowserContext.targets() method # BrowserContext.targets() method
An array of all active targets inside the browser context. Gets all active [targets](./puppeteer.target.md) inside this [browser context](./puppeteer.browsercontext.md).
#### Signature: #### Signature:

View File

@ -4,13 +4,15 @@ sidebar_label: BrowserContext.waitForTarget
# BrowserContext.waitForTarget() method # BrowserContext.waitForTarget() method
This searches for a target in this specific browser context. 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).
#### Signature: #### Signature:
```typescript ```typescript
class BrowserContext { class BrowserContext {
waitForTarget( abstract waitForTarget(
predicate: (x: Target) => boolean | Promise<boolean>, predicate: (x: Target) => boolean | Promise<boolean>,
options?: { options?: {
timeout?: number; timeout?: number;
@ -22,19 +24,17 @@ class BrowserContext {
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | --------- | ---------------------------------------------------------------------------- | ------------ |
| predicate | (x: [Target](./puppeteer.target.md)) =&gt; boolean \| Promise&lt;boolean&gt; | A function to be run for every target | | predicate | (x: [Target](./puppeteer.target.md)) =&gt; boolean \| Promise&lt;boolean&gt; | |
| options | { timeout?: number; } | _(Optional)_ An object of options. Accepts a timeout, which is the maximum wait time in milliseconds. Pass <code>0</code> to disable the timeout. Defaults to 30 seconds. | | options | { timeout?: number; } | _(Optional)_ |
**Returns:** **Returns:**
Promise&lt;[Target](./puppeteer.target.md)&gt; Promise&lt;[Target](./puppeteer.target.md)&gt;
Promise which resolves to the first target found that matches the `predicate` function.
## Example ## Example
An example of finding a target for a page opened via `window.open`: Finding a target for a page opened via `window.open`:
```ts ```ts
await page.evaluate(() => window.open('https://www.example.com/')); await page.evaluate(() => window.open('https://www.example.com/'));

View File

@ -15,6 +15,7 @@
*/ */
import {EventEmitter, type EventType} from '../common/EventEmitter.js'; import {EventEmitter, type EventType} from '../common/EventEmitter.js';
import {debugError} from '../common/util.js';
import type {Browser, Permission} from './Browser.js'; import type {Browser, Permission} from './Browser.js';
import {type Page} from './Page.js'; import {type Page} from './Page.js';
@ -63,25 +64,21 @@ export interface BrowserContextEvents extends Record<EventType, unknown> {
} }
/** /**
* BrowserContexts provide a way to operate multiple independent browser * {@link BrowserContext} represents individual sessions within a
* sessions. When a browser is launched, it has a single BrowserContext used by * {@link Browser | browser}.
* default. The method {@link Browser.newPage | Browser.newPage} creates a page
* in the default browser context.
* *
* @remarks * When a {@link Browser | browser} is launched, it has a single
* {@link BrowserContext | browser context} by default. Others can be created
* using {@link Browser.createIncognitoBrowserContext}.
* *
* The Browser class extends from Puppeteer's {@link EventEmitter} class and * {@link BrowserContext} {@link EventEmitter | emits} various events which are
* will emit various events which are documented in the * documented in the {@link BrowserContextEvent} enum.
* {@link BrowserContextEvents} enum.
* *
* If a page opens another page, e.g. with a `window.open` call, the popup will * If a {@link Page | page} opens another {@link Page | page}, e.g. using
* belong to the parent page's browser context. * `window.open`, the popup will belong to the parent {@link Page.browserContext
* | page's browser context}.
* *
* Puppeteer allows creation of "incognito" browser contexts with * @example Creating an incognito {@link BrowserContext | browser context}:
* {@link Browser.createIncognitoBrowserContext | Browser.createIncognitoBrowserContext}
* method. "Incognito" browser contexts don't write any browsing data to disk.
*
* @example
* *
* ```ts * ```ts
* // Create a new incognito browser context * // Create a new incognito browser context
@ -97,7 +94,7 @@ export interface BrowserContextEvents extends Record<EventType, unknown> {
* @public * @public
*/ */
export class BrowserContext extends EventEmitter<BrowserContextEvents> { export abstract class BrowserContext extends EventEmitter<BrowserContextEvents> {
/** /**
* @internal * @internal
*/ */
@ -106,17 +103,20 @@ export class BrowserContext extends EventEmitter<BrowserContextEvents> {
} }
/** /**
* An array of all active targets inside the browser context. * Gets all active {@link Target | targets} inside this
* {@link BrowserContext | browser context}.
*/ */
targets(): Target[] { targets(): Target[] {
throw new Error('Not implemented'); throw new Error('Not implemented');
} }
/** /**
* This searches for a target in this specific browser context. * Waits until a {@link Target | target} matching the given `predicate`
* appears and returns it.
* *
* @example * This will look all open {@link BrowserContext | browser contexts}.
* An example of finding a target for a page opened via `window.open`: *
* @example Finding a target for a page opened via `window.open`:
* *
* ```ts * ```ts
* await page.evaluate(() => window.open('https://www.example.com/')); * await page.evaluate(() => window.open('https://www.example.com/'));
@ -124,46 +124,35 @@ export class BrowserContext extends EventEmitter<BrowserContextEvents> {
* target => target.url() === 'https://www.example.com/' * target => target.url() === 'https://www.example.com/'
* ); * );
* ``` * ```
*
* @param predicate - A function to be run for every target
* @param options - An object of options. Accepts a timeout,
* which is the maximum wait time in milliseconds.
* Pass `0` to disable the timeout. Defaults to 30 seconds.
* @returns Promise which resolves to the first target found
* that matches the `predicate` function.
*/ */
waitForTarget( abstract waitForTarget(
predicate: (x: Target) => boolean | Promise<boolean>, predicate: (x: Target) => boolean | Promise<boolean>,
options?: {timeout?: number} options?: {timeout?: number}
): Promise<Target>; ): Promise<Target>;
waitForTarget(): Promise<Target> {
throw new Error('Not implemented');
}
/** /**
* An array of all pages inside the browser context. * Gets a list of all open {@link Page | pages} inside this
* {@link BrowserContext | browser context}.
* *
* @returns Promise which resolves to an array of all open pages. * @remarks Non-visible {@link Page | pages}, such as `"background_page"`,
* Non visible pages, such as `"background_page"`, will not be listed here. * will not be listed here. You can find them using {@link Target.page}.
* You can find them using {@link Target.page | the target page}.
*/ */
pages(): Promise<Page[]> { abstract pages(): Promise<Page[]>;
throw new Error('Not implemented');
}
/** /**
* Returns whether BrowserContext is incognito. * Whether this {@link BrowserContext | browser context} is incognito.
* The default browser context is the only non-incognito browser context.
* *
* @remarks * The {@link Browser.defaultBrowserContext | default browser context} is the
* The default browser context cannot be closed. * only non-incognito browser context.
*/ */
isIncognito(): boolean { abstract isIncognito(): boolean;
throw new Error('Not implemented');
}
/** /**
* @example * Grants this {@link BrowserContext | browser context} the given
* `permissions` within the given `origin`.
*
* @example Overriding permissions in the
* {@link Browser.defaultBrowserContext | default browser context}:
* *
* ```ts * ```ts
* const context = browser.defaultBrowserContext(); * const context = browser.defaultBrowserContext();
@ -172,9 +161,10 @@ export class BrowserContext extends EventEmitter<BrowserContextEvents> {
* ]); * ]);
* ``` * ```
* *
* @param origin - The origin to grant permissions to, e.g. "https://example.com". * @param origin - The origin to grant permissions to, e.g.
* @param permissions - An array of permissions to grant. * "https://example.com".
* All permissions that are not listed here will be automatically denied. * @param permissions - An array of permissions to grant. All permissions that
* are not listed here will be automatically denied.
*/ */
overridePermissions(origin: string, permissions: Permission[]): Promise<void>; overridePermissions(origin: string, permissions: Permission[]): Promise<void>;
overridePermissions(): Promise<void> { overridePermissions(): Promise<void> {
@ -182,9 +172,11 @@ export class BrowserContext extends EventEmitter<BrowserContextEvents> {
} }
/** /**
* Clears all permission overrides for the browser context. * Clears all permission overrides for this
* {@link BrowserContext | browser context}.
* *
* @example * @example Clearing overridden permissions in the
* {@link Browser.defaultBrowserContext | default browser context}:
* *
* ```ts * ```ts
* const context = browser.defaultBrowserContext(); * const context = browser.defaultBrowserContext();
@ -198,31 +190,48 @@ export class BrowserContext extends EventEmitter<BrowserContextEvents> {
} }
/** /**
* Creates a new page in the browser context. * Creates a new {@link Page | page} in this
* {@link BrowserContext | browser context}.
*/ */
newPage(): Promise<Page> { abstract newPage(): Promise<Page>;
throw new Error('Not implemented');
}
/** /**
* The browser this browser context belongs to. * Gets the {@link Browser | browser} associated with this
* {@link BrowserContext | browser context}.
*/ */
browser(): Browser { abstract browser(): Browser;
throw new Error('Not implemented');
}
/** /**
* Closes the browser context. All the targets that belong to the browser context * Closes this {@link BrowserContext | browser context} and all associated
* will be closed. * {@link Page | pages}.
* *
* @remarks * @remarks The
* Only incognito browser contexts can be closed. * {@link Browser.defaultBrowserContext | default browser context} cannot be
* closed.
*/ */
close(): Promise<void> { abstract close(): Promise<void>;
throw new Error('Not implemented');
/**
* Whether this {@link BrowserContext | browser context} is closed.
*/
get closed(): boolean {
return !this.browser().browserContexts().includes(this);
} }
/**
* Identifier for this {@link BrowserContext | browser context}.
*/
get id(): string | undefined { get id(): string | undefined {
return undefined; return undefined;
} }
/** @internal */
[Symbol.dispose](): void {
return void this.close().catch(debugError);
}
/** @internal */
[Symbol.asyncDispose](): Promise<void> {
return this.close();
}
} }