playwright-core
Advanced tools
Comparing version 0.11.1-next.1583455961750 to 0.11.1-next.1583512728058
@@ -17,6 +17,7 @@ /** | ||
*/ | ||
import * as network from './network'; | ||
import { Page, PageBinding } from './page'; | ||
import * as network from './network'; | ||
import * as platform from './platform'; | ||
import { TimeoutSettings } from './timeoutSettings'; | ||
import * as types from './types'; | ||
import { TimeoutSettings } from './timeoutSettings'; | ||
export declare type BrowserContextOptions = { | ||
@@ -42,3 +43,3 @@ viewport?: types.Viewport | null; | ||
newPage(): Promise<Page>; | ||
cookies(...urls: string[]): Promise<network.NetworkCookie[]>; | ||
cookies(urls?: string | string[]): Promise<network.NetworkCookie[]>; | ||
setCookies(cookies: network.SetNetworkCookieParam[]): Promise<void>; | ||
@@ -56,10 +57,42 @@ clearCookies(): Promise<void>; | ||
exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
waitForEvent(event: string, optionsOrPredicate?: Function | (types.TimeoutOptions & { | ||
predicate?: Function; | ||
})): Promise<any>; | ||
close(): Promise<void>; | ||
_existingPages(): Page[]; | ||
} | ||
export declare abstract class BrowserContextBase extends platform.EventEmitter implements BrowserContext { | ||
readonly _timeoutSettings: TimeoutSettings; | ||
readonly _pageBindings: Map<string, PageBinding>; | ||
readonly _options: BrowserContextOptions; | ||
readonly _pageBindings: Map<string, PageBinding>; | ||
_closed: boolean; | ||
private readonly _closePromise; | ||
private _closePromiseFulfill; | ||
constructor(options: BrowserContextOptions); | ||
abstract _existingPages(): Page[]; | ||
_browserClosed(): void; | ||
_didCloseInternal(): void; | ||
abstract pages(): Promise<Page[]>; | ||
abstract newPage(): Promise<Page>; | ||
abstract cookies(...urls: string[]): Promise<network.NetworkCookie[]>; | ||
abstract setCookies(cookies: network.SetNetworkCookieParam[]): Promise<void>; | ||
abstract clearCookies(): Promise<void>; | ||
abstract setPermissions(origin: string, permissions: string[]): Promise<void>; | ||
abstract clearPermissions(): Promise<void>; | ||
abstract setGeolocation(geolocation: types.Geolocation | null): Promise<void>; | ||
abstract setExtraHTTPHeaders(headers: network.Headers): Promise<void>; | ||
abstract setOffline(offline: boolean): Promise<void>; | ||
abstract addInitScript(script: string | Function | { | ||
path?: string | undefined; | ||
content?: string | undefined; | ||
}, ...args: any[]): Promise<void>; | ||
abstract exposeFunction(name: string, playwrightFunction: Function): Promise<void>; | ||
abstract close(): Promise<void>; | ||
setDefaultNavigationTimeout(timeout: number): void; | ||
setDefaultTimeout(timeout: number): void; | ||
waitForEvent(event: string, optionsOrPredicate?: Function | (types.TimeoutOptions & { | ||
predicate?: Function; | ||
})): Promise<any>; | ||
} | ||
export declare function assertBrowserContextIsNotOwned(context: BrowserContext): void; | ||
export declare function assertBrowserContextIsNotOwned(context: BrowserContextBase): void; | ||
export declare function validateBrowserContextOptions(options: BrowserContextOptions): BrowserContextOptions; | ||
export declare function verifyGeolocation(geolocation: types.Geolocation): types.Geolocation; |
@@ -19,4 +19,43 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const helper_1 = require("./helper"); | ||
const network = require("./network"); | ||
const helper_1 = require("./helper"); | ||
const platform = require("./platform"); | ||
const timeoutSettings_1 = require("./timeoutSettings"); | ||
const events_1 = require("./events"); | ||
class BrowserContextBase extends platform.EventEmitter { | ||
constructor(options) { | ||
super(); | ||
this._timeoutSettings = new timeoutSettings_1.TimeoutSettings(); | ||
this._pageBindings = new Map(); | ||
this._closed = false; | ||
this._options = options; | ||
this._closePromise = new Promise(fulfill => this._closePromiseFulfill = fulfill); | ||
} | ||
_browserClosed() { | ||
for (const page of this._existingPages()) | ||
page._didClose(); | ||
this._didCloseInternal(); | ||
} | ||
_didCloseInternal() { | ||
this._closed = true; | ||
this.emit(events_1.Events.BrowserContext.Close); | ||
this._closePromiseFulfill(new Error('Context closed')); | ||
} | ||
setDefaultNavigationTimeout(timeout) { | ||
this._timeoutSettings.setDefaultNavigationTimeout(timeout); | ||
} | ||
setDefaultTimeout(timeout) { | ||
this._timeoutSettings.setDefaultTimeout(timeout); | ||
} | ||
async waitForEvent(event, optionsOrPredicate) { | ||
if (!optionsOrPredicate) | ||
optionsOrPredicate = {}; | ||
if (typeof optionsOrPredicate === 'function') | ||
optionsOrPredicate = { predicate: optionsOrPredicate }; | ||
const { timeout = this._timeoutSettings.timeout(), predicate = () => true } = optionsOrPredicate; | ||
const abortPromise = (event === events_1.Events.BrowserContext.Close) ? new Promise(() => { }) : this._closePromise; | ||
return helper_1.helper.waitForEvent(this, event, (...args) => !!predicate(...args), timeout, abortPromise); | ||
} | ||
} | ||
exports.BrowserContextBase = BrowserContextBase; | ||
function assertBrowserContextIsNotOwned(context) { | ||
@@ -23,0 +62,0 @@ const pages = context._existingPages(); |
@@ -17,13 +17,12 @@ /** | ||
*/ | ||
import { BrowserContext, BrowserContextOptions } from '../browserContext'; | ||
import { CRConnection, CRSession } from './crConnection'; | ||
import { Page, PageBinding } from '../page'; | ||
import { CRTarget } from './crTarget'; | ||
import { Protocol } from './protocol'; | ||
import { Browser } from '../browser'; | ||
import { BrowserContext, BrowserContextBase, BrowserContextOptions } from '../browserContext'; | ||
import * as network from '../network'; | ||
import * as types from '../types'; | ||
import { Page } from '../page'; | ||
import * as platform from '../platform'; | ||
import { ConnectionTransport } from '../transport'; | ||
import { TimeoutSettings } from '../timeoutSettings'; | ||
import * as types from '../types'; | ||
import { CRConnection, CRSession } from './crConnection'; | ||
import { CRTarget } from './crTarget'; | ||
import { Protocol } from './protocol'; | ||
export declare class CRBrowser extends platform.EventEmitter implements Browser { | ||
@@ -62,18 +61,12 @@ _connection: CRConnection; | ||
} | ||
export declare class CRBrowserContext extends platform.EventEmitter implements BrowserContext { | ||
export declare class CRBrowserContext extends BrowserContextBase { | ||
readonly _browser: CRBrowser; | ||
readonly _browserContextId: string | null; | ||
readonly _options: BrowserContextOptions; | ||
readonly _timeoutSettings: TimeoutSettings; | ||
readonly _evaluateOnNewDocumentSources: string[]; | ||
readonly _pageBindings: Map<string, PageBinding>; | ||
private _closed; | ||
constructor(browser: CRBrowser, browserContextId: string | null, options: BrowserContextOptions); | ||
_initialize(): Promise<void>; | ||
_existingPages(): Page[]; | ||
setDefaultNavigationTimeout(timeout: number): void; | ||
setDefaultTimeout(timeout: number): void; | ||
pages(): Promise<Page[]>; | ||
newPage(): Promise<Page>; | ||
cookies(...urls: string[]): Promise<network.NetworkCookie[]>; | ||
cookies(urls?: string | string[]): Promise<network.NetworkCookie[]>; | ||
setCookies(cookies: network.SetNetworkCookieParam[]): Promise<void>; | ||
@@ -94,3 +87,2 @@ clearCookies(): Promise<void>; | ||
createSession(page: Page): Promise<CRSession>; | ||
_browserClosed(): void; | ||
} |
@@ -19,15 +19,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const events_1 = require("./events"); | ||
const events_2 = require("../events"); | ||
const browser_1 = require("../browser"); | ||
const browserContext_1 = require("../browserContext"); | ||
const events_1 = require("../events"); | ||
const helper_1 = require("../helper"); | ||
const browserContext_1 = require("../browserContext"); | ||
const crConnection_1 = require("./crConnection"); | ||
const network = require("../network"); | ||
const page_1 = require("../page"); | ||
const crTarget_1 = require("./crTarget"); | ||
const browser_1 = require("../browser"); | ||
const network = require("../network"); | ||
const platform = require("../platform"); | ||
const transport_1 = require("../transport"); | ||
const crConnection_1 = require("./crConnection"); | ||
const crProtocolHelper_1 = require("./crProtocolHelper"); | ||
const transport_1 = require("../transport"); | ||
const timeoutSettings_1 = require("../timeoutSettings"); | ||
const crTarget_1 = require("./crTarget"); | ||
const events_2 = require("./events"); | ||
class CRBrowser extends platform.EventEmitter { | ||
@@ -46,3 +45,3 @@ constructor(connection) { | ||
context._browserClosed(); | ||
this.emit(events_2.Events.Browser.Disconnected); | ||
this.emit(events_1.Events.Browser.Disconnected); | ||
}); | ||
@@ -109,3 +108,3 @@ this._client.on('Target.targetCreated', this._targetCreated.bind(this)); | ||
const event = new page_1.PageEvent(target.pageOrError()); | ||
context.emit(events_2.Events.BrowserContext.Page, event); | ||
context.emit(events_1.Events.BrowserContext.Page, event); | ||
const opener = target.opener(); | ||
@@ -116,3 +115,3 @@ if (!opener) | ||
if (openerPage instanceof page_1.Page && !openerPage.isClosed()) | ||
openerPage.emit(events_2.Events.Page.Popup, new page_1.PageEvent(target.pageOrError())); | ||
openerPage.emit(events_1.Events.Page.Popup, new page_1.PageEvent(target.pageOrError())); | ||
break; | ||
@@ -122,3 +121,3 @@ } | ||
const event = new page_1.PageEvent(target.pageOrError()); | ||
context.emit(events_1.Events.CRBrowserContext.BackgroundPage, event); | ||
context.emit(events_2.Events.CRBrowserContext.BackgroundPage, event); | ||
break; | ||
@@ -128,3 +127,3 @@ } | ||
const serviceWorker = await target.serviceWorker(); | ||
context.emit(events_1.Events.CRBrowserContext.ServiceWorker, serviceWorker); | ||
context.emit(events_2.Events.CRBrowserContext.ServiceWorker, serviceWorker); | ||
break; | ||
@@ -202,11 +201,7 @@ } | ||
exports.CRBrowser = CRBrowser; | ||
class CRBrowserContext extends platform.EventEmitter { | ||
class CRBrowserContext extends browserContext_1.BrowserContextBase { | ||
constructor(browser, browserContextId, options) { | ||
super(); | ||
this._pageBindings = new Map(); | ||
this._closed = false; | ||
super(options); | ||
this._browser = browser; | ||
this._browserContextId = browserContextId; | ||
this._timeoutSettings = new timeoutSettings_1.TimeoutSettings(); | ||
this._options = options; | ||
this._evaluateOnNewDocumentSources = []; | ||
@@ -230,8 +225,2 @@ } | ||
} | ||
setDefaultNavigationTimeout(timeout) { | ||
this._timeoutSettings.setDefaultNavigationTimeout(timeout); | ||
} | ||
setDefaultTimeout(timeout) { | ||
this._timeoutSettings.setDefaultTimeout(timeout); | ||
} | ||
async pages() { | ||
@@ -254,3 +243,3 @@ const targets = this._browser._allTargets().filter(target => target.context() === this && target.type() === 'page'); | ||
} | ||
async cookies(...urls) { | ||
async cookies(urls) { | ||
const { cookies } = await this._browser._client.send('Storage.getCookies', { browserContextId: this._browserContextId || undefined }); | ||
@@ -341,4 +330,3 @@ return network.filterCookies(cookies.map(c => { | ||
this._browser._contexts.delete(this._browserContextId); | ||
this._closed = true; | ||
this.emit(events_2.Events.BrowserContext.Close); | ||
this._didCloseInternal(); | ||
} | ||
@@ -353,10 +341,4 @@ async backgroundPages() { | ||
} | ||
_browserClosed() { | ||
this._closed = true; | ||
for (const page of this._existingPages()) | ||
page._didClose(); | ||
this.emit(events_2.Events.BrowserContext.Close); | ||
} | ||
} | ||
exports.CRBrowserContext = CRBrowserContext; | ||
//# sourceMappingURL=crBrowser.js.map |
@@ -86,3 +86,3 @@ "use strict"; | ||
]; | ||
const options = this._page.context()._options; | ||
const options = this._browserContext._options; | ||
if (options.bypassCSP) | ||
@@ -290,3 +290,3 @@ promises.push(this._client.send('Page.setBypassCSP', { enabled: true })); | ||
const headers = network.mergeHeaders([ | ||
this._page.context()._options.extraHTTPHeaders, | ||
this._browserContext._options.extraHTTPHeaders, | ||
this._page._state.extraHTTPHeaders | ||
@@ -301,3 +301,3 @@ ]); | ||
async _updateViewport(updateTouch) { | ||
let viewport = this._page.context()._options.viewport || { width: 0, height: 0 }; | ||
let viewport = this._browserContext._options.viewport || { width: 0, height: 0 }; | ||
const viewportSize = this._page._state.viewportSize; | ||
@@ -304,0 +304,0 @@ if (viewportSize) |
@@ -20,2 +20,3 @@ /** | ||
import * as types from './types'; | ||
import Injected from './injected/injected'; | ||
import { Page } from './page'; | ||
@@ -36,3 +37,3 @@ import * as platform from './platform'; | ||
_createHandle(remoteObject: any): js.JSHandle; | ||
_injected(): Promise<js.JSHandle>; | ||
_injected(): Promise<js.JSHandle<Injected>>; | ||
_$(selector: string, scope?: ElementHandle): Promise<ElementHandle<Element> | null>; | ||
@@ -54,20 +55,20 @@ _$array(selector: string, scope?: ElementHandle): Promise<js.JSHandle<Element[]>>; | ||
private _offsetPoint; | ||
_performPointerAction(action: (point: types.Point) => Promise<void>, options?: PointerActionOptions & types.WaitForOptions): Promise<void>; | ||
_performPointerAction(action: (point: types.Point) => Promise<void>, options?: PointerActionOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
hover(options?: PointerActionOptions & types.WaitForOptions): Promise<void>; | ||
click(options?: ClickOptions & types.WaitForOptions): Promise<void>; | ||
dblclick(options?: MultiClickOptions & types.WaitForOptions): Promise<void>; | ||
tripleclick(options?: MultiClickOptions & types.WaitForOptions): Promise<void>; | ||
select(...values: (string | ElementHandle | types.SelectOption)[]): Promise<string[]>; | ||
fill(value: string): Promise<void>; | ||
setInputFiles(...files: (string | types.FilePayload)[]): Promise<void>; | ||
click(options?: ClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
dblclick(options?: MultiClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
tripleclick(options?: MultiClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
select(values: string | ElementHandle | types.SelectOption | string[] | ElementHandle[] | types.SelectOption[], options?: types.NavigateOptions): Promise<string[]>; | ||
fill(value: string, options?: types.NavigateOptions): Promise<void>; | ||
setInputFiles(files: string | types.FilePayload | string[] | types.FilePayload[]): Promise<void>; | ||
focus(): Promise<void>; | ||
type(text: string, options?: { | ||
delay?: number; | ||
}): Promise<void>; | ||
} & types.NavigateOptions): Promise<void>; | ||
press(key: string, options?: { | ||
delay?: number; | ||
text?: string; | ||
}): Promise<void>; | ||
check(options?: types.WaitForOptions): Promise<void>; | ||
uncheck(options?: types.WaitForOptions): Promise<void>; | ||
} & types.NavigateOptions): Promise<void>; | ||
check(options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
uncheck(options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
private _setChecked; | ||
@@ -85,3 +86,3 @@ boundingBox(): Promise<types.Rect | null>; | ||
export declare function waitForFunctionTask(selector: string | undefined, pageFunction: Function | string, options: types.WaitForFunctionOptions, ...args: any[]): Task; | ||
export declare function waitForSelectorTask(selector: string, visibility: types.Visibility, timeout: number): Task; | ||
export declare function waitForSelectorTask(selector: string, waitFor: 'attached' | 'detached' | 'visible' | 'hidden', timeout: number): Task; | ||
export declare const setFileInputFunction: (element: HTMLInputElement, payloads: types.FilePayload[]) => Promise<void>; |
@@ -140,3 +140,3 @@ "use strict"; | ||
return null; | ||
const pages = this._page.context()._existingPages(); | ||
const pages = this._page._browserContext._existingPages(); | ||
for (const page of pages) { | ||
@@ -231,3 +231,3 @@ const frame = page._frameManager.frame(frameId); | ||
await this._page.keyboard._ensureModifiers(restoreModifiers); | ||
}); | ||
}, options); | ||
} | ||
@@ -246,5 +246,10 @@ hover(options) { | ||
} | ||
async select(...values) { | ||
const options = values.map(value => typeof value === 'object' ? value : { value }); | ||
for (const option of options) { | ||
async select(values, options) { | ||
let vals; | ||
if (!Array.isArray(values)) | ||
vals = [values]; | ||
else | ||
vals = values; | ||
const selectOptions = vals.map((value) => typeof value === 'object' ? value : { value }); | ||
for (const option of selectOptions) { | ||
if (option instanceof ElementHandle) | ||
@@ -260,6 +265,6 @@ continue; | ||
return await this._page._frameManager.waitForNavigationsCreatedBy(async () => { | ||
return this._evaluateInUtility((injected, node, ...optionsToSelect) => injected.selectOptions(node, optionsToSelect), ...options); | ||
}); | ||
return this._evaluateInUtility((injected, node, ...optionsToSelect) => injected.selectOptions(node, optionsToSelect), ...selectOptions); | ||
}, options); | ||
} | ||
async fill(value) { | ||
async fill(value, options) { | ||
helper_1.assert(helper_1.helper.isString(value), 'Value must be string. Found value "' + value + '" of type "' + (typeof value) + '"'); | ||
@@ -274,5 +279,5 @@ await this._page._frameManager.waitForNavigationsCreatedBy(async () => { | ||
await this._page.keyboard.press('Delete'); | ||
}); | ||
}, options); | ||
} | ||
async setInputFiles(...files) { | ||
async setInputFiles(files) { | ||
const multiple = await this._evaluateInUtility((injected, node) => { | ||
@@ -284,4 +289,10 @@ if (node.nodeType !== Node.ELEMENT_NODE || node.tagName !== 'INPUT') | ||
}); | ||
helper_1.assert(multiple || files.length <= 1, 'Non-multiple file input can only accept single file!'); | ||
const filePayloads = await Promise.all(files.map(async (item) => { | ||
let ff; | ||
if (!Array.isArray(files)) | ||
ff = [files]; | ||
else | ||
ff = files; | ||
helper_1.assert(multiple || ff.length <= 1, 'Non-multiple file input can only accept single file!'); | ||
const filePayloads = []; | ||
for (const item of ff) { | ||
if (typeof item === 'string') { | ||
@@ -293,6 +304,8 @@ const file = { | ||
}; | ||
return file; | ||
filePayloads.push(file); | ||
} | ||
return item; | ||
})); | ||
else { | ||
filePayloads.push(item); | ||
} | ||
} | ||
await this._page._frameManager.waitForNavigationsCreatedBy(async () => { | ||
@@ -316,3 +329,3 @@ await this._page._delegate.setInputFiles(this, filePayloads); | ||
await this._page.keyboard.type(text, options); | ||
}); | ||
}, options); | ||
} | ||
@@ -323,3 +336,3 @@ async press(key, options) { | ||
await this._page.keyboard.press(key, options); | ||
}); | ||
}, options); | ||
} | ||
@@ -396,13 +409,18 @@ async check(options) { | ||
exports.waitForFunctionTask = waitForFunctionTask; | ||
function waitForSelectorTask(selector, visibility, timeout) { | ||
return async (context) => context.evaluateHandle((injected, selector, visibility, timeout) => { | ||
const polling = visibility === 'any' ? 'mutation' : 'raf'; | ||
function waitForSelectorTask(selector, waitFor, timeout) { | ||
return async (context) => context.evaluateHandle((injected, selector, waitFor, timeout) => { | ||
const polling = (waitFor === 'attached' || waitFor === 'detached') ? 'mutation' : 'raf'; | ||
return injected.poll(polling, selector, timeout, (element) => { | ||
if (!element) | ||
return visibility === 'hidden'; | ||
if (visibility === 'any') | ||
return element; | ||
return injected.isVisible(element) === (visibility === 'visible') ? element : false; | ||
switch (waitFor) { | ||
case 'attached': | ||
return element || false; | ||
case 'detached': | ||
return !element; | ||
case 'visible': | ||
return element && injected.isVisible(element) ? element : false; | ||
case 'hidden': | ||
return !element || !injected.isVisible(element); | ||
} | ||
}); | ||
}, await context._injected(), selector, visibility, timeout); | ||
}, await context._injected(), selector, waitFor, timeout); | ||
} | ||
@@ -409,0 +427,0 @@ exports.waitForSelectorTask = waitForSelectorTask; |
@@ -18,12 +18,11 @@ /** | ||
import { Browser } from '../browser'; | ||
import { BrowserContext, BrowserContextOptions } from '../browserContext'; | ||
import { BrowserContext, BrowserContextBase, BrowserContextOptions } from '../browserContext'; | ||
import * as network from '../network'; | ||
import { Page } from '../page'; | ||
import * as platform from '../platform'; | ||
import { ConnectionTransport } from '../transport'; | ||
import * as types from '../types'; | ||
import { Page, PageBinding } from '../page'; | ||
import { FFConnection, FFSession } from './ffConnection'; | ||
import { FFPage } from './ffPage'; | ||
import * as platform from '../platform'; | ||
import { Protocol } from './protocol'; | ||
import { ConnectionTransport } from '../transport'; | ||
import { TimeoutSettings } from '../timeoutSettings'; | ||
export declare class FFBrowser extends platform.EventEmitter implements Browser { | ||
@@ -72,10 +71,6 @@ _connection: FFConnection; | ||
} | ||
export declare class FFBrowserContext extends platform.EventEmitter implements BrowserContext { | ||
export declare class FFBrowserContext extends BrowserContextBase { | ||
readonly _browser: FFBrowser; | ||
readonly _browserContextId: string | null; | ||
readonly _options: BrowserContextOptions; | ||
readonly _timeoutSettings: TimeoutSettings; | ||
private _closed; | ||
private readonly _evaluateOnNewDocumentSources; | ||
readonly _pageBindings: Map<string, PageBinding>; | ||
constructor(browser: FFBrowser, browserContextId: string | null, options: BrowserContextOptions); | ||
@@ -88,3 +83,3 @@ _initialize(): Promise<void>; | ||
newPage(): Promise<Page>; | ||
cookies(...urls: string[]): Promise<network.NetworkCookie[]>; | ||
cookies(urls?: string | string[]): Promise<network.NetworkCookie[]>; | ||
setCookies(cookies: network.SetNetworkCookieParam[]): Promise<void>; | ||
@@ -103,4 +98,3 @@ clearCookies(): Promise<void>; | ||
close(): Promise<void>; | ||
_browserClosed(): void; | ||
} | ||
export {}; |
@@ -25,8 +25,7 @@ "use strict"; | ||
const page_1 = require("../page"); | ||
const ffConnection_1 = require("./ffConnection"); | ||
const ffPage_1 = require("./ffPage"); | ||
const platform = require("../platform"); | ||
const transport_1 = require("../transport"); | ||
const timeoutSettings_1 = require("../timeoutSettings"); | ||
const ffConnection_1 = require("./ffConnection"); | ||
const ffNetworkManager_1 = require("./ffNetworkManager"); | ||
const ffPage_1 = require("./ffPage"); | ||
class FFBrowser extends platform.EventEmitter { | ||
@@ -231,11 +230,7 @@ constructor(connection) { | ||
} | ||
class FFBrowserContext extends platform.EventEmitter { | ||
class FFBrowserContext extends browserContext_1.BrowserContextBase { | ||
constructor(browser, browserContextId, options) { | ||
super(); | ||
this._closed = false; | ||
this._pageBindings = new Map(); | ||
super(options); | ||
this._browser = browser; | ||
this._browserContextId = browserContextId; | ||
this._timeoutSettings = new timeoutSettings_1.TimeoutSettings(); | ||
this._options = options; | ||
this._evaluateOnNewDocumentSources = []; | ||
@@ -286,3 +281,3 @@ } | ||
} | ||
async cookies(...urls) { | ||
async cookies(urls) { | ||
const { cookies } = await this._browser._connection.send('Browser.getCookies', { browserContextId: this._browserContextId || undefined }); | ||
@@ -353,13 +348,6 @@ return network.filterCookies(cookies.map(c => { | ||
this._browser._contexts.delete(this._browserContextId); | ||
this._closed = true; | ||
this.emit(events_1.Events.BrowserContext.Close); | ||
this._didCloseInternal(); | ||
} | ||
_browserClosed() { | ||
this._closed = true; | ||
for (const page of this._existingPages()) | ||
page._didClose(); | ||
this.emit(events_1.Events.BrowserContext.Close); | ||
} | ||
} | ||
exports.FFBrowserContext = FFBrowserContext; | ||
//# sourceMappingURL=ffBrowser.js.map |
@@ -17,12 +17,12 @@ /** | ||
*/ | ||
import * as dom from '../dom'; | ||
import * as frames from '../frames'; | ||
import * as dom from '../dom'; | ||
import { Page, PageBinding, PageDelegate } from '../page'; | ||
import * as platform from '../platform'; | ||
import * as types from '../types'; | ||
import { FFBrowserContext } from './ffBrowser'; | ||
import { FFSession } from './ffConnection'; | ||
import { Page, PageDelegate, PageBinding } from '../page'; | ||
import { RawKeyboardImpl, RawMouseImpl } from './ffInput'; | ||
import { FFNetworkManager } from './ffNetworkManager'; | ||
import { Protocol } from './protocol'; | ||
import { RawMouseImpl, RawKeyboardImpl } from './ffInput'; | ||
import { BrowserContext } from '../browserContext'; | ||
import * as types from '../types'; | ||
import * as platform from '../platform'; | ||
export declare class FFPage implements PageDelegate { | ||
@@ -38,3 +38,3 @@ readonly rawMouse: RawMouseImpl; | ||
private _workers; | ||
constructor(session: FFSession, browserContext: BrowserContext, openerResolver: () => Promise<Page | null>); | ||
constructor(session: FFSession, browserContext: FFBrowserContext, openerResolver: () => Promise<Page | null>); | ||
_initialize(): Promise<void>; | ||
@@ -103,2 +103,1 @@ _onExecutionContextCreated(payload: Protocol.Runtime.executionContextCreatedPayload): void; | ||
} | ||
export declare function normalizeWaitUntil(waitUntil: frames.LifecycleEvent | frames.LifecycleEvent[]): frames.LifecycleEvent[]; |
@@ -19,14 +19,14 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const dialog = require("../dialog"); | ||
const dom = require("../dom"); | ||
const events_1 = require("../events"); | ||
const helper_1 = require("../helper"); | ||
const dom = require("../dom"); | ||
const page_1 = require("../page"); | ||
const platform = require("../platform"); | ||
const screenshotter_1 = require("../screenshotter"); | ||
const ffAccessibility_1 = require("./ffAccessibility"); | ||
const ffConnection_1 = require("./ffConnection"); | ||
const ffExecutionContext_1 = require("./ffExecutionContext"); | ||
const page_1 = require("../page"); | ||
const ffInput_1 = require("./ffInput"); | ||
const ffNetworkManager_1 = require("./ffNetworkManager"); | ||
const events_1 = require("../events"); | ||
const dialog = require("../dialog"); | ||
const ffInput_1 = require("./ffInput"); | ||
const ffAccessibility_1 = require("./ffAccessibility"); | ||
const platform = require("../platform"); | ||
const screenshotter_1 = require("../screenshotter"); | ||
const UTILITY_WORLD_NAME = '__playwright_utility_world__'; | ||
@@ -390,12 +390,2 @@ class FFPage { | ||
exports.FFPage = FFPage; | ||
function normalizeWaitUntil(waitUntil) { | ||
if (!Array.isArray(waitUntil)) | ||
waitUntil = [waitUntil]; | ||
for (const condition of waitUntil) { | ||
if (condition !== 'load' && condition !== 'domcontentloaded') | ||
throw new Error('Unknown waitUntil condition: ' + condition); | ||
} | ||
return waitUntil; | ||
} | ||
exports.normalizeWaitUntil = normalizeWaitUntil; | ||
function toRemoteObject(handle) { | ||
@@ -402,0 +392,0 @@ return handle._remoteObject; |
@@ -25,10 +25,3 @@ /** | ||
declare type ContextType = 'main' | 'utility'; | ||
export declare type NavigateOptions = { | ||
timeout?: number; | ||
waitUntil?: LifecycleEvent | LifecycleEvent[]; | ||
}; | ||
export declare type WaitForNavigationOptions = NavigateOptions & { | ||
url?: types.URLMatch; | ||
}; | ||
export declare type GotoOptions = NavigateOptions & { | ||
export declare type GotoOptions = types.NavigateOptions & { | ||
referer?: string; | ||
@@ -39,3 +32,2 @@ }; | ||
}; | ||
export declare type LifecycleEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; | ||
declare type ConsoleTagHandler = () => void; | ||
@@ -54,3 +46,3 @@ export declare class FrameManager { | ||
frameAttached(frameId: string, parentFrameId: string | null | undefined): Frame; | ||
waitForNavigationsCreatedBy<T>(action: () => Promise<T>, options?: WaitForNavigationOptions): Promise<T>; | ||
waitForNavigationsCreatedBy<T>(action: () => Promise<T>, options?: types.WaitForNavigationOptions): Promise<T>; | ||
frameWillPotentiallyRequestNavigation(): void; | ||
@@ -63,3 +55,3 @@ frameDidPotentiallyRequestNavigation(): void; | ||
frameStoppedLoading(frameId: string): void; | ||
frameLifecycleEvent(frameId: string, event: LifecycleEvent): void; | ||
frameLifecycleEvent(frameId: string, event: types.LifecycleEvent): void; | ||
clearFrameLifecycle(frame: Frame): void; | ||
@@ -80,3 +72,3 @@ requestStarted(request: network.Request): void; | ||
_id: string; | ||
readonly _firedLifecycleEvents: Set<LifecycleEvent>; | ||
readonly _firedLifecycleEvents: Set<types.LifecycleEvent>; | ||
_lastDocumentId: string; | ||
@@ -94,3 +86,3 @@ _requestWatchers: Set<(request: network.Request) => void>; | ||
_inflightRequests: Set<network.Request>; | ||
readonly _networkIdleTimers: Map<LifecycleEvent, NodeJS.Timer>; | ||
readonly _networkIdleTimers: Map<types.LifecycleEvent, NodeJS.Timer>; | ||
private _setContentCounter; | ||
@@ -101,4 +93,4 @@ private _detachedPromise; | ||
goto(url: string, options?: GotoOptions): Promise<network.Response | null>; | ||
waitForNavigation(options?: WaitForNavigationOptions): Promise<network.Response | null>; | ||
waitForLoadState(options?: NavigateOptions): Promise<void>; | ||
waitForNavigation(options?: types.WaitForNavigationOptions): Promise<network.Response | null>; | ||
waitForLoadState(options?: types.NavigateOptions): Promise<void>; | ||
_waitForSpecificDocument(expectedDocumentId: string): Disposable<Promise<Error | void>>; | ||
@@ -110,3 +102,3 @@ _waitForNewDocument(url?: types.URLMatch): Disposable<Promise<{ | ||
_waitForSameDocumentNavigation(url?: types.URLMatch): Disposable<Promise<void>>; | ||
_waitForLifecycle(waitUntil?: LifecycleEvent | LifecycleEvent[]): Disposable<Promise<void>>; | ||
_waitForLifecycle(waitUntil?: types.LifecycleEvent): Disposable<Promise<void>>; | ||
_trackDocumentRequests(): Disposable<Map<string, network.Request>>; | ||
@@ -121,8 +113,3 @@ _createFrameDestroyedPromise(): Promise<Error>; | ||
$(selector: string): Promise<dom.ElementHandle<Element> | null>; | ||
waitForSelector(selector: string, options?: types.TimeoutOptions & { | ||
visibility?: types.Visibility; | ||
}): Promise<dom.ElementHandle<Element> | null>; | ||
$wait(selector: string, options?: types.TimeoutOptions & { | ||
visibility?: types.Visibility; | ||
}): Promise<dom.ElementHandle<Element> | null>; | ||
waitForElement(selector: string, options?: types.WaitForElementOptions): Promise<dom.ElementHandle<Element> | null>; | ||
$eval: types.$Eval; | ||
@@ -132,3 +119,3 @@ $$eval: types.$$Eval; | ||
content(): Promise<string>; | ||
setContent(html: string, options?: NavigateOptions): Promise<void>; | ||
setContent(html: string, options?: types.NavigateOptions): Promise<void>; | ||
name(): string; | ||
@@ -151,17 +138,15 @@ url(): string; | ||
private _raceWithCSPError; | ||
click(selector: string, options?: dom.ClickOptions & types.WaitForOptions): Promise<void>; | ||
dblclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions): Promise<void>; | ||
tripleclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions): Promise<void>; | ||
fill(selector: string, value: string, options?: types.WaitForOptions): Promise<void>; | ||
click(selector: string, options?: dom.ClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
dblclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
tripleclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
fill(selector: string, value: string, options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
focus(selector: string, options?: types.WaitForOptions): Promise<void>; | ||
hover(selector: string, options?: dom.PointerActionOptions & types.WaitForOptions): Promise<void>; | ||
select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions): Promise<string[]>; | ||
select(selector: string, values: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions & types.NavigateOptions): Promise<string[]>; | ||
type(selector: string, text: string, options?: { | ||
delay?: number; | ||
} & types.WaitForOptions): Promise<void>; | ||
check(selector: string, options?: types.WaitForOptions): Promise<void>; | ||
uncheck(selector: string, options?: types.WaitForOptions): Promise<void>; | ||
waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options?: types.WaitForFunctionOptions & { | ||
visibility?: types.Visibility; | ||
}, ...args: any[]): Promise<js.JSHandle | null>; | ||
} & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
check(selector: string, options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
uncheck(selector: string, options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options?: types.WaitForFunctionOptions & types.WaitForElementOptions, ...args: any[]): Promise<js.JSHandle | null>; | ||
private _optionallyWaitForSelectorInUtilityContext; | ||
@@ -168,0 +153,0 @@ private _waitForSelectorInUtilityContext; |
@@ -24,3 +24,3 @@ "use strict"; | ||
const platform = require("./platform"); | ||
const kLifecycleEvents = new Set(['load', 'domcontentloaded', 'networkidle0', 'networkidle2']); | ||
const kLifecycleEvents = new Set(['commit', 'load', 'domcontentloaded', 'networkidle0', 'networkidle2']); | ||
class FrameManager { | ||
@@ -136,2 +136,3 @@ constructor(page) { | ||
const hasLoad = frame._firedLifecycleEvents.has('load'); | ||
frame._firedLifecycleEvents.add('commit'); | ||
frame._firedLifecycleEvents.add('domcontentloaded'); | ||
@@ -160,2 +161,3 @@ frame._firedLifecycleEvents.add('load'); | ||
frame._firedLifecycleEvents.clear(); | ||
frame._firedLifecycleEvents.add('commit'); | ||
// Keep the current navigation request if any. | ||
@@ -446,7 +448,4 @@ frame._inflightRequests = new Set(Array.from(frame._inflightRequests).filter(request => request._documentId === frame._lastDocumentId)); | ||
let resolve; | ||
const expectedLifecycle = typeof waitUntil === 'string' ? [waitUntil] : waitUntil; | ||
for (const event of expectedLifecycle) { | ||
if (!kLifecycleEvents.has(event)) | ||
throw new Error(`Unsupported waitUntil option ${String(event)}`); | ||
} | ||
if (!kLifecycleEvents.has(waitUntil)) | ||
throw new Error(`Unsupported waitUntil option ${String(waitUntil)}`); | ||
const checkLifecycleComplete = () => { | ||
@@ -463,6 +462,4 @@ if (!checkLifecycleRecursively(this)) | ||
function checkLifecycleRecursively(frame) { | ||
for (const event of expectedLifecycle) { | ||
if (!frame._firedLifecycleEvents.has(event)) | ||
return false; | ||
} | ||
if (!frame._firedLifecycleEvents.has(waitUntil)) | ||
return false; | ||
for (const child of frame.childFrames()) { | ||
@@ -519,5 +516,6 @@ if (!checkLifecycleRecursively(child)) | ||
} | ||
async waitForSelector(selector, options) { | ||
const { timeout = this._page._timeoutSettings.timeout(), visibility = 'any' } = (options || {}); | ||
const handle = await this._waitForSelectorInUtilityContext(selector, visibility, timeout); | ||
async waitForElement(selector, options) { | ||
if (options && options.visibility) | ||
throw new Error('options.visibility is not supported, did you mean options.waitFor?'); | ||
const handle = await this._waitForSelectorInUtilityContext(selector, options); | ||
const mainContext = await this._mainContext(); | ||
@@ -531,5 +529,2 @@ if (handle && handle._context !== mainContext) { | ||
} | ||
async $wait(selector, options) { | ||
return this.waitForSelector(selector, options); | ||
} | ||
async $$(selector) { | ||
@@ -711,3 +706,3 @@ const context = await this._mainContext(); | ||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options); | ||
await handle.fill(value); | ||
await handle.fill(value, options); | ||
handle.dispose(); | ||
@@ -725,6 +720,5 @@ } | ||
} | ||
async select(selector, value, options) { | ||
async select(selector, values, options) { | ||
const handle = await this._optionallyWaitForSelectorInUtilityContext(selector, options); | ||
const values = Array.isArray(value) ? value : [value]; | ||
const result = await handle.select(...values); | ||
const result = await handle.select(values, options); | ||
handle.dispose(); | ||
@@ -750,3 +744,3 @@ return result; | ||
if (helper_1.helper.isString(selectorOrFunctionOrTimeout)) | ||
return this.waitForSelector(selectorOrFunctionOrTimeout, options); | ||
return this.waitForElement(selectorOrFunctionOrTimeout, options); | ||
if (helper_1.helper.isNumber(selectorOrFunctionOrTimeout)) | ||
@@ -764,5 +758,5 @@ return new Promise(fulfill => setTimeout(fulfill, selectorOrFunctionOrTimeout)); | ||
if (waitFor) { | ||
const maybeHandle = await this._waitForSelectorInUtilityContext(selector, 'any', timeout); | ||
const maybeHandle = await this._waitForSelectorInUtilityContext(selector, { timeout, waitFor: 'attached' }); | ||
if (!maybeHandle) | ||
throw new Error('No node found for selector: ' + selectorToString(selector, 'any')); | ||
throw new Error('No node found for selector: ' + selectorToString(selector, 'attached')); | ||
handle = maybeHandle; | ||
@@ -778,10 +772,8 @@ } | ||
} | ||
async _waitForSelectorInUtilityContext(selector, waitFor, timeout) { | ||
let visibility = 'any'; | ||
if (waitFor === 'visible' || waitFor === 'hidden' || waitFor === 'any') | ||
visibility = waitFor; | ||
else | ||
throw new Error(`Unsupported visibility option "${waitFor}"`); | ||
const task = dom.waitForSelectorTask(selector, visibility, timeout); | ||
const result = await this._scheduleRerunnableTask(task, 'utility', timeout, `selector "${selectorToString(selector, visibility)}"`); | ||
async _waitForSelectorInUtilityContext(selector, options) { | ||
const { timeout = this._page._timeoutSettings.timeout(), waitFor = 'attached' } = (options || {}); | ||
if (!['attached', 'detached', 'visible', 'hidden'].includes(waitFor)) | ||
throw new Error(`Unsupported waitFor option "${waitFor}"`); | ||
const task = dom.waitForSelectorTask(selector, waitFor, timeout); | ||
const result = await this._scheduleRerunnableTask(task, 'utility', timeout, `selector "${selectorToString(selector, waitFor)}"`); | ||
if (!result.asElement()) { | ||
@@ -947,5 +939,5 @@ result.dispose(); | ||
} | ||
function selectorToString(selector, visibility) { | ||
function selectorToString(selector, waitFor) { | ||
let label; | ||
switch (visibility) { | ||
switch (waitFor) { | ||
case 'visible': | ||
@@ -957,6 +949,8 @@ label = '[visible] '; | ||
break; | ||
case 'any': | ||
case undefined: | ||
case 'attached': | ||
label = ''; | ||
break; | ||
case 'detached': | ||
label = '[detached]'; | ||
break; | ||
} | ||
@@ -963,0 +957,0 @@ return `${label}${selector}`; |
@@ -40,3 +40,3 @@ /** | ||
}; | ||
export declare function filterCookies(cookies: NetworkCookie[], urls: string[]): NetworkCookie[]; | ||
export declare function filterCookies(cookies: NetworkCookie[], urls?: string | string[]): NetworkCookie[]; | ||
export declare function rewriteCookies(cookies: SetNetworkCookieParam[]): SetNetworkCookieParam[]; | ||
@@ -43,0 +43,0 @@ export declare type Headers = { |
@@ -19,3 +19,5 @@ "use strict"; | ||
const helper_1 = require("./helper"); | ||
function filterCookies(cookies, urls) { | ||
function filterCookies(cookies, urls = []) { | ||
if (!Array.isArray(urls)) | ||
urls = [urls]; | ||
const parsedURLs = urls.map(s => new URL(s)); | ||
@@ -22,0 +24,0 @@ // Chromiums's cookies are missing sameSite when it is 'None' |
@@ -25,3 +25,3 @@ /** | ||
import * as types from './types'; | ||
import { BrowserContext } from './browserContext'; | ||
import { BrowserContext, BrowserContextBase } from './browserContext'; | ||
import { ConsoleMessageLocation } from './console'; | ||
@@ -101,3 +101,3 @@ import * as accessibility from './accessibility'; | ||
readonly _disconnectedPromise: Promise<Error>; | ||
private _browserContext; | ||
readonly _browserContext: BrowserContextBase; | ||
readonly keyboard: input.Keyboard; | ||
@@ -120,3 +120,3 @@ readonly mouse: input.Mouse; | ||
_ownedContext: BrowserContext | undefined; | ||
constructor(delegate: PageDelegate, browserContext: BrowserContext); | ||
constructor(delegate: PageDelegate, browserContext: BrowserContextBase); | ||
_didClose(): void; | ||
@@ -137,8 +137,3 @@ _didCrash(): void; | ||
$(selector: string): Promise<dom.ElementHandle<Element> | null>; | ||
waitForSelector(selector: string, options?: types.TimeoutOptions & { | ||
visibility?: types.Visibility; | ||
}): Promise<dom.ElementHandle<Element> | null>; | ||
$wait(selector: string, options?: types.TimeoutOptions & { | ||
visibility?: types.Visibility; | ||
}): Promise<dom.ElementHandle<Element> | null>; | ||
waitForElement(selector: string, options?: types.WaitForElementOptions): Promise<dom.ElementHandle<Element> | null>; | ||
evaluateHandle: types.EvaluateHandle; | ||
@@ -165,7 +160,7 @@ $eval: types.$Eval; | ||
content(): Promise<string>; | ||
setContent(html: string, options?: frames.NavigateOptions): Promise<void>; | ||
setContent(html: string, options?: types.NavigateOptions): Promise<void>; | ||
goto(url: string, options?: frames.GotoOptions): Promise<network.Response | null>; | ||
reload(options?: frames.NavigateOptions): Promise<network.Response | null>; | ||
waitForNavigation(options?: frames.WaitForNavigationOptions): Promise<network.Response | null>; | ||
waitForLoadState(options?: frames.NavigateOptions): Promise<void>; | ||
reload(options?: types.NavigateOptions): Promise<network.Response | null>; | ||
waitForNavigation(options?: types.WaitForNavigationOptions): Promise<network.Response | null>; | ||
waitForLoadState(options?: types.NavigateOptions): Promise<void>; | ||
waitForEvent(event: string, optionsOrPredicate?: Function | (types.TimeoutOptions & { | ||
@@ -176,4 +171,4 @@ predicate?: Function; | ||
waitForResponse(urlOrPredicate: string | RegExp | ((r: network.Response) => boolean), options?: types.TimeoutOptions): Promise<network.Response>; | ||
goBack(options?: frames.NavigateOptions): Promise<network.Response | null>; | ||
goForward(options?: frames.NavigateOptions): Promise<network.Response | null>; | ||
goBack(options?: types.NavigateOptions): Promise<network.Response | null>; | ||
goForward(options?: types.NavigateOptions): Promise<network.Response | null>; | ||
emulateMedia(options: { | ||
@@ -199,17 +194,15 @@ media?: types.MediaType; | ||
isClosed(): boolean; | ||
click(selector: string, options?: dom.ClickOptions & types.WaitForOptions): Promise<void>; | ||
dblclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions): Promise<void>; | ||
tripleclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions): Promise<void>; | ||
fill(selector: string, value: string, options?: types.WaitForOptions): Promise<void>; | ||
click(selector: string, options?: dom.ClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
dblclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
tripleclick(selector: string, options?: dom.MultiClickOptions & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
fill(selector: string, value: string, options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
focus(selector: string, options?: types.WaitForOptions): Promise<void>; | ||
hover(selector: string, options?: dom.PointerActionOptions & types.WaitForOptions): Promise<void>; | ||
select(selector: string, value: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions): Promise<string[]>; | ||
select(selector: string, values: string | dom.ElementHandle | types.SelectOption | string[] | dom.ElementHandle[] | types.SelectOption[], options?: types.WaitForOptions & types.NavigateOptions): Promise<string[]>; | ||
type(selector: string, text: string, options?: { | ||
delay?: number; | ||
} & types.WaitForOptions): Promise<void>; | ||
check(selector: string, options?: types.WaitForOptions): Promise<void>; | ||
uncheck(selector: string, options?: types.WaitForOptions): Promise<void>; | ||
waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options?: types.WaitForFunctionOptions & { | ||
visibility?: types.Visibility; | ||
}, ...args: any[]): Promise<js.JSHandle | null>; | ||
} & types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
check(selector: string, options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
uncheck(selector: string, options?: types.WaitForOptions & types.NavigateOptions): Promise<void>; | ||
waitFor(selectorOrFunctionOrTimeout: (string | number | Function), options?: types.WaitForFunctionOptions & types.WaitForElementOptions, ...args: any[]): Promise<js.JSHandle | null>; | ||
waitForFunction(pageFunction: Function | string, options?: types.WaitForFunctionOptions, ...args: any[]): Promise<js.JSHandle>; | ||
@@ -216,0 +209,0 @@ workers(): Worker[]; |
@@ -153,8 +153,5 @@ "use strict"; | ||
} | ||
async waitForSelector(selector, options) { | ||
return this.mainFrame().waitForSelector(selector, options); | ||
async waitForElement(selector, options) { | ||
return this.mainFrame().waitForElement(selector, options); | ||
} | ||
async $wait(selector, options) { | ||
return this.mainFrame().$wait(selector, options); | ||
} | ||
async $$(selector) { | ||
@@ -336,4 +333,4 @@ return this.mainFrame().$$(selector); | ||
} | ||
async select(selector, value, options) { | ||
return this.mainFrame().select(selector, value, options); | ||
async select(selector, values, options) { | ||
return this.mainFrame().select(selector, values, options); | ||
} | ||
@@ -426,3 +423,3 @@ async type(selector, text, options) { | ||
if (!binding) | ||
binding = page.context()._pageBindings.get(name); | ||
binding = page._browserContext._pageBindings.get(name); | ||
const result = await binding.playwrightFunction(...args); | ||
@@ -429,0 +426,0 @@ expression = helper_1.helper.evaluationString(deliverResult, name, seq, result); |
@@ -49,3 +49,5 @@ /** | ||
}; | ||
export declare type Visibility = 'visible' | 'hidden' | 'any'; | ||
export declare type WaitForElementOptions = TimeoutOptions & { | ||
waitFor?: 'attached' | 'detached' | 'visible' | 'hidden'; | ||
}; | ||
export declare type Polling = 'raf' | 'mutation' | number; | ||
@@ -55,2 +57,9 @@ export declare type WaitForFunctionOptions = TimeoutOptions & { | ||
}; | ||
export declare type LifecycleEvent = 'commit' | 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2'; | ||
export declare type NavigateOptions = TimeoutOptions & { | ||
waitUntil?: LifecycleEvent; | ||
}; | ||
export declare type WaitForNavigationOptions = NavigateOptions & { | ||
url?: URLMatch; | ||
}; | ||
export declare type ElementScreenshotOptions = { | ||
@@ -57,0 +66,0 @@ type?: 'png' | 'jpeg'; |
@@ -18,12 +18,11 @@ /** | ||
import { Browser } from '../browser'; | ||
import { BrowserContext, BrowserContextOptions } from '../browserContext'; | ||
import { BrowserContext, BrowserContextBase, BrowserContextOptions } from '../browserContext'; | ||
import * as network from '../network'; | ||
import { Page, PageBinding } from '../page'; | ||
import { Page } from '../page'; | ||
import * as platform from '../platform'; | ||
import { ConnectionTransport } from '../transport'; | ||
import * as types from '../types'; | ||
import { Protocol } from './protocol'; | ||
import { WKSession, PageProxyMessageReceivedPayload } from './wkConnection'; | ||
import { PageProxyMessageReceivedPayload, WKSession } from './wkConnection'; | ||
import { WKPageProxy } from './wkPageProxy'; | ||
import * as platform from '../platform'; | ||
import { TimeoutSettings } from '../timeoutSettings'; | ||
export declare class WKBrowser extends platform.EventEmitter implements Browser { | ||
@@ -54,18 +53,12 @@ private readonly _connection; | ||
} | ||
export declare class WKBrowserContext extends platform.EventEmitter implements BrowserContext { | ||
export declare class WKBrowserContext extends BrowserContextBase { | ||
readonly _browser: WKBrowser; | ||
readonly _browserContextId: string | undefined; | ||
readonly _options: BrowserContextOptions; | ||
readonly _timeoutSettings: TimeoutSettings; | ||
private _closed; | ||
readonly _evaluateOnNewDocumentSources: string[]; | ||
readonly _pageBindings: Map<string, PageBinding>; | ||
constructor(browser: WKBrowser, browserContextId: string | undefined, options: BrowserContextOptions); | ||
_initialize(): Promise<void>; | ||
_existingPages(): Page[]; | ||
setDefaultNavigationTimeout(timeout: number): void; | ||
setDefaultTimeout(timeout: number): void; | ||
pages(): Promise<Page[]>; | ||
newPage(): Promise<Page>; | ||
cookies(...urls: string[]): Promise<network.NetworkCookie[]>; | ||
cookies(urls?: string | string[]): Promise<network.NetworkCookie[]>; | ||
setCookies(cookies: network.SetNetworkCookieParam[]): Promise<void>; | ||
@@ -84,3 +77,2 @@ clearCookies(): Promise<void>; | ||
close(): Promise<void>; | ||
_browserClosed(): void; | ||
} |
@@ -21,11 +21,10 @@ "use strict"; | ||
const browserContext_1 = require("../browserContext"); | ||
const events_1 = require("../events"); | ||
const helper_1 = require("../helper"); | ||
const network = require("../network"); | ||
const page_1 = require("../page"); | ||
const platform = require("../platform"); | ||
const transport_1 = require("../transport"); | ||
const events_1 = require("../events"); | ||
const wkConnection_1 = require("./wkConnection"); | ||
const wkPageProxy_1 = require("./wkPageProxy"); | ||
const platform = require("../platform"); | ||
const timeoutSettings_1 = require("../timeoutSettings"); | ||
const DEFAULT_USER_AGENT = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.4 Safari/605.1.15'; | ||
@@ -150,11 +149,7 @@ class WKBrowser extends platform.EventEmitter { | ||
exports.WKBrowser = WKBrowser; | ||
class WKBrowserContext extends platform.EventEmitter { | ||
class WKBrowserContext extends browserContext_1.BrowserContextBase { | ||
constructor(browser, browserContextId, options) { | ||
super(); | ||
this._closed = false; | ||
this._pageBindings = new Map(); | ||
super(options); | ||
this._browser = browser; | ||
this._browserContextId = browserContextId; | ||
this._timeoutSettings = new timeoutSettings_1.TimeoutSettings(); | ||
this._options = options; | ||
this._evaluateOnNewDocumentSources = []; | ||
@@ -185,8 +180,2 @@ } | ||
} | ||
setDefaultNavigationTimeout(timeout) { | ||
this._timeoutSettings.setDefaultNavigationTimeout(timeout); | ||
} | ||
setDefaultTimeout(timeout) { | ||
this._timeoutSettings.setDefaultTimeout(timeout); | ||
} | ||
async pages() { | ||
@@ -209,3 +198,3 @@ const pageProxies = Array.from(this._browser._pageProxies.values()).filter(proxy => proxy._browserContext === this); | ||
} | ||
async cookies(...urls) { | ||
async cookies(urls) { | ||
const { cookies } = await this._browser._browserSession.send('Browser.getAllCookies', { browserContextId: this._browserContextId }); | ||
@@ -280,13 +269,6 @@ return network.filterCookies(cookies.map((c) => ({ | ||
this._browser._contexts.delete(this._browserContextId); | ||
this._closed = true; | ||
this.emit(events_1.Events.BrowserContext.Close); | ||
this._didCloseInternal(); | ||
} | ||
_browserClosed() { | ||
this._closed = true; | ||
for (const page of this._existingPages()) | ||
page._didClose(); | ||
this.emit(events_1.Events.BrowserContext.Close); | ||
} | ||
} | ||
exports.WKBrowserContext = WKBrowserContext; | ||
//# sourceMappingURL=wkBrowser.js.map |
@@ -57,3 +57,3 @@ "use strict"; | ||
]; | ||
const contextOptions = this._page.context()._options; | ||
const contextOptions = this._browserContext._options; | ||
if (contextOptions.javaScriptEnabled === false) | ||
@@ -108,3 +108,3 @@ promises.push(this._pageProxySession.send('Emulation.setJavaScriptEnabled', { enabled: false })); | ||
promises.push(session.send('Network.setInterceptionEnabled', { enabled: true, interceptRequests: true })); | ||
const contextOptions = this._page.context()._options; | ||
const contextOptions = this._browserContext._options; | ||
if (contextOptions.userAgent) | ||
@@ -333,6 +333,6 @@ promises.push(session.send('Page.overrideUserAgent', { value: contextOptions.userAgent })); | ||
const headers = network.mergeHeaders([ | ||
this._page.context()._options.extraHTTPHeaders, | ||
this._browserContext._options.extraHTTPHeaders, | ||
this._page._state.extraHTTPHeaders | ||
]); | ||
const locale = this._page.context()._options.locale; | ||
const locale = this._browserContext._options.locale; | ||
if (locale) | ||
@@ -350,3 +350,3 @@ headers['Accept-Language'] = locale; | ||
async _updateViewport(updateTouch) { | ||
let viewport = this._page.context()._options.viewport || { width: 0, height: 0 }; | ||
let viewport = this._browserContext._options.viewport || { width: 0, height: 0 }; | ||
const viewportSize = this._page._state.viewportSize; | ||
@@ -371,3 +371,3 @@ if (viewportSize) | ||
async updateOffline() { | ||
await this._updateState('Network.setEmulateOfflineState', { offline: !!this._page.context()._options.offline }); | ||
await this._updateState('Network.setEmulateOfflineState', { offline: !!this._browserContext._options.offline }); | ||
} | ||
@@ -374,0 +374,0 @@ async authenticate(credentials) { |
{ | ||
"name": "playwright-core", | ||
"version": "0.11.1-next.1583455961750", | ||
"version": "0.11.1-next.1583512728058", | ||
"description": "A high-level API to automate web browsers", | ||
@@ -5,0 +5,0 @@ "repository": "github:Microsoft/playwright", |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2447917
57473