Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: remove unused methods from server side (#3502)
Dmitry Gozman141a255a07f3
diff --git a/src/browser.ts b/src/browser.tsindex 8df824eb44..1e28152b90 100644--- a/src/browser.ts+++ b/src/browser.ts@@ -65,7 +65,6 @@ export abstract class BrowserBase extends EventEmitter implements Browser {abstract newContext(options?: BrowserContextOptions): Promise<BrowserContext>;abstract contexts(): BrowserContext[];abstract isConnected(): boolean;- abstract _disconnect(): void;abstract version(): string;async newPage(options?: BrowserContextOptions): Promise<Page> {diff --git a/src/browserContext.ts b/src/browserContext.tsindex 3faba57a14..577ebdaede 100644--- a/src/browserContext.ts+++ b/src/browserContext.ts@@ -25,7 +25,7 @@ import { Events } from './events';import { Download } from './download';import { BrowserBase } from './browser';import { EventEmitter } from 'events';-import { ProgressController } from './progress';+import { Progress } from './progress';import { DebugController } from './debug/debugController';export interface BrowserContext extends EventEmitter {@@ -44,10 +44,8 @@ export interface BrowserContext extends EventEmitter {setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void>;addInitScript(script: Function | string | { path?: string, content?: string }, arg?: any): Promise<void>;exposeBinding(name: string, playwrightBinding: frames.FunctionWithSource): Promise<void>;- exposeFunction(name: string, playwrightFunction: Function): Promise<void>;route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>;unroute(url: types.URLMatch, handler?: network.RouteHandler): Promise<void>;- waitForEvent(event: string, optionsOrPredicate?: Function | (types.TimeoutOptions & { predicate?: Function })): Promise<any>;close(): Promise<void>;}@@ -77,14 +75,6 @@ export abstract class BrowserContextBase extends EventEmitter implements Browsernew DebugController(this);}- async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {- const options = typeof optionsOrPredicate === 'function' ? { predicate: optionsOrPredicate } : optionsOrPredicate;- const progressController = new ProgressController(this._timeoutSettings.timeout(options));- if (event !== Events.BrowserContext.Close)- this._closePromise.then(error => progressController.abort(error));- return progressController.run(progress => helper.waitForEvent(progress, this, event, options.predicate).promise);- }-_browserClosed() {for (const page of this.pages())page._didClose();@@ -127,10 +117,6 @@ export abstract class BrowserContextBase extends EventEmitter implements Browserreturn await this._doCookies(urls as string[]);}- async exposeFunction(name: string, playwrightFunction: Function): Promise<void> {- await this.exposeBinding(name, (options, ...args: any) => playwrightFunction(...args));- }-setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void> {if (!isUnderTest())deprecate(`context.setHTTPCredentials`, `warning: method |context.setHTTPCredentials()| is deprecated. Instead of changing credentials, create another browser context with new credentials.`);@@ -180,9 +166,12 @@ export abstract class BrowserContextBase extends EventEmitter implements Browserthis._timeoutSettings.setDefaultTimeout(timeout);}- async _loadDefaultContext() {- if (!this.pages().length)- await this.waitForEvent('page');+ async _loadDefaultContext(progress: Progress) {+ if (!this.pages().length) {+ const waitForEvent = helper.waitForEvent(progress, this, Events.BrowserContext.Page);+ progress.cleanupWhenAborted(() => waitForEvent.dispose);+ await waitForEvent.promise;+ }const pages = this.pages();await pages[0].mainFrame().waitForLoadState();if (pages.length !== 1 || pages[0].mainFrame().url() !== 'about:blank')diff --git a/src/chromium/crBrowser.ts b/src/chromium/crBrowser.tsindex ba9a17e2e0..7e7178a6dc 100644--- a/src/chromium/crBrowser.ts+++ b/src/chromium/crBrowser.ts@@ -211,10 +211,6 @@ export class CRBrowser extends BrowserBase {await this._session.send('Target.closeTarget', { targetId: crPage._targetId });}- _disconnect() {- this._connection.close();- }-async newBrowserCDPSession(): Promise<CRSession> {return await this._connection.createBrowserSession();}diff --git a/src/chromium/crPage.ts b/src/chromium/crPage.tsindex a30f3c1923..28c447f05a 100644--- a/src/chromium/crPage.ts+++ b/src/chromium/crPage.ts@@ -119,7 +119,7 @@ export class CRPage implements PageDelegate {async exposeBinding(binding: PageBinding) {await this._forAllFrameSessions(frame => frame._initBinding(binding));- await Promise.all(this._page.frames().map(frame => frame.evaluate(binding.source).catch(e => {})));+ await Promise.all(this._page.frames().map(frame => frame._evaluateExpression(binding.source, false, {}).catch(e => {})));}async updateExtraHTTPHeaders(): Promise<void> {@@ -394,7 +394,7 @@ class FrameSession {worldName: UTILITY_WORLD_NAME,});for (const binding of this._crPage._browserContext._pageBindings.values())- frame.evaluate(binding.source).catch(e => {});+ frame._evaluateExpression(binding.source, false, {}).catch(e => {});}const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ':';if (isInitialEmptyPage) {diff --git a/src/console.ts b/src/console.tsindex d60a2908e4..08b8367df9 100644--- a/src/console.ts+++ b/src/console.ts@@ -15,7 +15,6 @@*/import * as js from './javascript';-import * as util from 'util';import { ConsoleMessageLocation } from './types';export class ConsoleMessage {@@ -48,8 +47,4 @@ export class ConsoleMessage {location(): ConsoleMessageLocation {return this._location;}-- [util.inspect.custom]() {- return this.text();- }}diff --git a/src/dom.ts b/src/dom.tsindex 903dd358a7..cabaaf5212 100644--- a/src/dom.ts+++ b/src/dom.ts@@ -15,7 +15,7 @@*/import * as frames from './frames';-import { assert, helper, assertMaxArguments } from './helper';+import { assert, helper } from './helper';import InjectedScript from './injected/injectedScript';import * as injectedScriptSource from './generated/injectedScriptSource';import * as debugScriptSource from './generated/debugScriptSource';@@ -607,13 +607,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return selectors._queryAll(this._context.frame, selector, this);}- async $eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element, Arg, R>, arg: Arg): Promise<R>;- async $eval<R>(selector: string, pageFunction: js.FuncOn<Element, void, R>, arg?: any): Promise<R>;- async $eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element, Arg, R>, arg: Arg): Promise<R> {- assertMaxArguments(arguments.length, 3);- return this._$evalExpression(selector, String(pageFunction), typeof pageFunction === 'function', arg);- }-async _$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {const handle = await selectors._query(this._context.frame, selector, this);if (!handle)@@ -623,13 +616,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return result;}- async $$eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element[], Arg, R>, arg: Arg): Promise<R>;- async $$eval<R>(selector: string, pageFunction: js.FuncOn<Element[], void, R>, arg?: any): Promise<R>;- async $$eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element[], Arg, R>, arg: Arg): Promise<R> {- assertMaxArguments(arguments.length, 3);- return this._$$evalExpression(selector, String(pageFunction), typeof pageFunction === 'function', arg);- }-async _$$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {const arrayHandle = await selectors._queryArray(this._context.frame, selector, this);const result = await arrayHandle._evaluateExpression(expression, isFunction, true, arg);diff --git a/src/fileChooser.ts b/src/fileChooser.tsindex 6ab8617f9f..c5fe59beaf 100644--- a/src/fileChooser.ts+++ b/src/fileChooser.ts@@ -16,7 +16,6 @@import { ElementHandle } from './dom';import { Page } from './page';-import * as types from './types';export class FileChooser {private _page: Page;@@ -40,8 +39,4 @@ export class FileChooser {page(): Page {return this._page;}-- async setFiles(files: string | types.FilePayload | string[] | types.FilePayload[], options?: types.NavigatingActionWaitOptions) {- return this._elementHandle.setInputFiles(files, options);- }}diff --git a/src/firefox/ffBrowser.ts b/src/firefox/ffBrowser.tsindex 5452dcb120..ceb5e34d43 100644--- a/src/firefox/ffBrowser.ts+++ b/src/firefox/ffBrowser.ts@@ -162,11 +162,6 @@ export class FFBrowser extends BrowserBase {const error = payload.canceled ? 'canceled' : payload.error;this._downloadFinished(payload.uuid, error);}-- _disconnect() {- helper.removeEventListeners(this._eventListeners);- this._connection.close();- }}export class FFBrowserContext extends BrowserContextBase {diff --git a/src/frames.ts b/src/frames.tsindex a4d2b0005c..fdfdce4d8d 100644--- a/src/frames.ts+++ b/src/frames.ts@@ -20,7 +20,7 @@ import * as util from 'util';import { ConsoleMessage } from './console';import * as dom from './dom';import { Events } from './events';-import { assert, helper, RegisteredListener, assertMaxArguments, debugLogger } from './helper';+import { assert, helper, RegisteredListener, debugLogger } from './helper';import * as js from './javascript';import * as network from './network';import { Page } from './page';@@ -374,10 +374,6 @@ export class Frame {this._parentFrame._childFrames.add(this);}- page(): Page {- return this._page;- }-_onLifecycleEvent(event: types.LifecycleEvent) {if (this._firedLifecycleEvents.has(event))return;@@ -524,27 +520,11 @@ export class Frame {return this._context('utility');}- async evaluateHandle<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<js.SmartHandle<R>>;- async evaluateHandle<R>(pageFunction: js.Func1<void, R>, arg?: any): Promise<js.SmartHandle<R>>;- async evaluateHandle<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<js.SmartHandle<R>> {- assertMaxArguments(arguments.length, 2);- const context = await this._mainContext();- return context.evaluateHandleInternal(pageFunction, arg);- }-async _evaluateExpressionHandle(expression: string, isFunction: boolean, arg: any): Promise<any> {const context = await this._mainContext();return context.evaluateExpressionHandleInternal(expression, isFunction, arg);}- async evaluate<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<R>;- async evaluate<R>(pageFunction: js.Func1<void, R>, arg?: any): Promise<R>;- async evaluate<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<R> {- assertMaxArguments(arguments.length, 2);- const context = await this._mainContext();- return context.evaluateInternal(pageFunction, arg);- }-async _evaluateExpression(expression: string, isFunction: boolean, arg: any): Promise<any> {const context = await this._mainContext();return context.evaluateExpressionInternal(expression, isFunction, arg);@@ -586,13 +566,6 @@ export class Frame {}, this._page._timeoutSettings.timeout(options));}- async $eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element, Arg, R>, arg: Arg): Promise<R>;- async $eval<R>(selector: string, pageFunction: js.FuncOn<Element, void, R>, arg?: any): Promise<R>;- async $eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element, Arg, R>, arg: Arg): Promise<R> {- assertMaxArguments(arguments.length, 3);- return this._$evalExpression(selector, String(pageFunction), typeof pageFunction === 'function', arg);- }-async _$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {const handle = await this.$(selector);if (!handle)@@ -602,13 +575,6 @@ export class Frame {return result;}- async $$eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element[], Arg, R>, arg: Arg): Promise<R>;- async $$eval<R>(selector: string, pageFunction: js.FuncOn<Element[], void, R>, arg?: any): Promise<R>;- async $$eval<R, Arg>(selector: string, pageFunction: js.FuncOn<Element[], Arg, R>, arg: Arg): Promise<R> {- assertMaxArguments(arguments.length, 3);- return this._$$evalExpression(selector, String(pageFunction), typeof pageFunction === 'function', arg);- }-async _$$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {const arrayHandle = await selectors._queryArray(this, selector);const result = await arrayHandle._evaluateExpression(expression, isFunction, true, arg);@@ -672,10 +638,6 @@ export class Frame {return Array.from(this._childFrames);}- isDetached(): boolean {- return this._detached;- }-async addScriptTag(options: {url?: string; path?: string;content?: string;@@ -924,16 +886,6 @@ export class Frame {await this._retryWithSelectorIfNotConnected(selector, options, (progress, handle) => handle._setChecked(progress, false, options));}- async waitForTimeout(timeout: number) {- await new Promise(fulfill => setTimeout(fulfill, timeout));- }-- async waitForFunction<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg, options?: types.WaitForFunctionOptions): Promise<js.SmartHandle<R>>;- async waitForFunction<R>(pageFunction: js.Func1<void, R>, arg?: any, options?: types.WaitForFunctionOptions): Promise<js.SmartHandle<R>>;- async waitForFunction<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg, options: types.WaitForFunctionOptions = {}): Promise<js.SmartHandle<R>> {- return this._waitForFunctionExpression(String(pageFunction), typeof pageFunction === 'function', arg, options);- }-async _waitForFunctionExpression<R>(expression: string, isFunction: boolean, arg: any, options: types.WaitForFunctionOptions = {}): Promise<js.SmartHandle<R>> {const { polling = 'raf' } = options;if (helper.isString(polling))diff --git a/src/helper.ts b/src/helper.tsindex 05a1a0024f..9f5a169912 100644--- a/src/helper.ts+++ b/src/helper.ts@@ -185,15 +185,6 @@ class Helper {return urlString;}- static trimMiddle(string: string, maxLength: number) {- if (string.length <= maxLength)- return string;-- const leftHalf = maxLength >> 1;- const rightHalf = maxLength - leftHalf - 1;- return string.substr(0, leftHalf) + '\u2026' + string.substr(this.length - rightHalf, rightHalf);- }-static enclosingIntRect(rect: types.Rect): types.Rect {const x = Math.floor(rect.x + 1e-3);const y = Math.floor(rect.y + 1e-3);@@ -363,10 +354,6 @@ export function debugAssert(value: any, message?: string): asserts value {throw new Error(message);}-export function assertMaxArguments(count: number, max: number): asserts count {- assert(count <= max, 'Too many arguments. If you need to pass more than 1 argument to the function wrap them in an object.');-}-export function getFromENV(name: string) {let value = process.env[name];value = value || process.env[`npm_config_${name.toLowerCase()}`];diff --git a/src/network.ts b/src/network.tsindex a60b4506db..d5cea20ada 100644--- a/src/network.ts+++ b/src/network.ts@@ -17,7 +17,6 @@import * as frames from './frames';import * as types from './types';import { assert, helper } from './helper';-import { URLSearchParams } from 'url';import { normalizeFulfillParameters, normalizeContinueOverrides } from './converters';export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): types.NetworkCookie[] {@@ -120,34 +119,10 @@ export class Request {return this._method;}- postData(): string | null {- return this._postData ? this._postData.toString('utf8') : null;- }-postDataBuffer(): Buffer | null {return this._postData;}- postDataJSON(): Object | null {- const postData = this.postData();- if (!postData)- return null;-- const contentType = this.headers()['content-type'];- if (!contentType)- return null;-- if (contentType === 'application/x-www-form-urlencoded') {- const entries: Record<string, string> = {};- const parsed = new URLSearchParams(postData);- for (const [k, v] of parsed.entries())- entries[k] = v;- return entries;- }-- return JSON.parse(postData);- }-headers(): {[key: string]: string} {return { ...this._headers };}@@ -181,10 +156,6 @@ export class Request {return this._redirectedFrom;}- redirectedTo(): Request | null {- return this._redirectedTo;- }-failure(): { errorText: string } | null {if (this._failureText === null)return null;@@ -268,10 +239,6 @@ export class Response {return this._url;}- ok(): boolean {- return this._status === 0 || (this._status >= 200 && this._status <= 299);- }-status(): number {return this._status;}@@ -299,16 +266,6 @@ export class Response {return this._contentPromise;}- async text(): Promise<string> {- const content = await this.body();- return content.toString('utf8');- }-- async json(): Promise<object> {- const content = await this.text();- return JSON.parse(content);- }-request(): Request {return this._request;}diff --git a/src/page.ts b/src/page.tsindex 572666a994..4e8c7d7baf 100644--- a/src/page.ts+++ b/src/page.ts@@ -17,7 +17,7 @@import * as dom from './dom';import * as frames from './frames';-import { assert, helper, Listener, assertMaxArguments, debugLogger } from './helper';+import { assert, helper, Listener, debugLogger } from './helper';import * as input from './input';import * as js from './javascript';import * as network from './network';@@ -30,7 +30,7 @@ import { ConsoleMessage } from './console';import * as accessibility from './accessibility';import { EventEmitter } from 'events';import { FileChooser } from './fileChooser';-import { ProgressController, Progress, runAbortableTask } from './progress';+import { Progress, runAbortableTask } from './progress';export interface PageDelegate {readonly rawMouse: input.RawMouse;@@ -192,17 +192,6 @@ export class Page extends EventEmitter {return this._frameManager.mainFrame();}- frame(options: string | { name?: string, url?: types.URLMatch }): frames.Frame | null {- const name = helper.isString(options) ? options : options.name;- const url = helper.isObject(options) ? options.url : undefined;- assert(name || url, 'Either name or url matcher should be specified');- return this.frames().find(f => {- if (name)- return f.name() === name;- return helper.urlMatches(f.url(), url);- }) || null;- }-frames(): frames.Frame[] {return this._frameManager.frames();}@@ -215,10 +204,6 @@ export class Page extends EventEmitter {this._timeoutSettings.setDefaultTimeout(timeout);}- async exposeFunction(name: string, playwrightFunction: Function) {- await this.exposeBinding(name, (options, ...args: any) => playwrightFunction(...args));- }-async exposeBinding(name: string, playwrightBinding: frames.FunctionWithSource) {if (this._pageBindings.has(name))throw new Error(`Function "${name}" has been already registered`);@@ -255,33 +240,6 @@ export class Page extends EventEmitter {return waitPromise;}- async waitForRequest(urlOrPredicate: string | RegExp | ((r: network.Request) => boolean), options: types.TimeoutOptions = {}): Promise<network.Request> {- const predicate = (request: network.Request) => {- if (helper.isString(urlOrPredicate) || helper.isRegExp(urlOrPredicate))- return helper.urlMatches(request.url(), urlOrPredicate);- return urlOrPredicate(request);- };- return this.waitForEvent(Events.Page.Request, { predicate, timeout: options.timeout });- }-- async waitForResponse(urlOrPredicate: string | RegExp | ((r: network.Response) => boolean), options: types.TimeoutOptions = {}): Promise<network.Response> {- const predicate = (response: network.Response) => {- if (helper.isString(urlOrPredicate) || helper.isRegExp(urlOrPredicate))- return helper.urlMatches(response.url(), urlOrPredicate);- return urlOrPredicate(response);- };- return this.waitForEvent(Events.Page.Response, { predicate, timeout: options.timeout });- }-- async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {- const options = typeof optionsOrPredicate === 'function' ? { predicate: optionsOrPredicate } : optionsOrPredicate;- const progressController = new ProgressController(this._timeoutSettings.timeout(options));- this._disconnectedPromise.then(error => progressController.abort(error));- if (event !== Events.Page.Crash)- this._crashedPromise.then(error => progressController.abort(error));- return progressController.run(progress => helper.waitForEvent(progress, this, event, options.predicate).promise);- }-async goBack(options?: types.NavigateOptions): Promise<network.Response | null> {const waitPromise = this.mainFrame().waitForNavigation(options);const result = await this._delegate.goBack();@@ -327,11 +285,6 @@ export class Page extends EventEmitter {await this._delegate.bringToFront();}- async addInitScript(script: Function | string | { path?: string, content?: string }, arg?: any) {- const source = await helper.evaluationScript(script, arg);- await this._addInitScriptExpression(source);- }-async _addInitScriptExpression(source: string) {this._evaluateOnNewDocumentSources.push(source);await this._delegate.evaluateOnNewDocument(source);@@ -413,14 +366,6 @@ export class Page extends EventEmitter {return this._closedState === 'closed';}- async waitForTimeout(timeout: number) {- await this.mainFrame().waitForTimeout(timeout);- }-- workers(): Worker[] {- return [...this._workers.values()];- }-_addWorker(workerId: string, worker: Worker) {this._workers.set(workerId, worker);this.emit(Events.Page.Worker, worker);@@ -480,24 +425,10 @@ export class Worker extends EventEmitter {return this._url;}- async evaluate<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<R>;- async evaluate<R>(pageFunction: js.Func1<void, R>, arg?: any): Promise<R>;- async evaluate<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<R> {- assertMaxArguments(arguments.length, 2);- return js.evaluate(await this._executionContextPromise, true /* returnByValue */, pageFunction, arg);- }-async _evaluateExpression(expression: string, isFunction: boolean, arg: any): Promise<any> {return js.evaluateExpression(await this._executionContextPromise, true /* returnByValue */, expression, isFunction, arg);}- async evaluateHandle<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<js.SmartHandle<R>>;- async evaluateHandle<R>(pageFunction: js.Func1<void, R>, arg?: any): Promise<js.SmartHandle<R>>;- async evaluateHandle<R, Arg>(pageFunction: js.Func1<Arg, R>, arg: Arg): Promise<js.SmartHandle<R>> {- assertMaxArguments(arguments.length, 2);- return js.evaluate(await this._executionContextPromise, false /* returnByValue */, pageFunction, arg);- }-async _evaluateExpressionHandle(expression: string, isFunction: boolean, arg: any): Promise<any> {return js.evaluateExpression(await this._executionContextPromise, false /* returnByValue */, expression, isFunction, arg);}diff --git a/src/rpc/client/consoleMessage.ts b/src/rpc/client/consoleMessage.tsindex 31071b9af2..17909cdde6 100644--- a/src/rpc/client/consoleMessage.ts+++ b/src/rpc/client/consoleMessage.ts@@ -19,8 +19,7 @@ import { JSHandle } from './jsHandle';import { ConsoleMessageChannel, ConsoleMessageInitializer } from '../channels';import { ChannelOwner } from './channelOwner';-let __dummyInitializer: ConsoleMessageInitializer;-type ConsoleMessageLocation = typeof __dummyInitializer.location;+type ConsoleMessageLocation = ConsoleMessageInitializer['location'];export class ConsoleMessage extends ChannelOwner<ConsoleMessageChannel, ConsoleMessageInitializer> {static from(message: ConsoleMessageChannel): ConsoleMessage {diff --git a/src/rpc/client/frame.ts b/src/rpc/client/frame.tsindex d1a00b5845..dcaf97dbf2 100644--- a/src/rpc/client/frame.ts+++ b/src/rpc/client/frame.ts@@ -15,12 +15,12 @@* limitations under the License.*/-import { assertMaxArguments, helper, assert } from '../../helper';+import { helper, assert } from '../../helper';import { FrameChannel, FrameInitializer, FrameNavigatedEvent, FrameGotoOptions, FrameWaitForSelectorOptions, FrameDispatchEventOptions, FrameSetContentOptions, FrameClickOptions, FrameDblclickOptions, FrameFillOptions, FrameFocusOptions, FrameTextContentOptions, FrameInnerTextOptions, FrameInnerHTMLOptions, FrameGetAttributeOptions, FrameHoverOptions, FrameSetInputFilesOptions, FrameTypeOptions, FramePressOptions, FrameCheckOptions, FrameUncheckOptions } from '../channels';import { BrowserContext } from './browserContext';import { ChannelOwner } from './channelOwner';import { ElementHandle, convertSelectOptionValues, convertInputFiles } from './elementHandle';-import { JSHandle, Func1, FuncOn, SmartHandle, serializeArgument, parseResult } from './jsHandle';+import { assertMaxArguments, JSHandle, Func1, FuncOn, SmartHandle, serializeArgument, parseResult } from './jsHandle';import * as fs from 'fs';import * as network from './network';import * as util from 'util';diff --git a/src/rpc/client/jsHandle.ts b/src/rpc/client/jsHandle.tsindex 4d9755fcaa..8f3212288e 100644--- a/src/rpc/client/jsHandle.ts+++ b/src/rpc/client/jsHandle.ts@@ -110,3 +110,8 @@ export function serializeArgument(arg: any): SerializedArgument {export function parseResult(value: SerializedValue): any {return parseSerializedValue(value, undefined);}++export function assertMaxArguments(count: number, max: number): asserts count {+ if (count > max)+ throw new Error('Too many arguments. If you need to pass more than 1 argument to the function wrap them in an object.');+}diff --git a/src/rpc/client/page.ts b/src/rpc/client/page.tsindex 6b032e2be1..91ae4618b8 100644--- a/src/rpc/client/page.ts+++ b/src/rpc/client/page.ts@@ -16,7 +16,7 @@*/import { Events } from './events';-import { assert, assertMaxArguments, helper, Listener } from '../../helper';+import { assert, helper, Listener } from '../../helper';import { TimeoutSettings } from '../../timeoutSettings';import { BindingCallChannel, BindingCallInitializer, PageChannel, PageInitializer, PagePdfParams, FrameWaitForSelectorOptions, FrameDispatchEventOptions, FrameSetContentOptions, FrameGotoOptions, PageReloadOptions, PageGoBackOptions, PageGoForwardOptions, PageScreenshotOptions, FrameClickOptions, FrameDblclickOptions, FrameFillOptions, FrameFocusOptions, FrameTextContentOptions, FrameInnerTextOptions, FrameInnerHTMLOptions, FrameGetAttributeOptions, FrameHoverOptions, FrameSetInputFilesOptions, FrameTypeOptions, FramePressOptions, FrameCheckOptions, FrameUncheckOptions } from '../channels';import { parseError, serializeError } from '../serializers';@@ -31,7 +31,7 @@ import { ElementHandle } from './elementHandle';import { Worker } from './worker';import { Frame, FunctionWithSource, verifyLoadState, WaitForNavigationOptions } from './frame';import { Keyboard, Mouse } from './input';-import { Func1, FuncOn, SmartHandle, serializeArgument, parseResult } from './jsHandle';+import { assertMaxArguments, Func1, FuncOn, SmartHandle, serializeArgument, parseResult } from './jsHandle';import { Request, Response, Route, RouteHandler } from './network';import { FileChooser } from './fileChooser';import { Buffer } from 'buffer';diff --git a/src/rpc/client/worker.ts b/src/rpc/client/worker.tsindex 8b19441f0e..c7dee8b718 100644--- a/src/rpc/client/worker.ts+++ b/src/rpc/client/worker.ts@@ -15,10 +15,9 @@*/import { Events } from './events';-import { assertMaxArguments } from '../../helper';import { WorkerChannel, WorkerInitializer } from '../channels';import { ChannelOwner } from './channelOwner';-import { Func1, JSHandle, parseResult, serializeArgument, SmartHandle } from './jsHandle';+import { assertMaxArguments, Func1, JSHandle, parseResult, serializeArgument, SmartHandle } from './jsHandle';import { Page } from './page';import { BrowserContext } from './browserContext';import { ChromiumBrowserContext } from './chromiumBrowserContext';diff --git a/src/server/browserType.ts b/src/server/browserType.tsindex 886e7780a7..018e541306 100644--- a/src/server/browserType.ts+++ b/src/server/browserType.ts@@ -111,7 +111,7 @@ export abstract class BrowserTypeBase implements BrowserType {// We assume no control when using custom arguments, and do not prepare the default context in that case.const hasCustomArguments = !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs);if (persistent && !hasCustomArguments)- await browser._defaultContext!._loadDefaultContext();+ await browser._defaultContext!._loadDefaultContext(progress);return browser;}diff --git a/src/server/electron.ts b/src/server/electron.tsindex c49d98e24a..bd7e4d7f89 100644--- a/src/server/electron.ts+++ b/src/server/electron.ts@@ -94,18 +94,8 @@ export class ElectronApplication extends EventEmitter {this.emit(ElectronEvents.ElectronApplication.Window, page);}- windows(): Page[] {- return [...this._windows];- }-- async firstWindow(): Promise<Page> {- if (this._windows.size)- return this._windows.values().next().value;- return this.waitForEvent('window');- }-async newBrowserWindow(options: any): Promise<Page> {- const windowId = await this.evaluate(async ({ BrowserWindow }, options) => {+ const windowId = await this._nodeElectronHandle!.evaluate(async ({ BrowserWindow }, options) => {const win = new BrowserWindow(options);win.loadURL('about:blank');return win.id;@@ -125,17 +115,16 @@ export class ElectronApplication extends EventEmitter {async close() {const closed = this.waitForEvent(ElectronEvents.ElectronApplication.Close);- await this.evaluate(({ app }) => app.quit());+ await this._nodeElectronHandle!.evaluate(({ app }) => app.quit());this._nodeConnection.close();await closed;}- async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {- const options = typeof optionsOrPredicate === 'function' ? { predicate: optionsOrPredicate } : optionsOrPredicate;- const progressController = new ProgressController(this._timeoutSettings.timeout(options));+ async waitForEvent(event: string, predicate?: Function): Promise<any> {+ const progressController = new ProgressController(this._timeoutSettings.timeout({}));if (event !== ElectronEvents.ElectronApplication.Close)this._browserContext._closePromise.then(error => progressController.abort(error));- return progressController.run(progress => helper.waitForEvent(progress, this, event, options.predicate).promise);+ return progressController.run(progress => helper.waitForEvent(progress, this, event, predicate).promise);}async _init() {@@ -150,18 +139,6 @@ export class ElectronApplication extends EventEmitter {return new Promise(f => (global as any)._playwrightRunCallback = f);});}-- async evaluate<R, Arg>(pageFunction: js.FuncOn<any, Arg, R>, arg: Arg): Promise<R>;- async evaluate<R>(pageFunction: js.FuncOn<any, void, R>, arg?: any): Promise<R>;- async evaluate<R, Arg>(pageFunction: js.FuncOn<any, Arg, R>, arg: Arg): Promise<R> {- return this._nodeElectronHandle!.evaluate(pageFunction, arg);- }-- async evaluateHandle<R, Arg>(pageFunction: js.FuncOn<any, Arg, R>, arg: Arg): Promise<js.SmartHandle<R>>;- async evaluateHandle<R>(pageFunction: js.FuncOn<any, void, R>, arg?: any): Promise<js.SmartHandle<R>>;- async evaluateHandle<R, Arg>(pageFunction: js.FuncOn<any, Arg, R>, arg: Arg): Promise<js.SmartHandle<R>> {- return this._nodeElectronHandle!.evaluateHandle(pageFunction, arg);- }}export class Electron {diff --git a/src/server/playwright.ts b/src/server/playwright.tsindex b684278b7f..f885329b9c 100644--- a/src/server/playwright.ts+++ b/src/server/playwright.ts@@ -15,7 +15,6 @@*/import * as types from '../types';-import { TimeoutError } from '../errors';import { DeviceDescriptors } from '../deviceDescriptors';import { Chromium } from './chromium';import { WebKit } from './webkit';@@ -26,14 +25,12 @@ import * as browserPaths from '../install/browserPaths';export class Playwright {readonly selectors = selectors;readonly devices: types.Devices;- readonly errors: { TimeoutError: typeof TimeoutError };readonly chromium: Chromium;readonly firefox: Firefox;readonly webkit: WebKit;constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) {this.devices = DeviceDescriptors;- this.errors = { TimeoutError };const chromium = browsers.find(browser => browser.name === 'chromium');this.chromium = new Chromium(packagePath, chromium!);diff --git a/src/transport.ts b/src/transport.tsindex 55ad9f7d68..8a9f8b2937 100644--- a/src/transport.ts+++ b/src/transport.ts@@ -86,38 +86,6 @@ export class SlowMoTransport implements ConnectionTransport {}}-export class DeferWriteTransport implements ConnectionTransport {- private _delegate: ConnectionTransport;- private _readPromise: Promise<void>;-- onmessage?: (message: ProtocolResponse) => void;- onclose?: () => void;-- constructor(transport: ConnectionTransport) {- this._delegate = transport;- let callback: () => void;- this._readPromise = new Promise(f => callback = f);- this._delegate.onmessage = (s: ProtocolResponse) => {- callback();- if (this.onmessage)- this.onmessage(s);- };- this._delegate.onclose = () => {- if (this.onclose)- this.onclose();- };- }-- async send(s: ProtocolRequest) {- await this._readPromise;- this._delegate.send(s);- }-- close() {- this._delegate.close();- }-}-export class WebSocketTransport implements ConnectionTransport {private _ws: WebSocket;private _progress: Progress;@@ -192,38 +160,3 @@ export class WebSocketTransport implements ConnectionTransport {return promise; // Make sure to await the actual disconnect.}}--export class InterceptingTransport implements ConnectionTransport {- private readonly _delegate: ConnectionTransport;- private _interceptor: (message: ProtocolRequest) => ProtocolRequest;-- onmessage?: (message: ProtocolResponse) => void;- onclose?: () => void;-- constructor(transport: ConnectionTransport, interceptor: (message: ProtocolRequest) => ProtocolRequest) {- this._delegate = transport;- this._interceptor = interceptor;- this._delegate.onmessage = this._onmessage.bind(this);- this._delegate.onclose = this._onClose.bind(this);- }-- private _onmessage(message: ProtocolResponse) {- if (this.onmessage)- this.onmessage(message);- }-- private _onClose() {- if (this.onclose)- this.onclose();- this._delegate.onmessage = undefined;- this._delegate.onclose = undefined;- }-- send(s: ProtocolRequest) {- this._delegate.send(this._interceptor(s));- }-- close() {- this._delegate.close();- }-}diff --git a/src/types.ts b/src/types.tsindex 043a1c3daa..7563050261 100644--- a/src/types.ts+++ b/src/types.ts@@ -187,8 +187,6 @@ export type ProxySettings = {password?: string};-export type WaitForEventOptions = Function | { predicate?: Function, timeout?: number };-export type KeyboardModifier = 'Alt' | 'Control' | 'Meta' | 'Shift';export type MouseButton = 'left' | 'right' | 'middle';diff --git a/src/webkit/wkBrowser.ts b/src/webkit/wkBrowser.tsindex 409a1d94ec..2a7a77e2ec 100644--- a/src/webkit/wkBrowser.ts+++ b/src/webkit/wkBrowser.ts@@ -193,11 +193,6 @@ export class WKBrowser extends BrowserBase {isConnected(): boolean {return !this._connection.isClosed();}-- _disconnect() {- helper.removeEventListeners(this._eventListeners);- this._connection.close();- }}export class WKBrowserContext extends BrowserContextBase {diff --git a/src/webkit/wkPage.ts b/src/webkit/wkPage.tsindex 64886e84d3..f77671d539 100644--- a/src/webkit/wkPage.ts+++ b/src/webkit/wkPage.ts@@ -662,7 +662,7 @@ export class WKPage implements PageDelegate {private async _evaluateBindingScript(binding: PageBinding): Promise<void> {const script = this._bindingToScript(binding);- await Promise.all(this._page.frames().map(frame => frame.evaluate(script).catch(e => {})));+ await Promise.all(this._page.frames().map(frame => frame._evaluateExpression(script, false, {}).catch(e => {})));}async evaluateOnNewDocument(script: string): Promise<void> {