Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(docs): Migrate BrowserContext events. #6168

Merged
merged 1 commit into from Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions new-docs/puppeteer.browsercontext.md
Expand Up @@ -15,6 +15,8 @@ export declare class BrowserContext extends EventEmitter

## Remarks

The Browser class extends from Puppeteer's [EventEmitter](./puppeteer.eventemitter.md) class and will emit various events which are documented in the [BrowserContextEmittedEvents](./puppeteer.browsercontextemittedevents.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.
Expand Down
20 changes: 20 additions & 0 deletions new-docs/puppeteer.browsercontextemittedevents.md
@@ -0,0 +1,20 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [puppeteer](./puppeteer.md) &gt; [BrowserContextEmittedEvents](./puppeteer.browsercontextemittedevents.md)

## BrowserContextEmittedEvents enum

<b>Signature:</b>

```typescript
export declare const enum BrowserContextEmittedEvents
```

## Enumeration Members

| Member | Value | Description |
| --- | --- | --- |
| TargetChanged | <code>&quot;targetchanged&quot;</code> | Emitted when the url of a target inside the browser context changes. Contains a [Target](./puppeteer.target.md) instance. |
| TargetCreated | <code>&quot;targetcreated&quot;</code> | Emitted when a target is created within the browser context, for example when a new page is opened by [window.open](https://developer.mozilla.org/en-US/docs/Web/API/Window/open) or by [browserContext.newPage](./puppeteer.browsercontext.newpage.md)<!-- -->Contains a [Target](./puppeteer.target.md) instance. |
| TargetDestroyed | <code>&quot;targetdestroyed&quot;</code> | Emitted when a target is destroyed within the browser context, for example when a page is closed. Contains a [Target](./puppeteer.target.md) instance. |

1 change: 1 addition & 0 deletions new-docs/puppeteer.md
Expand Up @@ -40,6 +40,7 @@

| Enumeration | Description |
| --- | --- |
| [BrowserContextEmittedEvents](./puppeteer.browsercontextemittedevents.md) | |
| [BrowserEmittedEvents](./puppeteer.browseremittedevents.md) | All the events a [browser instance](./puppeteer.browser.md) may emit. |
| [PageEmittedEvents](./puppeteer.pageemittedevents.md) | All the events that a page instance may emit. |

Expand Down
45 changes: 37 additions & 8 deletions src/common/Browser.ts
Expand Up @@ -297,7 +297,7 @@ export class Browser extends EventEmitter {

if (await target._initializedPromise) {
this.emit(BrowserEmittedEvents.TargetCreated, target);
context.emit(Events.BrowserContext.TargetCreated, target);
context.emit(BrowserContextEmittedEvents.TargetCreated, target);
}
}

Expand All @@ -310,7 +310,7 @@ export class Browser extends EventEmitter {
this.emit(BrowserEmittedEvents.TargetDestroyed, target);
target
.browserContext()
.emit(Events.BrowserContext.TargetDestroyed, target);
.emit(BrowserContextEmittedEvents.TargetDestroyed, target);
}
}

Expand All @@ -324,7 +324,9 @@ export class Browser extends EventEmitter {
target._targetInfoChanged(event.targetInfo);
if (wasInitialized && previousURL !== target.url()) {
this.emit(BrowserEmittedEvents.TargetChanged, target);
target.browserContext().emit(Events.BrowserContext.TargetChanged, target);
target
.browserContext()
.emit(BrowserContextEmittedEvents.TargetChanged, target);
}
}

Expand Down Expand Up @@ -504,16 +506,43 @@ export class Browser extends EventEmitter {
}
}

export const enum BrowserContextEmittedEvents {
/**
* Emitted when the url of a target inside the browser context changes.
* Contains a {@link Target} instance.
*/
TargetChanged = 'targetchanged',

/**
* Emitted when a target is created within the browser context, for example
* when a new page is opened by
* {@link https://developer.mozilla.org/en-US/docs/Web/API/Window/open | window.open}
* or by {@link BrowserContext.newPage | browserContext.newPage}
*
* Contains a {@link Target} instance.
*/
TargetCreated = 'targetcreated',
/**
* Emitted when a target is destroyed within the browser context, for example
* when a page is closed. Contains a {@link Target} instance.
*/
TargetDestroyed = 'targetdestroyed',
}

/**
* 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 {@link Browser.newPage | Browser.newPage} creates a page
* 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 {@link Browser.newPage | Browser.newPage} creates a page
* in the default browser context.
*
* @remarks
*
* If a page opens another page, e.g. with a `window.open` call,
* the popup will belong to the parent page's browser context.
* The Browser class extends from Puppeteer's {@link EventEmitter} class and
* will emit various events which are documented in the
* {@link BrowserContextEmittedEvents} 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
* {@link Browser.createIncognitoBrowserContext | Browser.createIncognitoBrowserContext}
Expand Down