feat(browserContext): add BrowserContext.browser() (#3849)
This commit is contained in:
parent
5314512cbc
commit
beceeaf6a1
|
|
@ -309,6 +309,7 @@ await context.close();
|
||||||
- [event: 'page'](#event-page)
|
- [event: 'page'](#event-page)
|
||||||
- [browserContext.addCookies(cookies)](#browsercontextaddcookiescookies)
|
- [browserContext.addCookies(cookies)](#browsercontextaddcookiescookies)
|
||||||
- [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg)
|
- [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg)
|
||||||
|
- [browserContext.browser()](#browsercontextbrowser)
|
||||||
- [browserContext.clearCookies()](#browsercontextclearcookies)
|
- [browserContext.clearCookies()](#browsercontextclearcookies)
|
||||||
- [browserContext.clearPermissions()](#browsercontextclearpermissions)
|
- [browserContext.clearPermissions()](#browsercontextclearpermissions)
|
||||||
- [browserContext.close()](#browsercontextclose)
|
- [browserContext.close()](#browsercontextclose)
|
||||||
|
|
@ -398,6 +399,10 @@ await browserContext.addInitScript({
|
||||||
```
|
```
|
||||||
|
|
||||||
> **NOTE** The order of evaluation of multiple scripts installed via [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg) and [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) is not defined.
|
> **NOTE** The order of evaluation of multiple scripts installed via [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg) and [page.addInitScript(script[, arg])](#pageaddinitscriptscript-arg) is not defined.
|
||||||
|
|
||||||
|
#### browserContext.browser()
|
||||||
|
- returns: <[null]|[Browser]> Returns the browser instance of the context. If it was launched as a persistent context null gets returned.
|
||||||
|
|
||||||
#### browserContext.clearCookies()
|
#### browserContext.clearCookies()
|
||||||
- returns: <[Promise]>
|
- returns: <[Promise]>
|
||||||
|
|
||||||
|
|
@ -4430,6 +4435,7 @@ const backgroundPage = await context.waitForEvent('backgroundpage');
|
||||||
- [event: 'page'](#event-page)
|
- [event: 'page'](#event-page)
|
||||||
- [browserContext.addCookies(cookies)](#browsercontextaddcookiescookies)
|
- [browserContext.addCookies(cookies)](#browsercontextaddcookiescookies)
|
||||||
- [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg)
|
- [browserContext.addInitScript(script[, arg])](#browsercontextaddinitscriptscript-arg)
|
||||||
|
- [browserContext.browser()](#browsercontextbrowser)
|
||||||
- [browserContext.clearCookies()](#browsercontextclearcookies)
|
- [browserContext.clearCookies()](#browsercontextclearcookies)
|
||||||
- [browserContext.clearPermissions()](#browsercontextclearpermissions)
|
- [browserContext.clearPermissions()](#browsercontextclearpermissions)
|
||||||
- [browserContext.close()](#browsercontextclose)
|
- [browserContext.close()](#browsercontextclose)
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import { isUnderTest, headersObjectToArray } from '../utils/utils';
|
||||||
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel, channels.BrowserContextInitializer> {
|
export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel, channels.BrowserContextInitializer> {
|
||||||
_pages = new Set<Page>();
|
_pages = new Set<Page>();
|
||||||
private _routes: { url: URLMatch, handler: network.RouteHandler }[] = [];
|
private _routes: { url: URLMatch, handler: network.RouteHandler }[] = [];
|
||||||
readonly _browser: Browser | undefined;
|
readonly _browser: Browser | null = null;
|
||||||
readonly _browserName: string;
|
readonly _browserName: string;
|
||||||
readonly _bindings = new Map<string, frames.FunctionWithSource>();
|
readonly _bindings = new Map<string, frames.FunctionWithSource>();
|
||||||
_timeoutSettings = new TimeoutSettings();
|
_timeoutSettings = new TimeoutSettings();
|
||||||
|
|
@ -92,6 +92,10 @@ export class BrowserContext extends ChannelOwner<channels.BrowserContextChannel,
|
||||||
this._channel.setDefaultTimeoutNoReply({ timeout });
|
this._channel.setDefaultTimeoutNoReply({ timeout });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
browser(): Browser | null {
|
||||||
|
return this._browser;
|
||||||
|
}
|
||||||
|
|
||||||
pages(): Page[] {
|
pages(): Page[] {
|
||||||
return [...this._pages];
|
return [...this._pages];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import * as fs from 'fs';
|
||||||
import { mkdirIfNeeded } from '../utils/utils';
|
import { mkdirIfNeeded } from '../utils/utils';
|
||||||
|
|
||||||
export class Download extends ChannelOwner<channels.DownloadChannel, channels.DownloadInitializer> {
|
export class Download extends ChannelOwner<channels.DownloadChannel, channels.DownloadInitializer> {
|
||||||
private _browser: Browser | undefined;
|
private _browser: Browser | null;
|
||||||
|
|
||||||
static from(download: channels.DownloadChannel): Download {
|
static from(download: channels.DownloadChannel): Download {
|
||||||
return (download as any)._object;
|
return (download as any)._object;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import { BrowserContext } from './browserContext';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
|
|
||||||
export class Video extends ChannelOwner<channels.VideoChannel, channels.VideoInitializer> {
|
export class Video extends ChannelOwner<channels.VideoChannel, channels.VideoInitializer> {
|
||||||
private _browser: Browser | undefined;
|
private _browser: Browser | null;
|
||||||
|
|
||||||
static from(channel: channels.VideoChannel): Video {
|
static from(channel: channels.VideoChannel): Video {
|
||||||
return (channel as any)._object;
|
return (channel as any)._object;
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,10 @@ it('should create new context', async function({browser}) {
|
||||||
const context = await browser.newContext();
|
const context = await browser.newContext();
|
||||||
expect(browser.contexts().length).toBe(1);
|
expect(browser.contexts().length).toBe(1);
|
||||||
expect(browser.contexts().indexOf(context) !== -1).toBe(true);
|
expect(browser.contexts().indexOf(context) !== -1).toBe(true);
|
||||||
|
expect(browser).toBe(context.browser());
|
||||||
await context.close();
|
await context.close();
|
||||||
expect(browser.contexts().length).toBe(0);
|
expect(browser.contexts().length).toBe(0);
|
||||||
|
expect(browser).toBe(context.browser());
|
||||||
});
|
});
|
||||||
|
|
||||||
it('window.open should use parent tab context', async function({browser, server}) {
|
it('window.open should use parent tab context', async function({browser, server}) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue