chore: inline page._runAbortableTask (#3861)
It does not do anything nowadays.
This commit is contained in:
parent
02275f2414
commit
5314512cbc
|
|
@ -22,7 +22,7 @@ import * as js from './javascript';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
import { SelectorInfo } from './selectors';
|
import { SelectorInfo } from './selectors';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { Progress } from './progress';
|
import { Progress, runAbortableTask } from './progress';
|
||||||
import { FatalDOMError, RetargetableDOMError } from './common/domErrors';
|
import { FatalDOMError, RetargetableDOMError } from './common/domErrors';
|
||||||
|
|
||||||
export class FrameExecutionContext extends js.ExecutionContext {
|
export class FrameExecutionContext extends js.ExecutionContext {
|
||||||
|
|
@ -213,7 +213,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async scrollIntoViewIfNeeded(options: types.TimeoutOptions = {}) {
|
async scrollIntoViewIfNeeded(options: types.TimeoutOptions = {}) {
|
||||||
return this._page._runAbortableTask(
|
return runAbortableTask(
|
||||||
progress => this._waitAndScrollIntoViewIfNeeded(progress),
|
progress => this._waitAndScrollIntoViewIfNeeded(progress),
|
||||||
this._page._timeoutSettings.timeout(options));
|
this._page._timeoutSettings.timeout(options));
|
||||||
}
|
}
|
||||||
|
|
@ -432,7 +432,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async selectText(options: types.TimeoutOptions = {}): Promise<void> {
|
async selectText(options: types.TimeoutOptions = {}): Promise<void> {
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.throwIfAborted(); // Avoid action that has side-effects.
|
progress.throwIfAborted(); // Avoid action that has side-effects.
|
||||||
const poll = await this._evaluateHandleInUtility(([injected, node]) => {
|
const poll = await this._evaluateHandleInUtility(([injected, node]) => {
|
||||||
return injected.waitForVisibleAndSelectText(node);
|
return injected.waitForVisibleAndSelectText(node);
|
||||||
|
|
@ -469,7 +469,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async focus(): Promise<void> {
|
async focus(): Promise<void> {
|
||||||
await this._page._runAbortableTask(async progress => {
|
await runAbortableTask(async progress => {
|
||||||
const result = await this._focus(progress);
|
const result = await this._focus(progress);
|
||||||
await this._page._doSlowMo();
|
await this._page._doSlowMo();
|
||||||
return assertDone(throwRetargetableDOMError(result));
|
return assertDone(throwRetargetableDOMError(result));
|
||||||
|
|
@ -542,7 +542,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshot(options: types.ElementScreenshotOptions = {}): Promise<Buffer> {
|
async screenshot(options: types.ElementScreenshotOptions = {}): Promise<Buffer> {
|
||||||
return this._page._runAbortableTask(
|
return runAbortableTask(
|
||||||
progress => this._page._screenshotter.screenshotElement(progress, this, options),
|
progress => this._page._screenshotter.screenshotElement(progress, this, options),
|
||||||
this._page._timeoutSettings.timeout(options));
|
this._page._timeoutSettings.timeout(options));
|
||||||
}
|
}
|
||||||
|
|
@ -572,7 +572,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async waitForElementState(state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled', options: types.TimeoutOptions = {}): Promise<void> {
|
async waitForElementState(state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled', options: types.TimeoutOptions = {}): Promise<void> {
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(` waiting for element to be ${state}`);
|
progress.log(` waiting for element to be ${state}`);
|
||||||
if (state === 'visible') {
|
if (state === 'visible') {
|
||||||
const poll = await this._evaluateHandleInUtility(([injected, node]) => {
|
const poll = await this._evaluateHandleInUtility(([injected, node]) => {
|
||||||
|
|
@ -625,7 +625,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {
|
||||||
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = waitForSelectorTask(info, state, this);
|
const task = waitForSelectorTask(info, state, this);
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(`waiting for selector "${selector}"${state === 'attached' ? '' : ' to be ' + state}`);
|
progress.log(`waiting for selector "${selector}"${state === 'attached' ? '' : ' to be ' + state}`);
|
||||||
const context = await this._context.frame._context(info.world);
|
const context = await this._context.frame._context(info.world);
|
||||||
const injected = await context.injectedScript();
|
const injected = await context.injectedScript();
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ import * as network from './network';
|
||||||
import { Page } from './page';
|
import { Page } from './page';
|
||||||
import * as types from './types';
|
import * as types from './types';
|
||||||
import { BrowserContext } from './browserContext';
|
import { BrowserContext } from './browserContext';
|
||||||
import { Progress, ProgressController } from './progress';
|
import { Progress, ProgressController, runAbortableTask } from './progress';
|
||||||
import { EventEmitter } from 'events';
|
import { EventEmitter } from 'events';
|
||||||
import { assert, makeWaitForNextTask } from '../utils/utils';
|
import { assert, makeWaitForNextTask } from '../utils/utils';
|
||||||
import { debugLogger } from '../utils/debugLogger';
|
import { debugLogger } from '../utils/debugLogger';
|
||||||
|
|
@ -550,7 +550,7 @@ export class Frame extends EventEmitter {
|
||||||
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
throw new Error(`state: expected one of (attached|detached|visible|hidden)`);
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = dom.waitForSelectorTask(info, state);
|
const task = dom.waitForSelectorTask(info, state);
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(`waiting for selector "${selector}"${state === 'attached' ? '' : ' to be ' + state}`);
|
progress.log(`waiting for selector "${selector}"${state === 'attached' ? '' : ' to be ' + state}`);
|
||||||
const result = await this._scheduleRerunnableHandleTask(progress, info.world, task);
|
const result = await this._scheduleRerunnableHandleTask(progress, info.world, task);
|
||||||
if (!result.asElement()) {
|
if (!result.asElement()) {
|
||||||
|
|
@ -565,7 +565,7 @@ export class Frame extends EventEmitter {
|
||||||
async dispatchEvent(selector: string, type: string, eventInit?: Object, options: types.TimeoutOptions = {}): Promise<void> {
|
async dispatchEvent(selector: string, type: string, eventInit?: Object, options: types.TimeoutOptions = {}): Promise<void> {
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = dom.dispatchEventTask(info, type, eventInit || {});
|
const task = dom.dispatchEventTask(info, type, eventInit || {});
|
||||||
await this._page._runAbortableTask(async progress => {
|
await runAbortableTask(async progress => {
|
||||||
progress.log(`Dispatching "${type}" event on selector "${selector}"...`);
|
progress.log(`Dispatching "${type}" event on selector "${selector}"...`);
|
||||||
// Note: we always dispatch events in the main world.
|
// Note: we always dispatch events in the main world.
|
||||||
await this._scheduleRerunnableTask(progress, 'main', task);
|
await this._scheduleRerunnableTask(progress, 'main', task);
|
||||||
|
|
@ -799,7 +799,7 @@ export class Frame extends EventEmitter {
|
||||||
private async _retryWithSelectorIfNotConnected<R>(
|
private async _retryWithSelectorIfNotConnected<R>(
|
||||||
selector: string, options: types.TimeoutOptions,
|
selector: string, options: types.TimeoutOptions,
|
||||||
action: (progress: Progress, handle: dom.ElementHandle<Element>) => Promise<R | 'error:notconnected'>): Promise<R> {
|
action: (progress: Progress, handle: dom.ElementHandle<Element>) => Promise<R | 'error:notconnected'>): Promise<R> {
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
return this._retryWithProgressIfNotConnected(progress, selector, handle => action(progress, handle));
|
return this._retryWithProgressIfNotConnected(progress, selector, handle => action(progress, handle));
|
||||||
}, this._page._timeoutSettings.timeout(options));
|
}, this._page._timeoutSettings.timeout(options));
|
||||||
}
|
}
|
||||||
|
|
@ -824,7 +824,7 @@ export class Frame extends EventEmitter {
|
||||||
async textContent(selector: string, options: types.TimeoutOptions = {}): Promise<string | null> {
|
async textContent(selector: string, options: types.TimeoutOptions = {}): Promise<string | null> {
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = dom.textContentTask(info);
|
const task = dom.textContentTask(info);
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(` retrieving textContent from "${selector}"`);
|
progress.log(` retrieving textContent from "${selector}"`);
|
||||||
return this._scheduleRerunnableTask(progress, info.world, task);
|
return this._scheduleRerunnableTask(progress, info.world, task);
|
||||||
}, this._page._timeoutSettings.timeout(options));
|
}, this._page._timeoutSettings.timeout(options));
|
||||||
|
|
@ -833,7 +833,7 @@ export class Frame extends EventEmitter {
|
||||||
async innerText(selector: string, options: types.TimeoutOptions = {}): Promise<string> {
|
async innerText(selector: string, options: types.TimeoutOptions = {}): Promise<string> {
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = dom.innerTextTask(info);
|
const task = dom.innerTextTask(info);
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(` retrieving innerText from "${selector}"`);
|
progress.log(` retrieving innerText from "${selector}"`);
|
||||||
const result = dom.throwFatalDOMError(await this._scheduleRerunnableTask(progress, info.world, task));
|
const result = dom.throwFatalDOMError(await this._scheduleRerunnableTask(progress, info.world, task));
|
||||||
return result.innerText;
|
return result.innerText;
|
||||||
|
|
@ -843,7 +843,7 @@ export class Frame extends EventEmitter {
|
||||||
async innerHTML(selector: string, options: types.TimeoutOptions = {}): Promise<string> {
|
async innerHTML(selector: string, options: types.TimeoutOptions = {}): Promise<string> {
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = dom.innerHTMLTask(info);
|
const task = dom.innerHTMLTask(info);
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(` retrieving innerHTML from "${selector}"`);
|
progress.log(` retrieving innerHTML from "${selector}"`);
|
||||||
return this._scheduleRerunnableTask(progress, info.world, task);
|
return this._scheduleRerunnableTask(progress, info.world, task);
|
||||||
}, this._page._timeoutSettings.timeout(options));
|
}, this._page._timeoutSettings.timeout(options));
|
||||||
|
|
@ -852,7 +852,7 @@ export class Frame extends EventEmitter {
|
||||||
async getAttribute(selector: string, name: string, options: types.TimeoutOptions = {}): Promise<string | null> {
|
async getAttribute(selector: string, name: string, options: types.TimeoutOptions = {}): Promise<string | null> {
|
||||||
const info = this._page.selectors._parseSelector(selector);
|
const info = this._page.selectors._parseSelector(selector);
|
||||||
const task = dom.getAttributeTask(info, name);
|
const task = dom.getAttributeTask(info, name);
|
||||||
return this._page._runAbortableTask(async progress => {
|
return runAbortableTask(async progress => {
|
||||||
progress.log(` retrieving attribute "${name}" from "${selector}"`);
|
progress.log(` retrieving attribute "${name}" from "${selector}"`);
|
||||||
return this._scheduleRerunnableTask(progress, info.world, task);
|
return this._scheduleRerunnableTask(progress, info.world, task);
|
||||||
}, this._page._timeoutSettings.timeout(options));
|
}, this._page._timeoutSettings.timeout(options));
|
||||||
|
|
@ -896,7 +896,7 @@ export class Frame extends EventEmitter {
|
||||||
return injectedScript.pollRaf((progress, continuePolling) => innerPredicate(arg) || continuePolling);
|
return injectedScript.pollRaf((progress, continuePolling) => innerPredicate(arg) || continuePolling);
|
||||||
return injectedScript.pollInterval(polling, (progress, continuePolling) => innerPredicate(arg) || continuePolling);
|
return injectedScript.pollInterval(polling, (progress, continuePolling) => innerPredicate(arg) || continuePolling);
|
||||||
}, { predicateBody, polling: options.pollingInterval, arg });
|
}, { predicateBody, polling: options.pollingInterval, arg });
|
||||||
return this._page._runAbortableTask(
|
return runAbortableTask(
|
||||||
progress => this._scheduleRerunnableHandleTask(progress, 'main', task),
|
progress => this._scheduleRerunnableHandleTask(progress, 'main', task),
|
||||||
this._page._timeoutSettings.timeout(options));
|
this._page._timeoutSettings.timeout(options));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,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 { Progress, runAbortableTask } from './progress';
|
import { runAbortableTask } from './progress';
|
||||||
import { assert, isError } from '../utils/utils';
|
import { assert, isError } from '../utils/utils';
|
||||||
import { debugLogger } from '../utils/debugLogger';
|
import { debugLogger } from '../utils/debugLogger';
|
||||||
import { Selectors } from './selectors';
|
import { Selectors } from './selectors';
|
||||||
|
|
@ -198,10 +198,6 @@ export class Page extends EventEmitter {
|
||||||
this._disconnectedCallback(new Error('Page closed'));
|
this._disconnectedCallback(new Error('Page closed'));
|
||||||
}
|
}
|
||||||
|
|
||||||
async _runAbortableTask<T>(task: (progress: Progress) => Promise<T>, timeout: number): Promise<T> {
|
|
||||||
return runAbortableTask(task, timeout);
|
|
||||||
}
|
|
||||||
|
|
||||||
async _onFileChooserOpened(handle: dom.ElementHandle) {
|
async _onFileChooserOpened(handle: dom.ElementHandle) {
|
||||||
const multiple = await handle.evaluate(element => !!(element as HTMLInputElement).multiple);
|
const multiple = await handle.evaluate(element => !!(element as HTMLInputElement).multiple);
|
||||||
if (!this.listenerCount(Page.Events.FileChooser)) {
|
if (!this.listenerCount(Page.Events.FileChooser)) {
|
||||||
|
|
@ -356,7 +352,7 @@ export class Page extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
async screenshot(options: types.ScreenshotOptions = {}): Promise<Buffer> {
|
async screenshot(options: types.ScreenshotOptions = {}): Promise<Buffer> {
|
||||||
return this._runAbortableTask(
|
return runAbortableTask(
|
||||||
progress => this._screenshotter.screenshotPage(progress, options),
|
progress => this._screenshotter.screenshotPage(progress, options),
|
||||||
this._timeoutSettings.timeout(options));
|
this._timeoutSettings.timeout(options));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue