Skip to content

Commit

Permalink
chore(docs): migrate BrowserContext events (#6168)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackfranklin committed Jul 7, 2020
1 parent e2e0502 commit 2256b8d
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
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

0 comments on commit 2256b8d

Please sign in to comment.