chore: remove unused methods from server side (#3502)
Most of these were api methods that are no longer called directly.
This commit is contained in:
parent
1e9c0eb705
commit
141a255a07
|
|
@ -65,7 +65,6 @@ export abstract class BrowserBase extends EventEmitter implements Browser {
|
||||||
abstract newContext(options?: BrowserContextOptions): Promise<BrowserContext>;
|
abstract newContext(options?: BrowserContextOptions): Promise<BrowserContext>;
|
||||||
abstract contexts(): BrowserContext[];
|
abstract contexts(): BrowserContext[];
|
||||||
abstract isConnected(): boolean;
|
abstract isConnected(): boolean;
|
||||||
abstract _disconnect(): void;
|
|
||||||
abstract version(): string;
|
abstract version(): string;
|
||||||
|
|
||||||
async newPage(options?: BrowserContextOptions): Promise<Page> {
|
async newPage(options?: BrowserContextOptions): Promise<Page> {
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ import { Events } from './events';
|
||||||
import { Download } from './download';
|
import { Download } from './download';
|
||||||
import { BrowserBase } from './browser';
|
import { BrowserBase } from './browser';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { ProgressController } from './progress';
|
import { Progress } from './progress';
|
||||||
import { DebugController } from './debug/debugController';
|
import { DebugController } from './debug/debugController';
|
||||||
|
|
||||||
export interface BrowserContext extends EventEmitter {
|
export interface BrowserContext extends EventEmitter {
|
||||||
|
|
@ -44,10 +44,8 @@ export interface BrowserContext extends EventEmitter {
|
||||||
setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void>;
|
setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void>;
|
||||||
addInitScript(script: Function | string | { path?: string, content?: string }, arg?: any): Promise<void>;
|
addInitScript(script: Function | string | { path?: string, content?: string }, arg?: any): Promise<void>;
|
||||||
exposeBinding(name: string, playwrightBinding: frames.FunctionWithSource): 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>;
|
route(url: types.URLMatch, handler: network.RouteHandler): Promise<void>;
|
||||||
unroute(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>;
|
close(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,14 +75,6 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
|
||||||
new DebugController(this);
|
new 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() {
|
_browserClosed() {
|
||||||
for (const page of this.pages())
|
for (const page of this.pages())
|
||||||
page._didClose();
|
page._didClose();
|
||||||
|
|
@ -127,10 +117,6 @@ export abstract class BrowserContextBase extends EventEmitter implements Browser
|
||||||
return await this._doCookies(urls as string[]);
|
return 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> {
|
setHTTPCredentials(httpCredentials: types.Credentials | null): Promise<void> {
|
||||||
if (!isUnderTest())
|
if (!isUnderTest())
|
||||||
deprecate(`context.setHTTPCredentials`, `warning: method |context.setHTTPCredentials()| is deprecated. Instead of changing credentials, create another browser context with new credentials.`);
|
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 Browser
|
||||||
this._timeoutSettings.setDefaultTimeout(timeout);
|
this._timeoutSettings.setDefaultTimeout(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
async _loadDefaultContext() {
|
async _loadDefaultContext(progress: Progress) {
|
||||||
if (!this.pages().length)
|
if (!this.pages().length) {
|
||||||
await this.waitForEvent('page');
|
const waitForEvent = helper.waitForEvent(progress, this, Events.BrowserContext.Page);
|
||||||
|
progress.cleanupWhenAborted(() => waitForEvent.dispose);
|
||||||
|
await waitForEvent.promise;
|
||||||
|
}
|
||||||
const pages = this.pages();
|
const pages = this.pages();
|
||||||
await pages[0].mainFrame().waitForLoadState();
|
await pages[0].mainFrame().waitForLoadState();
|
||||||
if (pages.length !== 1 || pages[0].mainFrame().url() !== 'about:blank')
|
if (pages.length !== 1 || pages[0].mainFrame().url() !== 'about:blank')
|
||||||
|
|
|
||||||
|
|
@ -211,10 +211,6 @@ export class CRBrowser extends BrowserBase {
|
||||||
await this._session.send('Target.closeTarget', { targetId: crPage._targetId });
|
await this._session.send('Target.closeTarget', { targetId: crPage._targetId });
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
|
||||||
this._connection.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
async newBrowserCDPSession(): Promise<CRSession> {
|
async newBrowserCDPSession(): Promise<CRSession> {
|
||||||
return await this._connection.createBrowserSession();
|
return await this._connection.createBrowserSession();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,7 +119,7 @@ export class CRPage implements PageDelegate {
|
||||||
|
|
||||||
async exposeBinding(binding: PageBinding) {
|
async exposeBinding(binding: PageBinding) {
|
||||||
await this._forAllFrameSessions(frame => frame._initBinding(binding));
|
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> {
|
async updateExtraHTTPHeaders(): Promise<void> {
|
||||||
|
|
@ -394,7 +394,7 @@ class FrameSession {
|
||||||
worldName: UTILITY_WORLD_NAME,
|
worldName: UTILITY_WORLD_NAME,
|
||||||
});
|
});
|
||||||
for (const binding of this._crPage._browserContext._pageBindings.values())
|
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() === ':';
|
const isInitialEmptyPage = this._isMainFrame() && this._page.mainFrame().url() === ':';
|
||||||
if (isInitialEmptyPage) {
|
if (isInitialEmptyPage) {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as js from './javascript';
|
import * as js from './javascript';
|
||||||
import * as util from 'util';
|
|
||||||
import { ConsoleMessageLocation } from './types';
|
import { ConsoleMessageLocation } from './types';
|
||||||
|
|
||||||
export class ConsoleMessage {
|
export class ConsoleMessage {
|
||||||
|
|
@ -48,8 +47,4 @@ export class ConsoleMessage {
|
||||||
location(): ConsoleMessageLocation {
|
location(): ConsoleMessageLocation {
|
||||||
return this._location;
|
return this._location;
|
||||||
}
|
}
|
||||||
|
|
||||||
[util.inspect.custom]() {
|
|
||||||
return this.text();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
16
src/dom.ts
16
src/dom.ts
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as frames from './frames';
|
import * as frames from './frames';
|
||||||
import { assert, helper, assertMaxArguments } from './helper';
|
import { assert, helper } from './helper';
|
||||||
import InjectedScript from './injected/injectedScript';
|
import InjectedScript from './injected/injectedScript';
|
||||||
import * as injectedScriptSource from './generated/injectedScriptSource';
|
import * as injectedScriptSource from './generated/injectedScriptSource';
|
||||||
import * as debugScriptSource from './generated/debugScriptSource';
|
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);
|
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> {
|
async _$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
const handle = await selectors._query(this._context.frame, selector, this);
|
const handle = await selectors._query(this._context.frame, selector, this);
|
||||||
if (!handle)
|
if (!handle)
|
||||||
|
|
@ -623,13 +616,6 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
return result;
|
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> {
|
async _$$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
const arrayHandle = await selectors._queryArray(this._context.frame, selector, this);
|
const arrayHandle = await selectors._queryArray(this._context.frame, selector, this);
|
||||||
const result = await arrayHandle._evaluateExpression(expression, isFunction, true, arg);
|
const result = await arrayHandle._evaluateExpression(expression, isFunction, true, arg);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@
|
||||||
|
|
||||||
import { ElementHandle } from './dom';
|
import { ElementHandle } from './dom';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
import * as types from './types';
|
|
||||||
|
|
||||||
export class FileChooser {
|
export class FileChooser {
|
||||||
private _page: Page;
|
private _page: Page;
|
||||||
|
|
@ -40,8 +39,4 @@ export class FileChooser {
|
||||||
page(): Page {
|
page(): Page {
|
||||||
return this._page;
|
return this._page;
|
||||||
}
|
}
|
||||||
|
|
||||||
async setFiles(files: string | types.FilePayload | string[] | types.FilePayload[], options?: types.NavigatingActionWaitOptions) {
|
|
||||||
return this._elementHandle.setInputFiles(files, options);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -162,11 +162,6 @@ export class FFBrowser extends BrowserBase {
|
||||||
const error = payload.canceled ? 'canceled' : payload.error;
|
const error = payload.canceled ? 'canceled' : payload.error;
|
||||||
this._downloadFinished(payload.uuid, error);
|
this._downloadFinished(payload.uuid, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
|
||||||
helper.removeEventListeners(this._eventListeners);
|
|
||||||
this._connection.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FFBrowserContext extends BrowserContextBase {
|
export class FFBrowserContext extends BrowserContextBase {
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ import * as util from 'util';
|
||||||
import { ConsoleMessage } from './console';
|
import { ConsoleMessage } from './console';
|
||||||
import * as dom from './dom';
|
import * as dom from './dom';
|
||||||
import { Events } from './events';
|
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 js from './javascript';
|
||||||
import * as network from './network';
|
import * as network from './network';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
|
|
@ -374,10 +374,6 @@ export class Frame {
|
||||||
this._parentFrame._childFrames.add(this);
|
this._parentFrame._childFrames.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
page(): Page {
|
|
||||||
return this._page;
|
|
||||||
}
|
|
||||||
|
|
||||||
_onLifecycleEvent(event: types.LifecycleEvent) {
|
_onLifecycleEvent(event: types.LifecycleEvent) {
|
||||||
if (this._firedLifecycleEvents.has(event))
|
if (this._firedLifecycleEvents.has(event))
|
||||||
return;
|
return;
|
||||||
|
|
@ -524,27 +520,11 @@ export class Frame {
|
||||||
return this._context('utility');
|
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> {
|
async _evaluateExpressionHandle(expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
const context = await this._mainContext();
|
const context = await this._mainContext();
|
||||||
return context.evaluateExpressionHandleInternal(expression, isFunction, arg);
|
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> {
|
async _evaluateExpression(expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
const context = await this._mainContext();
|
const context = await this._mainContext();
|
||||||
return context.evaluateExpressionInternal(expression, isFunction, arg);
|
return context.evaluateExpressionInternal(expression, isFunction, arg);
|
||||||
|
|
@ -586,13 +566,6 @@ export class Frame {
|
||||||
}, this._page._timeoutSettings.timeout(options));
|
}, 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> {
|
async _$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
const handle = await this.$(selector);
|
const handle = await this.$(selector);
|
||||||
if (!handle)
|
if (!handle)
|
||||||
|
|
@ -602,13 +575,6 @@ export class Frame {
|
||||||
return result;
|
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> {
|
async _$$evalExpression(selector: string, expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
const arrayHandle = await selectors._queryArray(this, selector);
|
const arrayHandle = await selectors._queryArray(this, selector);
|
||||||
const result = await arrayHandle._evaluateExpression(expression, isFunction, true, arg);
|
const result = await arrayHandle._evaluateExpression(expression, isFunction, true, arg);
|
||||||
|
|
@ -672,10 +638,6 @@ export class Frame {
|
||||||
return Array.from(this._childFrames);
|
return Array.from(this._childFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
isDetached(): boolean {
|
|
||||||
return this._detached;
|
|
||||||
}
|
|
||||||
|
|
||||||
async addScriptTag(options: {
|
async addScriptTag(options: {
|
||||||
url?: string; path?: string;
|
url?: string; path?: string;
|
||||||
content?: string;
|
content?: string;
|
||||||
|
|
@ -924,16 +886,6 @@ export class Frame {
|
||||||
await this._retryWithSelectorIfNotConnected(selector, options, (progress, handle) => handle._setChecked(progress, false, options));
|
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>> {
|
async _waitForFunctionExpression<R>(expression: string, isFunction: boolean, arg: any, options: types.WaitForFunctionOptions = {}): Promise<js.SmartHandle<R>> {
|
||||||
const { polling = 'raf' } = options;
|
const { polling = 'raf' } = options;
|
||||||
if (helper.isString(polling))
|
if (helper.isString(polling))
|
||||||
|
|
|
||||||
|
|
@ -185,15 +185,6 @@ class Helper {
|
||||||
return urlString;
|
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 {
|
static enclosingIntRect(rect: types.Rect): types.Rect {
|
||||||
const x = Math.floor(rect.x + 1e-3);
|
const x = Math.floor(rect.x + 1e-3);
|
||||||
const y = Math.floor(rect.y + 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);
|
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) {
|
export function getFromENV(name: string) {
|
||||||
let value = process.env[name];
|
let value = process.env[name];
|
||||||
value = value || process.env[`npm_config_${name.toLowerCase()}`];
|
value = value || process.env[`npm_config_${name.toLowerCase()}`];
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@
|
||||||
import * as frames from './frames';
|
import * as frames from './frames';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { assert, helper } from './helper';
|
import { assert, helper } from './helper';
|
||||||
import { URLSearchParams } from 'url';
|
|
||||||
import { normalizeFulfillParameters, normalizeContinueOverrides } from './converters';
|
import { normalizeFulfillParameters, normalizeContinueOverrides } from './converters';
|
||||||
|
|
||||||
export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): types.NetworkCookie[] {
|
export function filterCookies(cookies: types.NetworkCookie[], urls: string[]): types.NetworkCookie[] {
|
||||||
|
|
@ -120,34 +119,10 @@ export class Request {
|
||||||
return this._method;
|
return this._method;
|
||||||
}
|
}
|
||||||
|
|
||||||
postData(): string | null {
|
|
||||||
return this._postData ? this._postData.toString('utf8') : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
postDataBuffer(): Buffer | null {
|
postDataBuffer(): Buffer | null {
|
||||||
return this._postData;
|
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} {
|
headers(): {[key: string]: string} {
|
||||||
return { ...this._headers };
|
return { ...this._headers };
|
||||||
}
|
}
|
||||||
|
|
@ -181,10 +156,6 @@ export class Request {
|
||||||
return this._redirectedFrom;
|
return this._redirectedFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
redirectedTo(): Request | null {
|
|
||||||
return this._redirectedTo;
|
|
||||||
}
|
|
||||||
|
|
||||||
failure(): { errorText: string } | null {
|
failure(): { errorText: string } | null {
|
||||||
if (this._failureText === null)
|
if (this._failureText === null)
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -268,10 +239,6 @@ export class Response {
|
||||||
return this._url;
|
return this._url;
|
||||||
}
|
}
|
||||||
|
|
||||||
ok(): boolean {
|
|
||||||
return this._status === 0 || (this._status >= 200 && this._status <= 299);
|
|
||||||
}
|
|
||||||
|
|
||||||
status(): number {
|
status(): number {
|
||||||
return this._status;
|
return this._status;
|
||||||
}
|
}
|
||||||
|
|
@ -299,16 +266,6 @@ export class Response {
|
||||||
return this._contentPromise;
|
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 {
|
request(): Request {
|
||||||
return this._request;
|
return this._request;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
73
src/page.ts
73
src/page.ts
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
import * as dom from './dom';
|
import * as dom from './dom';
|
||||||
import * as frames from './frames';
|
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 input from './input';
|
||||||
import * as js from './javascript';
|
import * as js from './javascript';
|
||||||
import * as network from './network';
|
import * as network from './network';
|
||||||
|
|
@ -30,7 +30,7 @@ import { ConsoleMessage } from './console';
|
||||||
import * as accessibility from './accessibility';
|
import * as accessibility from './accessibility';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { FileChooser } from './fileChooser';
|
import { FileChooser } from './fileChooser';
|
||||||
import { ProgressController, Progress, runAbortableTask } from './progress';
|
import { Progress, runAbortableTask } from './progress';
|
||||||
|
|
||||||
export interface PageDelegate {
|
export interface PageDelegate {
|
||||||
readonly rawMouse: input.RawMouse;
|
readonly rawMouse: input.RawMouse;
|
||||||
|
|
@ -192,17 +192,6 @@ export class Page extends EventEmitter {
|
||||||
return this._frameManager.mainFrame();
|
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[] {
|
frames(): frames.Frame[] {
|
||||||
return this._frameManager.frames();
|
return this._frameManager.frames();
|
||||||
}
|
}
|
||||||
|
|
@ -215,10 +204,6 @@ export class Page extends EventEmitter {
|
||||||
this._timeoutSettings.setDefaultTimeout(timeout);
|
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) {
|
async exposeBinding(name: string, playwrightBinding: frames.FunctionWithSource) {
|
||||||
if (this._pageBindings.has(name))
|
if (this._pageBindings.has(name))
|
||||||
throw new Error(`Function "${name}" has been already registered`);
|
throw new Error(`Function "${name}" has been already registered`);
|
||||||
|
|
@ -255,33 +240,6 @@ export class Page extends EventEmitter {
|
||||||
return waitPromise;
|
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> {
|
async goBack(options?: types.NavigateOptions): Promise<network.Response | null> {
|
||||||
const waitPromise = this.mainFrame().waitForNavigation(options);
|
const waitPromise = this.mainFrame().waitForNavigation(options);
|
||||||
const result = await this._delegate.goBack();
|
const result = await this._delegate.goBack();
|
||||||
|
|
@ -327,11 +285,6 @@ export class Page extends EventEmitter {
|
||||||
await this._delegate.bringToFront();
|
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) {
|
async _addInitScriptExpression(source: string) {
|
||||||
this._evaluateOnNewDocumentSources.push(source);
|
this._evaluateOnNewDocumentSources.push(source);
|
||||||
await this._delegate.evaluateOnNewDocument(source);
|
await this._delegate.evaluateOnNewDocument(source);
|
||||||
|
|
@ -413,14 +366,6 @@ export class Page extends EventEmitter {
|
||||||
return this._closedState === 'closed';
|
return this._closedState === 'closed';
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForTimeout(timeout: number) {
|
|
||||||
await this.mainFrame().waitForTimeout(timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
workers(): Worker[] {
|
|
||||||
return [...this._workers.values()];
|
|
||||||
}
|
|
||||||
|
|
||||||
_addWorker(workerId: string, worker: Worker) {
|
_addWorker(workerId: string, worker: Worker) {
|
||||||
this._workers.set(workerId, worker);
|
this._workers.set(workerId, worker);
|
||||||
this.emit(Events.Page.Worker, worker);
|
this.emit(Events.Page.Worker, worker);
|
||||||
|
|
@ -480,24 +425,10 @@ export class Worker extends EventEmitter {
|
||||||
return this._url;
|
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> {
|
async _evaluateExpression(expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
return js.evaluateExpression(await this._executionContextPromise, true /* returnByValue */, expression, isFunction, arg);
|
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> {
|
async _evaluateExpressionHandle(expression: string, isFunction: boolean, arg: any): Promise<any> {
|
||||||
return js.evaluateExpression(await this._executionContextPromise, false /* returnByValue */, expression, isFunction, arg);
|
return js.evaluateExpression(await this._executionContextPromise, false /* returnByValue */, expression, isFunction, arg);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,7 @@ import { JSHandle } from './jsHandle';
|
||||||
import { ConsoleMessageChannel, ConsoleMessageInitializer } from '../channels';
|
import { ConsoleMessageChannel, ConsoleMessageInitializer } from '../channels';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
|
|
||||||
let __dummyInitializer: ConsoleMessageInitializer;
|
type ConsoleMessageLocation = ConsoleMessageInitializer['location'];
|
||||||
type ConsoleMessageLocation = typeof __dummyInitializer.location;
|
|
||||||
|
|
||||||
export class ConsoleMessage extends ChannelOwner<ConsoleMessageChannel, ConsoleMessageInitializer> {
|
export class ConsoleMessage extends ChannelOwner<ConsoleMessageChannel, ConsoleMessageInitializer> {
|
||||||
static from(message: ConsoleMessageChannel): ConsoleMessage {
|
static from(message: ConsoleMessageChannel): ConsoleMessage {
|
||||||
|
|
|
||||||
|
|
@ -15,12 +15,12 @@
|
||||||
* limitations under the License.
|
* 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 { 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 { BrowserContext } from './browserContext';
|
||||||
import { ChannelOwner } from './channelOwner';
|
import { ChannelOwner } from './channelOwner';
|
||||||
import { ElementHandle, convertSelectOptionValues, convertInputFiles } from './elementHandle';
|
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 fs from 'fs';
|
||||||
import * as network from './network';
|
import * as network from './network';
|
||||||
import * as util from 'util';
|
import * as util from 'util';
|
||||||
|
|
|
||||||
|
|
@ -110,3 +110,8 @@ export function serializeArgument(arg: any): SerializedArgument {
|
||||||
export function parseResult(value: SerializedValue): any {
|
export function parseResult(value: SerializedValue): any {
|
||||||
return parseSerializedValue(value, undefined);
|
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.');
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Events } from './events';
|
import { Events } from './events';
|
||||||
import { assert, assertMaxArguments, helper, Listener } from '../../helper';
|
import { assert, helper, Listener } from '../../helper';
|
||||||
import { TimeoutSettings } from '../../timeoutSettings';
|
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 { 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';
|
import { parseError, serializeError } from '../serializers';
|
||||||
|
|
@ -31,7 +31,7 @@ import { ElementHandle } from './elementHandle';
|
||||||
import { Worker } from './worker';
|
import { Worker } from './worker';
|
||||||
import { Frame, FunctionWithSource, verifyLoadState, WaitForNavigationOptions } from './frame';
|
import { Frame, FunctionWithSource, verifyLoadState, WaitForNavigationOptions } from './frame';
|
||||||
import { Keyboard, Mouse } from './input';
|
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 { Request, Response, Route, RouteHandler } from './network';
|
||||||
import { FileChooser } from './fileChooser';
|
import { FileChooser } from './fileChooser';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Events } from './events';
|
import { Events } from './events';
|
||||||
import { assertMaxArguments } from '../../helper';
|
|
||||||
import { WorkerChannel, WorkerInitializer } from '../channels';
|
import { WorkerChannel, WorkerInitializer } from '../channels';
|
||||||
import { ChannelOwner } from './channelOwner';
|
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 { Page } from './page';
|
||||||
import { BrowserContext } from './browserContext';
|
import { BrowserContext } from './browserContext';
|
||||||
import { ChromiumBrowserContext } from './chromiumBrowserContext';
|
import { ChromiumBrowserContext } from './chromiumBrowserContext';
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// 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);
|
const hasCustomArguments = !!options.ignoreDefaultArgs && !Array.isArray(options.ignoreDefaultArgs);
|
||||||
if (persistent && !hasCustomArguments)
|
if (persistent && !hasCustomArguments)
|
||||||
await browser._defaultContext!._loadDefaultContext();
|
await browser._defaultContext!._loadDefaultContext(progress);
|
||||||
return browser;
|
return browser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -94,18 +94,8 @@ export class ElectronApplication extends EventEmitter {
|
||||||
this.emit(ElectronEvents.ElectronApplication.Window, page);
|
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> {
|
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);
|
const win = new BrowserWindow(options);
|
||||||
win.loadURL('about:blank');
|
win.loadURL('about:blank');
|
||||||
return win.id;
|
return win.id;
|
||||||
|
|
@ -125,17 +115,16 @@ export class ElectronApplication extends EventEmitter {
|
||||||
|
|
||||||
async close() {
|
async close() {
|
||||||
const closed = this.waitForEvent(ElectronEvents.ElectronApplication.Close);
|
const closed = this.waitForEvent(ElectronEvents.ElectronApplication.Close);
|
||||||
await this.evaluate(({ app }) => app.quit());
|
await this._nodeElectronHandle!.evaluate(({ app }) => app.quit());
|
||||||
this._nodeConnection.close();
|
this._nodeConnection.close();
|
||||||
await closed;
|
await closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForEvent(event: string, optionsOrPredicate: types.WaitForEventOptions = {}): Promise<any> {
|
async waitForEvent(event: string, predicate?: Function): Promise<any> {
|
||||||
const options = typeof optionsOrPredicate === 'function' ? { predicate: optionsOrPredicate } : optionsOrPredicate;
|
const progressController = new ProgressController(this._timeoutSettings.timeout({}));
|
||||||
const progressController = new ProgressController(this._timeoutSettings.timeout(options));
|
|
||||||
if (event !== ElectronEvents.ElectronApplication.Close)
|
if (event !== ElectronEvents.ElectronApplication.Close)
|
||||||
this._browserContext._closePromise.then(error => progressController.abort(error));
|
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() {
|
async _init() {
|
||||||
|
|
@ -150,18 +139,6 @@ export class ElectronApplication extends EventEmitter {
|
||||||
return new Promise(f => (global as any)._playwrightRunCallback = f);
|
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 {
|
export class Electron {
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as types from '../types';
|
import * as types from '../types';
|
||||||
import { TimeoutError } from '../errors';
|
|
||||||
import { DeviceDescriptors } from '../deviceDescriptors';
|
import { DeviceDescriptors } from '../deviceDescriptors';
|
||||||
import { Chromium } from './chromium';
|
import { Chromium } from './chromium';
|
||||||
import { WebKit } from './webkit';
|
import { WebKit } from './webkit';
|
||||||
|
|
@ -26,14 +25,12 @@ import * as browserPaths from '../install/browserPaths';
|
||||||
export class Playwright {
|
export class Playwright {
|
||||||
readonly selectors = selectors;
|
readonly selectors = selectors;
|
||||||
readonly devices: types.Devices;
|
readonly devices: types.Devices;
|
||||||
readonly errors: { TimeoutError: typeof TimeoutError };
|
|
||||||
readonly chromium: Chromium;
|
readonly chromium: Chromium;
|
||||||
readonly firefox: Firefox;
|
readonly firefox: Firefox;
|
||||||
readonly webkit: WebKit;
|
readonly webkit: WebKit;
|
||||||
|
|
||||||
constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) {
|
constructor(packagePath: string, browsers: browserPaths.BrowserDescriptor[]) {
|
||||||
this.devices = DeviceDescriptors;
|
this.devices = DeviceDescriptors;
|
||||||
this.errors = { TimeoutError };
|
|
||||||
|
|
||||||
const chromium = browsers.find(browser => browser.name === 'chromium');
|
const chromium = browsers.find(browser => browser.name === 'chromium');
|
||||||
this.chromium = new Chromium(packagePath, chromium!);
|
this.chromium = new Chromium(packagePath, chromium!);
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
export class WebSocketTransport implements ConnectionTransport {
|
||||||
private _ws: WebSocket;
|
private _ws: WebSocket;
|
||||||
private _progress: Progress;
|
private _progress: Progress;
|
||||||
|
|
@ -192,38 +160,3 @@ export class WebSocketTransport implements ConnectionTransport {
|
||||||
return promise; // Make sure to await the actual disconnect.
|
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -187,8 +187,6 @@ export type ProxySettings = {
|
||||||
password?: string
|
password?: string
|
||||||
};
|
};
|
||||||
|
|
||||||
export type WaitForEventOptions = Function | { predicate?: Function, timeout?: number };
|
|
||||||
|
|
||||||
export type KeyboardModifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
|
export type KeyboardModifier = 'Alt' | 'Control' | 'Meta' | 'Shift';
|
||||||
export type MouseButton = 'left' | 'right' | 'middle';
|
export type MouseButton = 'left' | 'right' | 'middle';
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -193,11 +193,6 @@ export class WKBrowser extends BrowserBase {
|
||||||
isConnected(): boolean {
|
isConnected(): boolean {
|
||||||
return !this._connection.isClosed();
|
return !this._connection.isClosed();
|
||||||
}
|
}
|
||||||
|
|
||||||
_disconnect() {
|
|
||||||
helper.removeEventListeners(this._eventListeners);
|
|
||||||
this._connection.close();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class WKBrowserContext extends BrowserContextBase {
|
export class WKBrowserContext extends BrowserContextBase {
|
||||||
|
|
|
||||||
|
|
@ -662,7 +662,7 @@ export class WKPage implements PageDelegate {
|
||||||
|
|
||||||
private async _evaluateBindingScript(binding: PageBinding): Promise<void> {
|
private async _evaluateBindingScript(binding: PageBinding): Promise<void> {
|
||||||
const script = this._bindingToScript(binding);
|
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> {
|
async evaluateOnNewDocument(script: string): Promise<void> {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue