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: migrate some dispatchers from CallMetadata to Progress (part 1) (#36429)
Dmitry Gozmana3eff54e9456
diff --git a/packages/injected/src/injectedScript.ts b/packages/injected/src/injectedScript.tsindex e31bf7b1c4..2c9b11f36a 100644--- a/packages/injected/src/injectedScript.ts+++ b/packages/injected/src/injectedScript.ts@@ -47,7 +47,7 @@ import type { ElementText, TextMatcher } from './selectorUtils';import type { Builtins } from './utilityScript';-export type FrameExpectParams = Omit<channels.FrameExpectParams, 'expectedValue'> & { expectedValue?: any };+export type FrameExpectParams = Omit<channels.FrameExpectParams, 'expectedValue' | 'timeout'> & { expectedValue?: any };export type ElementState = 'visible' | 'hidden' | 'enabled' | 'disabled' | 'editable' | 'checked' | 'unchecked' | 'indeterminate' | 'stable';export type ElementStateWithoutStable = Exclude<ElementState, 'stable'>;diff --git a/packages/playwright-core/src/server/debugController.ts b/packages/playwright-core/src/server/debugController.tsindex 92b94211a6..a861facd8c 100644--- a/packages/playwright-core/src/server/debugController.ts+++ b/packages/playwright-core/src/server/debugController.ts@@ -22,6 +22,7 @@ import { parseAriaSnapshotUnsafe } from '../utils/isomorphic/ariaSnapshot';import { yaml } from '../utilsBundle';import { EmptyRecorderApp } from './recorder/recorderApp';import { unsafeLocatorOrSelectorAsSelector } from '../utils/isomorphic/locatorParser';+import { ProgressController } from './progress';import type { Language } from '../utils';import type { Browser } from './browser';@@ -83,8 +84,10 @@ export class DebugController extends SdkObject {}async navigate(url: string) {- for (const p of this._playwright.allPages())- await p.mainFrame().goto(internalMetadata, url, { timeout: DEFAULT_PLAYWRIGHT_TIMEOUT });+ for (const p of this._playwright.allPages()) {+ const controller = new ProgressController(internalMetadata, this);+ await controller.run(progress => p.mainFrame().goto(progress, url), DEFAULT_PLAYWRIGHT_TIMEOUT);+ }}async setRecorderMode(params: { mode: Mode, file?: string, testIdAttributeName?: string }) {diff --git a/packages/playwright-core/src/server/dispatchers/dispatcher.ts b/packages/playwright-core/src/server/dispatchers/dispatcher.tsindex cc38a398df..db91f38acc 100644--- a/packages/playwright-core/src/server/dispatchers/dispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/dispatcher.ts@@ -24,7 +24,8 @@ import { TargetClosedError, isTargetClosedError, serializeError } from '../errorimport { createRootSdkObject, SdkObject } from '../instrumentation';import { isProtocolError } from '../protocolError';import { compressCallLog } from '../callLog';-import { methodMetainfo } from '../../utils/isomorphic/protocolMetainfo';+import { methodMetainfo, progressTypes } from '../../utils/isomorphic/protocolMetainfo';+import { ProgressController } from '../progress';import type { CallMetadata } from '../instrumentation';import type { PlaywrightDispatcher } from './playwrightDispatcher';@@ -101,8 +102,16 @@ export class Dispatcher<Type extends SdkObject, ChannelType, ParentScopeType extthis.connection.sendAdopt(this, child);}+ private _runCommand(callMetadata: CallMetadata, method: string, validParams: any) {+ if (progressTypes.has(this._type)) {+ const controller = new ProgressController(callMetadata, this._object);+ return controller.run(progress => (this as any)[method](validParams, progress), validParams?.timeout);+ }+ return (this as any)[method](validParams, callMetadata);+ }+async _handleCommand(callMetadata: CallMetadata, method: string, validParams: any) {- const commandPromise = (this as any)[method](validParams, callMetadata);+ const commandPromise = this._runCommand(callMetadata, method, validParams);try {return await this._openScope.race(commandPromise);} catch (e) {diff --git a/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts b/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.tsindex 4f70827048..215aa288f6 100644--- a/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/elementHandlerDispatcher.ts@@ -20,9 +20,9 @@ import { JSHandleDispatcher, parseArgument, serializeResult } from './jsHandleDiimport type { ElementHandle } from '../dom';import type { Frame } from '../frames';-import type { CallMetadata } from '../instrumentation';import type * as js from '../javascript';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export class ElementHandleDispatcher extends JSHandleDispatcher<FrameDispatcher> implements channels.ElementHandleChannel {@@ -55,161 +55,161 @@ export class ElementHandleDispatcher extends JSHandleDispatcher<FrameDispatcher>this._elementHandle = elementHandle;}- async ownerFrame(params: channels.ElementHandleOwnerFrameParams, metadata: CallMetadata): Promise<channels.ElementHandleOwnerFrameResult> {+ async ownerFrame(params: channels.ElementHandleOwnerFrameParams, progress: Progress): Promise<channels.ElementHandleOwnerFrameResult> {const frame = await this._elementHandle.ownerFrame();return { frame: frame ? FrameDispatcher.from(this._browserContextDispatcher(), frame) : undefined };}- async contentFrame(params: channels.ElementHandleContentFrameParams, metadata: CallMetadata): Promise<channels.ElementHandleContentFrameResult> {- const frame = await this._elementHandle.contentFrame();+ async contentFrame(params: channels.ElementHandleContentFrameParams, progress: Progress): Promise<channels.ElementHandleContentFrameResult> {+ const frame = await progress.race(this._elementHandle.contentFrame());return { frame: frame ? FrameDispatcher.from(this._browserContextDispatcher(), frame) : undefined };}- async getAttribute(params: channels.ElementHandleGetAttributeParams, metadata: CallMetadata): Promise<channels.ElementHandleGetAttributeResult> {- const value = await this._elementHandle.getAttribute(metadata, params.name);+ async getAttribute(params: channels.ElementHandleGetAttributeParams, progress: Progress): Promise<channels.ElementHandleGetAttributeResult> {+ const value = await this._elementHandle.getAttribute(progress, params.name);return { value: value === null ? undefined : value };}- async inputValue(params: channels.ElementHandleInputValueParams, metadata: CallMetadata): Promise<channels.ElementHandleInputValueResult> {- const value = await this._elementHandle.inputValue(metadata);+ async inputValue(params: channels.ElementHandleInputValueParams, progress: Progress): Promise<channels.ElementHandleInputValueResult> {+ const value = await this._elementHandle.inputValue(progress);return { value };}- async textContent(params: channels.ElementHandleTextContentParams, metadata: CallMetadata): Promise<channels.ElementHandleTextContentResult> {- const value = await this._elementHandle.textContent(metadata);+ async textContent(params: channels.ElementHandleTextContentParams, progress: Progress): Promise<channels.ElementHandleTextContentResult> {+ const value = await this._elementHandle.textContent(progress);return { value: value === null ? undefined : value };}- async innerText(params: channels.ElementHandleInnerTextParams, metadata: CallMetadata): Promise<channels.ElementHandleInnerTextResult> {- return { value: await this._elementHandle.innerText(metadata) };+ async innerText(params: channels.ElementHandleInnerTextParams, progress: Progress): Promise<channels.ElementHandleInnerTextResult> {+ return { value: await this._elementHandle.innerText(progress) };}- async innerHTML(params: channels.ElementHandleInnerHTMLParams, metadata: CallMetadata): Promise<channels.ElementHandleInnerHTMLResult> {- return { value: await this._elementHandle.innerHTML(metadata) };+ async innerHTML(params: channels.ElementHandleInnerHTMLParams, progress: Progress): Promise<channels.ElementHandleInnerHTMLResult> {+ return { value: await this._elementHandle.innerHTML(progress) };}- async isChecked(params: channels.ElementHandleIsCheckedParams, metadata: CallMetadata): Promise<channels.ElementHandleIsCheckedResult> {- return { value: await this._elementHandle.isChecked(metadata) };+ async isChecked(params: channels.ElementHandleIsCheckedParams, progress: Progress): Promise<channels.ElementHandleIsCheckedResult> {+ return { value: await this._elementHandle.isChecked(progress) };}- async isDisabled(params: channels.ElementHandleIsDisabledParams, metadata: CallMetadata): Promise<channels.ElementHandleIsDisabledResult> {- return { value: await this._elementHandle.isDisabled(metadata) };+ async isDisabled(params: channels.ElementHandleIsDisabledParams, progress: Progress): Promise<channels.ElementHandleIsDisabledResult> {+ return { value: await this._elementHandle.isDisabled(progress) };}- async isEditable(params: channels.ElementHandleIsEditableParams, metadata: CallMetadata): Promise<channels.ElementHandleIsEditableResult> {- return { value: await this._elementHandle.isEditable(metadata) };+ async isEditable(params: channels.ElementHandleIsEditableParams, progress: Progress): Promise<channels.ElementHandleIsEditableResult> {+ return { value: await this._elementHandle.isEditable(progress) };}- async isEnabled(params: channels.ElementHandleIsEnabledParams, metadata: CallMetadata): Promise<channels.ElementHandleIsEnabledResult> {- return { value: await this._elementHandle.isEnabled(metadata) };+ async isEnabled(params: channels.ElementHandleIsEnabledParams, progress: Progress): Promise<channels.ElementHandleIsEnabledResult> {+ return { value: await this._elementHandle.isEnabled(progress) };}- async isHidden(params: channels.ElementHandleIsHiddenParams, metadata: CallMetadata): Promise<channels.ElementHandleIsHiddenResult> {- return { value: await this._elementHandle.isHidden(metadata) };+ async isHidden(params: channels.ElementHandleIsHiddenParams, progress: Progress): Promise<channels.ElementHandleIsHiddenResult> {+ return { value: await this._elementHandle.isHidden(progress) };}- async isVisible(params: channels.ElementHandleIsVisibleParams, metadata: CallMetadata): Promise<channels.ElementHandleIsVisibleResult> {- return { value: await this._elementHandle.isVisible(metadata) };+ async isVisible(params: channels.ElementHandleIsVisibleParams, progress: Progress): Promise<channels.ElementHandleIsVisibleResult> {+ return { value: await this._elementHandle.isVisible(progress) };}- async dispatchEvent(params: channels.ElementHandleDispatchEventParams, metadata: CallMetadata): Promise<void> {- await this._elementHandle.dispatchEvent(metadata, params.type, parseArgument(params.eventInit));+ async dispatchEvent(params: channels.ElementHandleDispatchEventParams, progress: Progress): Promise<void> {+ await this._elementHandle.dispatchEvent(progress, params.type, parseArgument(params.eventInit));}- async scrollIntoViewIfNeeded(params: channels.ElementHandleScrollIntoViewIfNeededParams, metadata: CallMetadata): Promise<void> {- await this._elementHandle.scrollIntoViewIfNeeded(metadata, params);+ async scrollIntoViewIfNeeded(params: channels.ElementHandleScrollIntoViewIfNeededParams, progress: Progress): Promise<void> {+ await this._elementHandle.scrollIntoViewIfNeeded(progress);}- async hover(params: channels.ElementHandleHoverParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.hover(metadata, params);+ async hover(params: channels.ElementHandleHoverParams, progress: Progress): Promise<void> {+ return await this._elementHandle.hover(progress, params);}- async click(params: channels.ElementHandleClickParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.click(metadata, params);+ async click(params: channels.ElementHandleClickParams, progress: Progress): Promise<void> {+ return await this._elementHandle.click(progress, params);}- async dblclick(params: channels.ElementHandleDblclickParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.dblclick(metadata, params);+ async dblclick(params: channels.ElementHandleDblclickParams, progress: Progress): Promise<void> {+ return await this._elementHandle.dblclick(progress, params);}- async tap(params: channels.ElementHandleTapParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.tap(metadata, params);+ async tap(params: channels.ElementHandleTapParams, progress: Progress): Promise<void> {+ return await this._elementHandle.tap(progress, params);}- async selectOption(params: channels.ElementHandleSelectOptionParams, metadata: CallMetadata): Promise<channels.ElementHandleSelectOptionResult> {+ async selectOption(params: channels.ElementHandleSelectOptionParams, progress: Progress): Promise<channels.ElementHandleSelectOptionResult> {const elements = (params.elements || []).map(e => (e as ElementHandleDispatcher)._elementHandle);- return { values: await this._elementHandle.selectOption(metadata, elements, params.options || [], params) };+ return { values: await this._elementHandle.selectOption(progress, elements, params.options || [], params) };}- async fill(params: channels.ElementHandleFillParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.fill(metadata, params.value, params);+ async fill(params: channels.ElementHandleFillParams, progress: Progress): Promise<void> {+ return await this._elementHandle.fill(progress, params.value, params);}- async selectText(params: channels.ElementHandleSelectTextParams, metadata: CallMetadata): Promise<void> {- await this._elementHandle.selectText(metadata, params);+ async selectText(params: channels.ElementHandleSelectTextParams, progress: Progress): Promise<void> {+ await this._elementHandle.selectText(progress, params);}- async setInputFiles(params: channels.ElementHandleSetInputFilesParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.setInputFiles(metadata, params);+ async setInputFiles(params: channels.ElementHandleSetInputFilesParams, progress: Progress): Promise<void> {+ return await this._elementHandle.setInputFiles(progress, params);}- async focus(params: channels.ElementHandleFocusParams, metadata: CallMetadata): Promise<void> {- await this._elementHandle.focus(metadata);+ async focus(params: channels.ElementHandleFocusParams, progress: Progress): Promise<void> {+ await this._elementHandle.focus(progress);}- async type(params: channels.ElementHandleTypeParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.type(metadata, params.text, params);+ async type(params: channels.ElementHandleTypeParams, progress: Progress): Promise<void> {+ return await this._elementHandle.type(progress, params.text, params);}- async press(params: channels.ElementHandlePressParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.press(metadata, params.key, params);+ async press(params: channels.ElementHandlePressParams, progress: Progress): Promise<void> {+ return await this._elementHandle.press(progress, params.key, params);}- async check(params: channels.ElementHandleCheckParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.check(metadata, params);+ async check(params: channels.ElementHandleCheckParams, progress: Progress): Promise<void> {+ return await this._elementHandle.check(progress, params);}- async uncheck(params: channels.ElementHandleUncheckParams, metadata: CallMetadata): Promise<void> {- return await this._elementHandle.uncheck(metadata, params);+ async uncheck(params: channels.ElementHandleUncheckParams, progress: Progress): Promise<void> {+ return await this._elementHandle.uncheck(progress, params);}- async boundingBox(params: channels.ElementHandleBoundingBoxParams, metadata: CallMetadata): Promise<channels.ElementHandleBoundingBoxResult> {- const value = await this._elementHandle.boundingBox();+ async boundingBox(params: channels.ElementHandleBoundingBoxParams, progress: Progress): Promise<channels.ElementHandleBoundingBoxResult> {+ const value = await progress.race(this._elementHandle.boundingBox());return { value: value || undefined };}- async screenshot(params: channels.ElementHandleScreenshotParams, metadata: CallMetadata): Promise<channels.ElementHandleScreenshotResult> {+ async screenshot(params: channels.ElementHandleScreenshotParams, progress: Progress): Promise<channels.ElementHandleScreenshotResult> {const mask: { frame: Frame, selector: string }[] = (params.mask || []).map(({ frame, selector }) => ({frame: (frame as FrameDispatcher)._object,selector,}));- return { binary: await this._elementHandle.screenshot(metadata, { ...params, mask }) };+ return { binary: await this._elementHandle.screenshot(progress, { ...params, mask }) };}- async querySelector(params: channels.ElementHandleQuerySelectorParams, metadata: CallMetadata): Promise<channels.ElementHandleQuerySelectorResult> {- const handle = await this._elementHandle.querySelector(params.selector, params);+ async querySelector(params: channels.ElementHandleQuerySelectorParams, progress: Progress): Promise<channels.ElementHandleQuerySelectorResult> {+ const handle = await progress.race(this._elementHandle.querySelector(params.selector, params));return { element: ElementHandleDispatcher.fromNullable(this.parentScope(), handle) };}- async querySelectorAll(params: channels.ElementHandleQuerySelectorAllParams, metadata: CallMetadata): Promise<channels.ElementHandleQuerySelectorAllResult> {- const elements = await this._elementHandle.querySelectorAll(params.selector);+ async querySelectorAll(params: channels.ElementHandleQuerySelectorAllParams, progress: Progress): Promise<channels.ElementHandleQuerySelectorAllResult> {+ const elements = await progress.race(this._elementHandle.querySelectorAll(params.selector));return { elements: elements.map(e => ElementHandleDispatcher.from(this.parentScope(), e)) };}- async evalOnSelector(params: channels.ElementHandleEvalOnSelectorParams, metadata: CallMetadata): Promise<channels.ElementHandleEvalOnSelectorResult> {- return { value: serializeResult(await this._elementHandle.evalOnSelector(params.selector, !!params.strict, params.expression, params.isFunction, parseArgument(params.arg))) };+ async evalOnSelector(params: channels.ElementHandleEvalOnSelectorParams, progress: Progress): Promise<channels.ElementHandleEvalOnSelectorResult> {+ return { value: serializeResult(await progress.race(this._elementHandle.evalOnSelector(params.selector, !!params.strict, params.expression, params.isFunction, parseArgument(params.arg)))) };}- async evalOnSelectorAll(params: channels.ElementHandleEvalOnSelectorAllParams, metadata: CallMetadata): Promise<channels.ElementHandleEvalOnSelectorAllResult> {- return { value: serializeResult(await this._elementHandle.evalOnSelectorAll(params.selector, params.expression, params.isFunction, parseArgument(params.arg))) };+ async evalOnSelectorAll(params: channels.ElementHandleEvalOnSelectorAllParams, progress: Progress): Promise<channels.ElementHandleEvalOnSelectorAllResult> {+ return { value: serializeResult(await progress.race(this._elementHandle.evalOnSelectorAll(params.selector, params.expression, params.isFunction, parseArgument(params.arg)))) };}- async waitForElementState(params: channels.ElementHandleWaitForElementStateParams, metadata: CallMetadata): Promise<void> {- await this._elementHandle.waitForElementState(metadata, params.state, params);+ async waitForElementState(params: channels.ElementHandleWaitForElementStateParams, progress: Progress): Promise<void> {+ await this._elementHandle.waitForElementState(progress, params.state);}- async waitForSelector(params: channels.ElementHandleWaitForSelectorParams, metadata: CallMetadata): Promise<channels.ElementHandleWaitForSelectorResult> {- return { element: ElementHandleDispatcher.fromNullable(this.parentScope(), await this._elementHandle.waitForSelector(metadata, params.selector, params)) };+ async waitForSelector(params: channels.ElementHandleWaitForSelectorParams, progress: Progress): Promise<channels.ElementHandleWaitForSelectorResult> {+ return { element: ElementHandleDispatcher.fromNullable(this.parentScope(), await this._elementHandle.waitForSelector(progress, params.selector, params)) };}private _browserContextDispatcher(): BrowserContextDispatcher {diff --git a/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts b/packages/playwright-core/src/server/dispatchers/frameDispatcher.tsindex 5db8c7c561..2b4f17f2d4 100644--- a/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/frameDispatcher.ts@@ -23,7 +23,7 @@ import { RequestDispatcher } from './networkDispatchers';import { parseAriaSnapshotUnsafe } from '../../utils/isomorphic/ariaSnapshot';import { yaml } from '../../utilsBundle';-import type { CallMetadata } from '../instrumentation';+import type { Progress } from '../progress';import type { BrowserContextDispatcher } from './browserContextDispatcher';import type { PageDispatcher } from './pageDispatcher';import type { NavigationEvent } from '../frames';@@ -75,204 +75,204 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameChannel, Br});}- async goto(params: channels.FrameGotoParams, metadata: CallMetadata): Promise<channels.FrameGotoResult> {- return { response: ResponseDispatcher.fromNullable(this._browserContextDispatcher, await this._frame.goto(metadata, params.url, params)) };+ async goto(params: channels.FrameGotoParams, progress: Progress): Promise<channels.FrameGotoResult> {+ return { response: ResponseDispatcher.fromNullable(this._browserContextDispatcher, await this._frame.goto(progress, params.url, params)) };}- async frameElement(): Promise<channels.FrameFrameElementResult> {- return { element: ElementHandleDispatcher.from(this, await this._frame.frameElement()) };+ async frameElement(params: channels.FrameFrameElementParams, progress: Progress): Promise<channels.FrameFrameElementResult> {+ return { element: ElementHandleDispatcher.from(this, await progress.race(this._frame.frameElement())) };}- async evaluateExpression(params: channels.FrameEvaluateExpressionParams, metadata: CallMetadata): Promise<channels.FrameEvaluateExpressionResult> {- return { value: serializeResult(await this._frame.evaluateExpression(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg))) };+ async evaluateExpression(params: channels.FrameEvaluateExpressionParams, progress: Progress): Promise<channels.FrameEvaluateExpressionResult> {+ return { value: serializeResult(await progress.race(this._frame.evaluateExpression(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg)))) };}- async evaluateExpressionHandle(params: channels.FrameEvaluateExpressionHandleParams, metadata: CallMetadata): Promise<channels.FrameEvaluateExpressionHandleResult> {- return { handle: ElementHandleDispatcher.fromJSOrElementHandle(this, await this._frame.evaluateExpressionHandle(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg))) };+ async evaluateExpressionHandle(params: channels.FrameEvaluateExpressionHandleParams, progress: Progress): Promise<channels.FrameEvaluateExpressionHandleResult> {+ return { handle: ElementHandleDispatcher.fromJSOrElementHandle(this, await progress.race(this._frame.evaluateExpressionHandle(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg)))) };}- async waitForSelector(params: channels.FrameWaitForSelectorParams, metadata: CallMetadata): Promise<channels.FrameWaitForSelectorResult> {- return { element: ElementHandleDispatcher.fromNullable(this, await this._frame.waitForSelector(metadata, params.selector, params)) };+ async waitForSelector(params: channels.FrameWaitForSelectorParams, progress: Progress): Promise<channels.FrameWaitForSelectorResult> {+ return { element: ElementHandleDispatcher.fromNullable(this, await this._frame.waitForSelector(progress, params.selector, true, params)) };}- async dispatchEvent(params: channels.FrameDispatchEventParams, metadata: CallMetadata): Promise<void> {- return this._frame.dispatchEvent(metadata, params.selector, params.type, parseArgument(params.eventInit), params);+ async dispatchEvent(params: channels.FrameDispatchEventParams, progress: Progress): Promise<void> {+ return this._frame.dispatchEvent(progress, params.selector, params.type, parseArgument(params.eventInit), params);}- async evalOnSelector(params: channels.FrameEvalOnSelectorParams, metadata: CallMetadata): Promise<channels.FrameEvalOnSelectorResult> {- return { value: serializeResult(await this._frame.evalOnSelector(params.selector, !!params.strict, params.expression, params.isFunction, parseArgument(params.arg))) };+ async evalOnSelector(params: channels.FrameEvalOnSelectorParams, progress: Progress): Promise<channels.FrameEvalOnSelectorResult> {+ return { value: serializeResult(await progress.race(this._frame.evalOnSelector(params.selector, !!params.strict, params.expression, params.isFunction, parseArgument(params.arg)))) };}- async evalOnSelectorAll(params: channels.FrameEvalOnSelectorAllParams, metadata: CallMetadata): Promise<channels.FrameEvalOnSelectorAllResult> {- return { value: serializeResult(await this._frame.evalOnSelectorAll(params.selector, params.expression, params.isFunction, parseArgument(params.arg))) };+ async evalOnSelectorAll(params: channels.FrameEvalOnSelectorAllParams, progress: Progress): Promise<channels.FrameEvalOnSelectorAllResult> {+ return { value: serializeResult(await progress.race(this._frame.evalOnSelectorAll(params.selector, params.expression, params.isFunction, parseArgument(params.arg)))) };}- async querySelector(params: channels.FrameQuerySelectorParams, metadata: CallMetadata): Promise<channels.FrameQuerySelectorResult> {- return { element: ElementHandleDispatcher.fromNullable(this, await this._frame.querySelector(params.selector, params)) };+ async querySelector(params: channels.FrameQuerySelectorParams, progress: Progress): Promise<channels.FrameQuerySelectorResult> {+ return { element: ElementHandleDispatcher.fromNullable(this, await progress.race(this._frame.querySelector(params.selector, params))) };}- async querySelectorAll(params: channels.FrameQuerySelectorAllParams, metadata: CallMetadata): Promise<channels.FrameQuerySelectorAllResult> {- const elements = await this._frame.querySelectorAll(params.selector);+ async querySelectorAll(params: channels.FrameQuerySelectorAllParams, progress: Progress): Promise<channels.FrameQuerySelectorAllResult> {+ const elements = await progress.race(this._frame.querySelectorAll(params.selector));return { elements: elements.map(e => ElementHandleDispatcher.from(this, e)) };}- async queryCount(params: channels.FrameQueryCountParams): Promise<channels.FrameQueryCountResult> {- return { value: await this._frame.queryCount(params.selector) };+ async queryCount(params: channels.FrameQueryCountParams, progress: Progress): Promise<channels.FrameQueryCountResult> {+ return { value: await progress.race(this._frame.queryCount(params.selector)) };}- async content(): Promise<channels.FrameContentResult> {- return { value: await this._frame.content() };+ async content(params: channels.FrameContentParams, progress: Progress): Promise<channels.FrameContentResult> {+ return { value: await progress.race(this._frame.content()) };}- async setContent(params: channels.FrameSetContentParams, metadata: CallMetadata): Promise<void> {- return await this._frame.setContent(metadata, params.html, params);+ async setContent(params: channels.FrameSetContentParams, progress: Progress): Promise<void> {+ return await this._frame.setContent(progress, params.html, params);}- async addScriptTag(params: channels.FrameAddScriptTagParams, metadata: CallMetadata): Promise<channels.FrameAddScriptTagResult> {- return { element: ElementHandleDispatcher.from(this, await this._frame.addScriptTag(params)) };+ async addScriptTag(params: channels.FrameAddScriptTagParams, progress: Progress): Promise<channels.FrameAddScriptTagResult> {+ return { element: ElementHandleDispatcher.from(this, await progress.race(this._frame.addScriptTag(params))) };}- async addStyleTag(params: channels.FrameAddStyleTagParams, metadata: CallMetadata): Promise<channels.FrameAddStyleTagResult> {- return { element: ElementHandleDispatcher.from(this, await this._frame.addStyleTag(params)) };+ async addStyleTag(params: channels.FrameAddStyleTagParams, progress: Progress): Promise<channels.FrameAddStyleTagResult> {+ return { element: ElementHandleDispatcher.from(this, await progress.race(this._frame.addStyleTag(params))) };}- async click(params: channels.FrameClickParams, metadata: CallMetadata): Promise<void> {- metadata.potentiallyClosesScope = true;- return await this._frame.click(metadata, params.selector, params);+ async click(params: channels.FrameClickParams, progress: Progress): Promise<void> {+ progress.metadata.potentiallyClosesScope = true;+ return await this._frame.click(progress, params.selector, params);}- async dblclick(params: channels.FrameDblclickParams, metadata: CallMetadata): Promise<void> {- return await this._frame.dblclick(metadata, params.selector, params);+ async dblclick(params: channels.FrameDblclickParams, progress: Progress): Promise<void> {+ return await this._frame.dblclick(progress, params.selector, params);}- async dragAndDrop(params: channels.FrameDragAndDropParams, metadata: CallMetadata): Promise<void> {- return await this._frame.dragAndDrop(metadata, params.source, params.target, params);+ async dragAndDrop(params: channels.FrameDragAndDropParams, progress: Progress): Promise<void> {+ return await this._frame.dragAndDrop(progress, params.source, params.target, params);}- async tap(params: channels.FrameTapParams, metadata: CallMetadata): Promise<void> {- return await this._frame.tap(metadata, params.selector, params);+ async tap(params: channels.FrameTapParams, progress: Progress): Promise<void> {+ return await this._frame.tap(progress, params.selector, params);}- async fill(params: channels.FrameFillParams, metadata: CallMetadata): Promise<void> {- return await this._frame.fill(metadata, params.selector, params.value, params);+ async fill(params: channels.FrameFillParams, progress: Progress): Promise<void> {+ return await this._frame.fill(progress, params.selector, params.value, params);}- async focus(params: channels.FrameFocusParams, metadata: CallMetadata): Promise<void> {- await this._frame.focus(metadata, params.selector, params);+ async focus(params: channels.FrameFocusParams, progress: Progress): Promise<void> {+ await this._frame.focus(progress, params.selector, params);}- async blur(params: channels.FrameBlurParams, metadata: CallMetadata): Promise<void> {- await this._frame.blur(metadata, params.selector, params);+ async blur(params: channels.FrameBlurParams, progress: Progress): Promise<void> {+ await this._frame.blur(progress, params.selector, params);}- async textContent(params: channels.FrameTextContentParams, metadata: CallMetadata): Promise<channels.FrameTextContentResult> {- const value = await this._frame.textContent(metadata, params.selector, params);+ async textContent(params: channels.FrameTextContentParams, progress: Progress): Promise<channels.FrameTextContentResult> {+ const value = await this._frame.textContent(progress, params.selector, params);return { value: value === null ? undefined : value };}- async innerText(params: channels.FrameInnerTextParams, metadata: CallMetadata): Promise<channels.FrameInnerTextResult> {- return { value: await this._frame.innerText(metadata, params.selector, params) };+ async innerText(params: channels.FrameInnerTextParams, progress: Progress): Promise<channels.FrameInnerTextResult> {+ return { value: await this._frame.innerText(progress, params.selector, params) };}- async innerHTML(params: channels.FrameInnerHTMLParams, metadata: CallMetadata): Promise<channels.FrameInnerHTMLResult> {- return { value: await this._frame.innerHTML(metadata, params.selector, params) };+ async innerHTML(params: channels.FrameInnerHTMLParams, progress: Progress): Promise<channels.FrameInnerHTMLResult> {+ return { value: await this._frame.innerHTML(progress, params.selector, params) };}- async generateLocatorString(params: channels.FrameGenerateLocatorStringParams, metadata: CallMetadata): Promise<channels.FrameGenerateLocatorStringResult> {- return { value: await this._frame.generateLocatorString(metadata, params.selector) };+ async generateLocatorString(params: channels.FrameGenerateLocatorStringParams, progress: Progress): Promise<channels.FrameGenerateLocatorStringResult> {+ return { value: await this._frame.generateLocatorString(progress, params.selector) };}- async getAttribute(params: channels.FrameGetAttributeParams, metadata: CallMetadata): Promise<channels.FrameGetAttributeResult> {- const value = await this._frame.getAttribute(metadata, params.selector, params.name, params);+ async getAttribute(params: channels.FrameGetAttributeParams, progress: Progress): Promise<channels.FrameGetAttributeResult> {+ const value = await this._frame.getAttribute(progress, params.selector, params.name, params);return { value: value === null ? undefined : value };}- async inputValue(params: channels.FrameInputValueParams, metadata: CallMetadata): Promise<channels.FrameInputValueResult> {- const value = await this._frame.inputValue(metadata, params.selector, params);+ async inputValue(params: channels.FrameInputValueParams, progress: Progress): Promise<channels.FrameInputValueResult> {+ const value = await this._frame.inputValue(progress, params.selector, params);return { value };}- async isChecked(params: channels.FrameIsCheckedParams, metadata: CallMetadata): Promise<channels.FrameIsCheckedResult> {- return { value: await this._frame.isChecked(metadata, params.selector, params) };+ async isChecked(params: channels.FrameIsCheckedParams, progress: Progress): Promise<channels.FrameIsCheckedResult> {+ return { value: await this._frame.isChecked(progress, params.selector, params) };}- async isDisabled(params: channels.FrameIsDisabledParams, metadata: CallMetadata): Promise<channels.FrameIsDisabledResult> {- return { value: await this._frame.isDisabled(metadata, params.selector, params) };+ async isDisabled(params: channels.FrameIsDisabledParams, progress: Progress): Promise<channels.FrameIsDisabledResult> {+ return { value: await this._frame.isDisabled(progress, params.selector, params) };}- async isEditable(params: channels.FrameIsEditableParams, metadata: CallMetadata): Promise<channels.FrameIsEditableResult> {- return { value: await this._frame.isEditable(metadata, params.selector, params) };+ async isEditable(params: channels.FrameIsEditableParams, progress: Progress): Promise<channels.FrameIsEditableResult> {+ return { value: await this._frame.isEditable(progress, params.selector, params) };}- async isEnabled(params: channels.FrameIsEnabledParams, metadata: CallMetadata): Promise<channels.FrameIsEnabledResult> {- return { value: await this._frame.isEnabled(metadata, params.selector, params) };+ async isEnabled(params: channels.FrameIsEnabledParams, progress: Progress): Promise<channels.FrameIsEnabledResult> {+ return { value: await this._frame.isEnabled(progress, params.selector, params) };}- async isHidden(params: channels.FrameIsHiddenParams, metadata: CallMetadata): Promise<channels.FrameIsHiddenResult> {- return { value: await this._frame.isHidden(metadata, params.selector, params) };+ async isHidden(params: channels.FrameIsHiddenParams, progress: Progress): Promise<channels.FrameIsHiddenResult> {+ return { value: await this._frame.isHidden(progress, params.selector, params) };}- async isVisible(params: channels.FrameIsVisibleParams, metadata: CallMetadata): Promise<channels.FrameIsVisibleResult> {- return { value: await this._frame.isVisible(metadata, params.selector, params) };+ async isVisible(params: channels.FrameIsVisibleParams, progress: Progress): Promise<channels.FrameIsVisibleResult> {+ return { value: await this._frame.isVisible(progress, params.selector, params) };}- async hover(params: channels.FrameHoverParams, metadata: CallMetadata): Promise<void> {- return await this._frame.hover(metadata, params.selector, params);+ async hover(params: channels.FrameHoverParams, progress: Progress): Promise<void> {+ return await this._frame.hover(progress, params.selector, params);}- async selectOption(params: channels.FrameSelectOptionParams, metadata: CallMetadata): Promise<channels.FrameSelectOptionResult> {+ async selectOption(params: channels.FrameSelectOptionParams, progress: Progress): Promise<channels.FrameSelectOptionResult> {const elements = (params.elements || []).map(e => (e as ElementHandleDispatcher)._elementHandle);- return { values: await this._frame.selectOption(metadata, params.selector, elements, params.options || [], params) };+ return { values: await this._frame.selectOption(progress, params.selector, elements, params.options || [], params) };}- async setInputFiles(params: channels.FrameSetInputFilesParams, metadata: CallMetadata): Promise<channels.FrameSetInputFilesResult> {- return await this._frame.setInputFiles(metadata, params.selector, params);+ async setInputFiles(params: channels.FrameSetInputFilesParams, progress: Progress): Promise<channels.FrameSetInputFilesResult> {+ return await this._frame.setInputFiles(progress, params.selector, params);}- async type(params: channels.FrameTypeParams, metadata: CallMetadata): Promise<void> {- return await this._frame.type(metadata, params.selector, params.text, params);+ async type(params: channels.FrameTypeParams, progress: Progress): Promise<void> {+ return await this._frame.type(progress, params.selector, params.text, params);}- async press(params: channels.FramePressParams, metadata: CallMetadata): Promise<void> {- return await this._frame.press(metadata, params.selector, params.key, params);+ async press(params: channels.FramePressParams, progress: Progress): Promise<void> {+ return await this._frame.press(progress, params.selector, params.key, params);}- async check(params: channels.FrameCheckParams, metadata: CallMetadata): Promise<void> {- return await this._frame.check(metadata, params.selector, params);+ async check(params: channels.FrameCheckParams, progress: Progress): Promise<void> {+ return await this._frame.check(progress, params.selector, params);}- async uncheck(params: channels.FrameUncheckParams, metadata: CallMetadata): Promise<void> {- return await this._frame.uncheck(metadata, params.selector, params);+ async uncheck(params: channels.FrameUncheckParams, progress: Progress): Promise<void> {+ return await this._frame.uncheck(progress, params.selector, params);}- async waitForTimeout(params: channels.FrameWaitForTimeoutParams, metadata: CallMetadata): Promise<void> {- return await this._frame.waitForTimeout(metadata, params.timeout);+ async waitForTimeout(params: channels.FrameWaitForTimeoutParams, progress: Progress): Promise<void> {+ return await this._frame.waitForTimeout(progress, params.timeout);}- async waitForFunction(params: channels.FrameWaitForFunctionParams, metadata: CallMetadata): Promise<channels.FrameWaitForFunctionResult> {- return { handle: ElementHandleDispatcher.fromJSOrElementHandle(this, await this._frame.waitForFunctionExpression(metadata, params.expression, params.isFunction, parseArgument(params.arg), params)) };+ async waitForFunction(params: channels.FrameWaitForFunctionParams, progress: Progress): Promise<channels.FrameWaitForFunctionResult> {+ return { handle: ElementHandleDispatcher.fromJSOrElementHandle(this, await this._frame.waitForFunctionExpression(progress, params.expression, params.isFunction, parseArgument(params.arg), params)) };}- async title(params: channels.FrameTitleParams, metadata: CallMetadata): Promise<channels.FrameTitleResult> {- return { value: await this._frame.title() };+ async title(params: channels.FrameTitleParams, progress: Progress): Promise<channels.FrameTitleResult> {+ return { value: await progress.race(this._frame.title()) };}- async highlight(params: channels.FrameHighlightParams, metadata: CallMetadata): Promise<void> {- return await this._frame.highlight(params.selector);+ async highlight(params: channels.FrameHighlightParams, progress: Progress): Promise<void> {+ return await this._frame.highlight(progress, params.selector);}- async expect(params: channels.FrameExpectParams, metadata: CallMetadata): Promise<channels.FrameExpectResult> {- metadata.potentiallyClosesScope = true;+ async expect(params: channels.FrameExpectParams, progress: Progress): Promise<channels.FrameExpectResult> {+ progress.metadata.potentiallyClosesScope = true;let expectedValue = params.expectedValue ? parseArgument(params.expectedValue) : undefined;if (params.expression === 'to.match.aria' && expectedValue)expectedValue = parseAriaSnapshotUnsafe(yaml, expectedValue);- const result = await this._frame.expect(metadata, params.selector, { ...params, expectedValue });+ const result = await this._frame.expect(progress, params.selector, { ...params, expectedValue }, params.timeout);if (result.received !== undefined)result.received = serializeResult(result.received);return result;}- async ariaSnapshot(params: channels.FrameAriaSnapshotParams, metadata: CallMetadata): Promise<channels.FrameAriaSnapshotResult> {- return { snapshot: await this._frame.ariaSnapshot(metadata, params.selector, params) };+ async ariaSnapshot(params: channels.FrameAriaSnapshotParams, progress: Progress): Promise<channels.FrameAriaSnapshotResult> {+ return { snapshot: await this._frame.ariaSnapshot(progress, params.selector, params) };}}diff --git a/packages/playwright-core/src/server/dom.ts b/packages/playwright-core/src/server/dom.tsindex 60abad7dfb..89cc1dc01a 100644--- a/packages/playwright-core/src/server/dom.ts+++ b/packages/playwright-core/src/server/dom.ts@@ -17,14 +17,12 @@import fs from 'fs';import * as js from './javascript';-import { ProgressController } from './progress';import { isUnderTest } from '../utils';import { prepareFilesForUpload } from './fileUploadUtils';import * as rawInjectedScriptSource from '../generated/injectedScriptSource';import type * as frames from './frames';import type { ElementState, HitTargetInterceptionResult, InjectedScript, InjectedScriptOptions } from '@injected/injectedScript';-import type { CallMetadata } from './instrumentation';import type { Page } from './page';import type { Progress } from './progress';import type { ScreenshotOptions } from './screenshotter';@@ -183,28 +181,28 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return this._page.delegate.getContentFrame(this);}- async getAttribute(metadata: CallMetadata, name: string): Promise<string | null> {- return this._frame.getAttribute(metadata, ':scope', name, { timeout: 0 }, this);+ async getAttribute(progress: Progress, name: string): Promise<string | null> {+ return this._frame.getAttribute(progress, ':scope', name, {}, this);}- async inputValue(metadata: CallMetadata): Promise<string> {- return this._frame.inputValue(metadata, ':scope', { timeout: 0 }, this);+ async inputValue(progress: Progress): Promise<string> {+ return this._frame.inputValue(progress, ':scope', {}, this);}- async textContent(metadata: CallMetadata): Promise<string | null> {- return this._frame.textContent(metadata, ':scope', { timeout: 0 }, this);+ async textContent(progress: Progress): Promise<string | null> {+ return this._frame.textContent(progress, ':scope', {}, this);}- async innerText(metadata: CallMetadata): Promise<string> {- return this._frame.innerText(metadata, ':scope', { timeout: 0 }, this);+ async innerText(progress: Progress): Promise<string> {+ return this._frame.innerText(progress, ':scope', {}, this);}- async innerHTML(metadata: CallMetadata): Promise<string> {- return this._frame.innerHTML(metadata, ':scope', { timeout: 0 }, this);+ async innerHTML(progress: Progress): Promise<string> {+ return this._frame.innerHTML(progress, ':scope', {}, this);}- async dispatchEvent(metadata: CallMetadata, type: string, eventInit: Object = {}) {- return this._frame.dispatchEvent(metadata, ':scope', type, eventInit, { timeout: 0 }, this);+ async dispatchEvent(progress: Progress, type: string, eventInit: Object = {}) {+ return this._frame.dispatchEvent(progress, ':scope', type, eventInit, {}, this);}async _scrollRectIntoViewIfNeeded(progress: Progress, rect?: types.Rect): Promise<'error:notvisible' | 'error:notconnected' | 'done'> {@@ -224,11 +222,8 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {assertDone(throwRetargetableDOMError(result));}- async scrollIntoViewIfNeeded(metadata: CallMetadata, options: types.TimeoutOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(- progress => this._waitAndScrollIntoViewIfNeeded(progress, false /* waitForVisible */),- options.timeout);+ async scrollIntoViewIfNeeded(progress: Progress) {+ await this._waitAndScrollIntoViewIfNeeded(progress, false /* waitForVisible */);}private async _clickablePoint(): Promise<types.Point | 'error:notvisible' | 'error:notinviewport' | 'error:notconnected'> {@@ -353,7 +348,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {}async _retryPointerAction(progress: Progress, actionName: ActionName, waitForEnabled: boolean, action: (point: types.Point) => Promise<void>,- options: Omit<{ waitAfter: boolean | 'disabled' } & types.PointerActionOptions & types.PointerActionWaitOptions, 'timeout'>): Promise<'error:notconnected' | 'done'> {+ options: { waitAfter: boolean | 'disabled' } & types.PointerActionOptions & types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> {// Note: do not perform locator handlers checkpoint to avoid moving the mouse in the middle of a drag operation.const skipActionPreChecks = actionName === 'move and up';return await this._retryAction(progress, actionName, async retry => {@@ -378,7 +373,7 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {waitForEnabled: boolean,action: (point: types.Point) => Promise<void>,forceScrollOptions: ScrollIntoViewOptions | undefined,- options: Omit<{ waitAfter: boolean | 'disabled' } & types.PointerActionOptions & types.PointerActionWaitOptions, 'timeout'>,+ options: { waitAfter: boolean | 'disabled' } & types.PointerActionOptions & types.PointerActionWaitOptions,): Promise<PerformActionResult> {const { force = false, position } = options;@@ -505,65 +500,50 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {}, progress.metadata.id));}- async hover(metadata: CallMetadata, options: types.PointerActionOptions & types.PointerActionWaitOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._hover(progress, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async hover(progress: Progress, options: types.PointerActionOptions & types.PointerActionWaitOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._hover(progress, options);+ return assertDone(throwRetargetableDOMError(result));}_hover(progress: Progress, options: types.PointerActionOptions & types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> {return this._retryPointerAction(progress, 'hover', false /* waitForEnabled */, point => this._page.mouse._move(progress, point.x, point.y), { ...options, waitAfter: 'disabled' });}- async click(metadata: CallMetadata, options: { noWaitAfter?: boolean } & types.MouseClickOptions & types.PointerActionWaitOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._click(progress, { ...options, waitAfter: !options.noWaitAfter });- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async click(progress: Progress, options: { noWaitAfter?: boolean } & types.MouseClickOptions & types.PointerActionWaitOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._click(progress, { ...options, waitAfter: !options.noWaitAfter });+ return assertDone(throwRetargetableDOMError(result));}_click(progress: Progress, options: { waitAfter: boolean | 'disabled' } & types.MouseClickOptions & types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> {return this._retryPointerAction(progress, 'click', true /* waitForEnabled */, point => this._page.mouse._click(progress, point.x, point.y, options), options);}- async dblclick(metadata: CallMetadata, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._dblclick(progress, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async dblclick(progress: Progress, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._dblclick(progress, options);+ return assertDone(throwRetargetableDOMError(result));}_dblclick(progress: Progress, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> {return this._retryPointerAction(progress, 'dblclick', true /* waitForEnabled */, point => this._page.mouse._click(progress, point.x, point.y, { ...options, clickCount: 2 }), { ...options, waitAfter: 'disabled' });}- async tap(metadata: CallMetadata, options: types.PointerActionWaitOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._tap(progress, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async tap(progress: Progress, options: types.PointerActionWaitOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._tap(progress, options);+ return assertDone(throwRetargetableDOMError(result));}_tap(progress: Progress, options: types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> {return this._retryPointerAction(progress, 'tap', true /* waitForEnabled */, point => this._page.touchscreen._tap(progress, point.x, point.y), { ...options, waitAfter: 'disabled' });}- async selectOption(metadata: CallMetadata, elements: ElementHandle[], values: types.SelectOption[], options: types.CommonActionOptions): Promise<string[]> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._selectOption(progress, elements, values, options);- return throwRetargetableDOMError(result);- }, options.timeout);+ async selectOption(progress: Progress, elements: ElementHandle[], values: types.SelectOption[], options: types.CommonActionOptions): Promise<string[]> {+ await this._markAsTargetElement(progress);+ const result = await this._selectOption(progress, elements, values, options);+ return throwRetargetableDOMError(result);}async _selectOption(progress: Progress, elements: ElementHandle[], values: types.SelectOption[], options: types.CommonActionOptions): Promise<string[] | 'error:notconnected'> {@@ -593,13 +573,10 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return resultingOptions;}- async fill(metadata: CallMetadata, value: string, options: types.CommonActionOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._fill(progress, value, options);- assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async fill(progress: Progress, value: string, options: types.CommonActionOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._fill(progress, value, options);+ assertDone(throwRetargetableDOMError(result));}async _fill(progress: Progress, value: string, options: types.CommonActionOptions): Promise<'error:notconnected' | 'done'> {@@ -628,33 +605,27 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {}, options);}- async selectText(metadata: CallMetadata, options: types.CommonActionOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const result = await this._retryAction(progress, 'selectText', async () => {- if (!options.force)- progress.log(' waiting for element to be visible');- return await progress.race(this.evaluateInUtility(async ([injected, node, { force }]) => {- if (!force) {- const checkResult = await injected.checkElementStates(node, ['visible']);- if (checkResult)- return checkResult;- }- return injected.selectText(node);- }, { force: options.force }));- }, options);- assertDone(throwRetargetableDOMError(result));- }, options.timeout);- }-- async setInputFiles(metadata: CallMetadata, params: channels.ElementHandleSetInputFilesParams) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const inputFileItems = await progress.race(prepareFilesForUpload(this._frame, params));- await this._markAsTargetElement(progress);- const result = await this._setInputFiles(progress, inputFileItems);- return assertDone(throwRetargetableDOMError(result));- }, params.timeout);+ async selectText(progress: Progress, options: types.CommonActionOptions): Promise<void> {+ const result = await this._retryAction(progress, 'selectText', async () => {+ if (!options.force)+ progress.log(' waiting for element to be visible');+ return await progress.race(this.evaluateInUtility(async ([injected, node, { force }]) => {+ if (!force) {+ const checkResult = await injected.checkElementStates(node, ['visible']);+ if (checkResult)+ return checkResult;+ }+ return injected.selectText(node);+ }, { force: options.force }));+ }, options);+ assertDone(throwRetargetableDOMError(result));+ }++ async setInputFiles(progress: Progress, params: Omit<channels.ElementHandleSetInputFilesParams, 'timeout'>) {+ const inputFileItems = await progress.race(prepareFilesForUpload(this._frame, params));+ await this._markAsTargetElement(progress);+ const result = await this._setInputFiles(progress, inputFileItems);+ return assertDone(throwRetargetableDOMError(result));}async _setInputFiles(progress: Progress, items: InputFilesItems): Promise<'error:notconnected' | 'done'> {@@ -697,13 +668,10 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return 'done';}- async focus(metadata: CallMetadata): Promise<void> {- const controller = new ProgressController(metadata, this);- await controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._focus(progress);- return assertDone(throwRetargetableDOMError(result));- }, 0);+ async focus(progress: Progress): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._focus(progress);+ return assertDone(throwRetargetableDOMError(result));}async _focus(progress: Progress, resetSelectionIfNotFocused?: boolean): Promise<'error:notconnected' | 'done'> {@@ -714,16 +682,13 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return await progress.race(this.evaluateInUtility(([injected, node]) => injected.blurNode(node), {}));}- async type(metadata: CallMetadata, text: string, options: { delay?: number } & types.TimeoutOptions & types.StrictOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._type(progress, text, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async type(progress: Progress, text: string, options: { delay?: number } & types.StrictOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._type(progress, text, options);+ return assertDone(throwRetargetableDOMError(result));}- async _type(progress: Progress, text: string, options: { delay?: number } & types.TimeoutOptions & types.StrictOptions): Promise<'error:notconnected' | 'done'> {+ async _type(progress: Progress, text: string, options: { delay?: number } & types.StrictOptions): Promise<'error:notconnected' | 'done'> {progress.log(`elementHandle.type("${text}")`);await progress.race(this.instrumentation.onBeforeInputAction(this, progress.metadata));const result = await this._focus(progress, true /* resetSelectionIfNotFocused */);@@ -733,16 +698,13 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return 'done';}- async press(metadata: CallMetadata, key: string, options: { delay?: number, noWaitAfter?: boolean } & types.TimeoutOptions & types.StrictOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this._markAsTargetElement(progress);- const result = await this._press(progress, key, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async press(progress: Progress, key: string, options: { delay?: number, noWaitAfter?: boolean } & types.StrictOptions): Promise<void> {+ await this._markAsTargetElement(progress);+ const result = await this._press(progress, key, options);+ return assertDone(throwRetargetableDOMError(result));}- async _press(progress: Progress, key: string, options: { delay?: number, noWaitAfter?: boolean } & types.TimeoutOptions & types.StrictOptions): Promise<'error:notconnected' | 'done'> {+ async _press(progress: Progress, key: string, options: { delay?: number, noWaitAfter?: boolean } & types.StrictOptions): Promise<'error:notconnected' | 'done'> {progress.log(`elementHandle.press("${key}")`);await progress.race(this.instrumentation.onBeforeInputAction(this, progress.metadata));return this._page.frameManager.waitForSignalsCreatedBy(progress, !options.noWaitAfter, async () => {@@ -754,20 +716,14 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {});}- async check(metadata: CallMetadata, options: { position?: types.Point } & types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const result = await this._setChecked(progress, true, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async check(progress: Progress, options: { position?: types.Point } & types.PointerActionWaitOptions) {+ const result = await this._setChecked(progress, true, options);+ return assertDone(throwRetargetableDOMError(result));}- async uncheck(metadata: CallMetadata, options: { position?: types.Point } & types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const result = await this._setChecked(progress, false, options);- return assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async uncheck(progress: Progress, options: { position?: types.Point } & types.PointerActionWaitOptions) {+ const result = await this._setChecked(progress, false, options);+ return assertDone(throwRetargetableDOMError(result));}async _setChecked(progress: Progress, state: boolean, options: { position?: types.Point } & types.PointerActionWaitOptions): Promise<'error:notconnected' | 'done'> {@@ -798,11 +754,8 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return await this.evaluateInUtility(([injected, element, options]) => injected.ariaSnapshot(element, options), options);}- async screenshot(metadata: CallMetadata, options: ScreenshotOptions & types.TimeoutOptions): Promise<Buffer> {- const controller = new ProgressController(metadata, this);- return controller.run(- progress => this._page.screenshotter.screenshotElement(progress, this, options),- options.timeout);+ async screenshot(progress: Progress, options: ScreenshotOptions): Promise<Buffer> {+ return await this._page.screenshotter.screenshotElement(progress, this, options);}async querySelector(selector: string, options: types.StrictOptions): Promise<ElementHandle | null> {@@ -821,45 +774,42 @@ export class ElementHandle<T extends Node = Node> extends js.JSHandle<T> {return this._frame.evalOnSelectorAll(selector, expression, isFunction, arg, this);}- async isVisible(metadata: CallMetadata): Promise<boolean> {- return this._frame.isVisible(metadata, ':scope', {}, this);+ async isVisible(progress: Progress): Promise<boolean> {+ return this._frame.isVisible(progress, ':scope', {}, this);}- async isHidden(metadata: CallMetadata): Promise<boolean> {- return this._frame.isHidden(metadata, ':scope', {}, this);+ async isHidden(progress: Progress): Promise<boolean> {+ return this._frame.isHidden(progress, ':scope', {}, this);}- async isEnabled(metadata: CallMetadata): Promise<boolean> {- return this._frame.isEnabled(metadata, ':scope', { timeout: 0 }, this);+ async isEnabled(progress: Progress): Promise<boolean> {+ return this._frame.isEnabled(progress, ':scope', {}, this);}- async isDisabled(metadata: CallMetadata): Promise<boolean> {- return this._frame.isDisabled(metadata, ':scope', { timeout: 0 }, this);+ async isDisabled(progress: Progress): Promise<boolean> {+ return this._frame.isDisabled(progress, ':scope', {}, this);}- async isEditable(metadata: CallMetadata): Promise<boolean> {- return this._frame.isEditable(metadata, ':scope', { timeout: 0 }, this);+ async isEditable(progress: Progress): Promise<boolean> {+ return this._frame.isEditable(progress, ':scope', {}, this);}- async isChecked(metadata: CallMetadata): Promise<boolean> {- return this._frame.isChecked(metadata, ':scope', { timeout: 0 }, this);+ async isChecked(progress: Progress): Promise<boolean> {+ return this._frame.isChecked(progress, ':scope', {}, this);}- async waitForElementState(metadata: CallMetadata, state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled' | 'editable', options: types.TimeoutOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const actionName = `wait for ${state}`;- const result = await this._retryAction(progress, actionName, async () => {- return await progress.race(this.evaluateInUtility(async ([injected, node, state]) => {- return (await injected.checkElementStates(node, [state])) || 'done';- }, state));- }, {});- assertDone(throwRetargetableDOMError(result));- }, options.timeout);+ async waitForElementState(progress: Progress, state: 'visible' | 'hidden' | 'stable' | 'enabled' | 'disabled' | 'editable'): Promise<void> {+ const actionName = `wait for ${state}`;+ const result = await this._retryAction(progress, actionName, async () => {+ return await progress.race(this.evaluateInUtility(async ([injected, node, state]) => {+ return (await injected.checkElementStates(node, [state])) || 'done';+ }, state));+ }, {});+ assertDone(throwRetargetableDOMError(result));}- async waitForSelector(metadata: CallMetadata, selector: string, options: types.WaitForElementOptions): Promise<ElementHandle<Element> | null> {- return this._frame.waitForSelector(metadata, selector, options, this);+ async waitForSelector(progress: Progress, selector: string, options: types.WaitForElementOptions): Promise<ElementHandle<Element> | null> {+ return await this._frame.waitForSelector(progress, selector, true, options, this);}async _adoptTo(context: FrameExecutionContext): Promise<ElementHandle<T>> {diff --git a/packages/playwright-core/src/server/fileUploadUtils.ts b/packages/playwright-core/src/server/fileUploadUtils.tsindex 9b1668ad80..5a3487a5c1 100644--- a/packages/playwright-core/src/server/fileUploadUtils.ts+++ b/packages/playwright-core/src/server/fileUploadUtils.ts@@ -34,7 +34,7 @@ async function filesExceedUploadLimit(files: string[]) {return sizes.reduce((total, size) => total + size, 0) >= fileUploadSizeLimit;}-export async function prepareFilesForUpload(frame: Frame, params: channels.ElementHandleSetInputFilesParams): Promise<InputFilesItems> {+export async function prepareFilesForUpload(frame: Frame, params: Omit<channels.ElementHandleSetInputFilesParams, 'timeout'>): Promise<InputFilesItems> {const { payloads, streams, directoryStream } = params;let { localPaths, localDirectory } = params;diff --git a/packages/playwright-core/src/server/frames.ts b/packages/playwright-core/src/server/frames.tsindex d428f79eb9..c8dfa9999c 100644--- a/packages/playwright-core/src/server/frames.ts+++ b/packages/playwright-core/src/server/frames.ts@@ -37,7 +37,6 @@ import { compressCallLog } from './callLog';import type { ConsoleMessage } from './console';import type { ElementStateWithoutStable, FrameExpectParams, InjectedScript } from '@injected/injectedScript';-import type { CallMetadata } from './instrumentation';import type { Progress } from './progress';import type { ScreenshotOptions } from './screenshotter';import type { RegisteredListener } from './utils/eventsHelper';@@ -609,15 +608,12 @@ export class Frame extends SdkObject {data.gotoPromise.finally(() => this._redirectedNavigations.delete(documentId));}- async goto(metadata: CallMetadata, url: string, options: types.GotoOptions): Promise<network.Response | null> {- const controller = new ProgressController(metadata, this);- return controller.run(progress => {- const constructedNavigationURL = constructURLBasedOnBaseURL(this._page.browserContext._options.baseURL, url);- return this.raceNavigationAction(progress, async () => this.gotoImpl(progress, constructedNavigationURL, options));- }, options.timeout);+ async goto(progress: Progress, url: string, options: types.GotoOptions = {}): Promise<network.Response | null> {+ const constructedNavigationURL = constructURLBasedOnBaseURL(this._page.browserContext._options.baseURL, url);+ return this.raceNavigationAction(progress, async () => this.gotoImpl(progress, constructedNavigationURL, options));}- async gotoImpl(progress: Progress, url: string, options: Omit<types.GotoOptions, 'timeout'>): Promise<network.Response | null> {+ async gotoImpl(progress: Progress, url: string, options: types.GotoOptions): Promise<network.Response | null> {const waitUntil = verifyLifecycle('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);progress.log(`navigating to "${url}", waiting until "${waitUntil}"`);const headers = this._page.extraHTTPHeaders() || [];@@ -673,7 +669,7 @@ export class Frame extends SdkObject {return response;}- async _waitForNavigation(progress: Progress, requiresNewDocument: boolean, options: types.NavigateOptions): Promise<network.Response | null> {+ async _waitForNavigation(progress: Progress, requiresNewDocument: boolean, options: Omit<types.NavigateOptions, 'timeout'>): Promise<network.Response | null> {const waitUntil = verifyLifecycle('waitUntil', options.waitUntil === undefined ? 'load' : options.waitUntil);progress.log(`waiting for navigation until "${waitUntil}"`);@@ -743,25 +739,18 @@ export class Frame extends SdkObject {return this.selectors.query(selector, options);}- async waitForSelector(metadata: CallMetadata, selector: string, options: types.WaitForElementOptions, scope?: dom.ElementHandle): Promise<dom.ElementHandle<Element> | null> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- if ((options as any).visibility)- throw new Error('options.visibility is not supported, did you mean options.state?');- if ((options as any).waitFor && (options as any).waitFor !== 'visible')- throw new Error('options.waitFor is not supported, did you mean options.state?');- const { state = 'visible' } = options;- if (!['attached', 'detached', 'visible', 'hidden'].includes(state))- throw new Error(`state: expected one of (attached|detached|visible|hidden)`);- progress.log(`waiting for ${this._asLocator(selector)}${state === 'attached' ? '' : ' to be ' + state}`);- return await this.waitForSelectorInternal(progress, selector, true, options, scope);- }, options.timeout);- }-- async waitForSelectorInternal(progress: Progress, selector: string, performActionPreChecks: boolean, options: Omit<types.WaitForElementOptions, 'timeout'>, scope?: dom.ElementHandle): Promise<dom.ElementHandle<Element> | null> {+ async waitForSelector(progress: Progress, selector: string, performActionPreChecksAndLog: boolean, options: types.WaitForElementOptions, scope?: dom.ElementHandle): Promise<dom.ElementHandle<Element> | null> {+ if ((options as any).visibility)+ throw new Error('options.visibility is not supported, did you mean options.state?');+ if ((options as any).waitFor && (options as any).waitFor !== 'visible')+ throw new Error('options.waitFor is not supported, did you mean options.state?');const { state = 'visible' } = options;+ if (!['attached', 'detached', 'visible', 'hidden'].includes(state))+ throw new Error(`state: expected one of (attached|detached|visible|hidden)`);+ if (performActionPreChecksAndLog)+ progress.log(`waiting for ${this._asLocator(selector)}${state === 'attached' ? '' : ' to be ' + state}`);const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {- if (performActionPreChecks)+ if (performActionPreChecksAndLog)await this._page.performActionPreChecks(progress);const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));@@ -814,8 +803,8 @@ export class Frame extends SdkObject {return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;}- async dispatchEvent(metadata: CallMetadata, selector: string, type: string, eventInit: Object = {}, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<void> {- await this._callOnElementOnceMatches(metadata, selector, (injectedScript, element, data) => {+ async dispatchEvent(progress: Progress, selector: string, type: string, eventInit: Object = {}, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<void> {+ await this._callOnElementOnceMatches(progress, selector, (injectedScript, element, data) => {injectedScript.dispatchEvent(element, data.type, data.eventInit);}, { type, eventInit }, { mainWorld: true, ...options }, scope);}@@ -870,32 +859,29 @@ export class Frame extends SdkObject {}}- async setContent(metadata: CallMetadata, html: string, options: types.NavigateOptions): Promise<void> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- await this.raceNavigationAction(progress, async () => {- const waitUntil = options.waitUntil === undefined ? 'load' : options.waitUntil;- progress.log(`setting frame content, waiting until "${waitUntil}"`);- const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;- const context = await progress.race(this._utilityContext());- const tagPromise = new ManualPromise<void>();- this._page.frameManager._consoleMessageTags.set(tag, () => {- // Clear lifecycle right after document.open() - see 'tag' below.- this._onClearLifecycle();- tagPromise.resolve();- });- progress.cleanupWhenAborted(() => this._page.frameManager._consoleMessageTags.delete(tag));- const lifecyclePromise = progress.race(tagPromise).then(() => this._waitForLoadState(progress, waitUntil));- const contentPromise = progress.race(context.evaluate(({ html, tag }) => {- document.open();- console.debug(tag); // eslint-disable-line no-console- document.write(html);- document.close();- }, { html, tag }));- await Promise.all([contentPromise, lifecyclePromise]);- return null;+ async setContent(progress: Progress, html: string, options: Omit<types.NavigateOptions, 'timeout'>): Promise<void> {+ await this.raceNavigationAction(progress, async () => {+ const waitUntil = options.waitUntil === undefined ? 'load' : options.waitUntil;+ progress.log(`setting frame content, waiting until "${waitUntil}"`);+ const tag = `--playwright--set--content--${this._id}--${++this._setContentCounter}--`;+ const context = await progress.race(this._utilityContext());+ const tagPromise = new ManualPromise<void>();+ this._page.frameManager._consoleMessageTags.set(tag, () => {+ // Clear lifecycle right after document.open() - see 'tag' below.+ this._onClearLifecycle();+ tagPromise.resolve();});- }, options.timeout);+ progress.cleanupWhenAborted(() => this._page.frameManager._consoleMessageTags.delete(tag));+ const lifecyclePromise = progress.race(tagPromise).then(() => this._waitForLoadState(progress, waitUntil));+ const contentPromise = progress.race(context.evaluate(({ html, tag }) => {+ document.open();+ console.debug(tag); // eslint-disable-line no-console+ document.write(html);+ document.close();+ }, { html, tag }));+ await Promise.all([contentPromise, lifecyclePromise]);+ return null;+ });}name(): string {@@ -1141,131 +1127,107 @@ export class Frame extends SdkObject {});}- async click(metadata: CallMetadata, selector: string, options: { noWaitAfter?: boolean } & types.MouseClickOptions & types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));- }, options.timeout);+ async click(progress: Progress, selector: string, options: { noWaitAfter?: boolean } & types.MouseClickOptions & types.PointerActionWaitOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._click(progress, { ...options, waitAfter: !options.noWaitAfter })));}- async dblclick(metadata: CallMetadata, selector: string, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._dblclick(progress, options)));- }, options.timeout);+ async dblclick(progress: Progress, selector: string, options: types.MouseMultiClickOptions & types.PointerActionWaitOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._dblclick(progress, options)));}- async dragAndDrop(metadata: CallMetadata, source: string, target: string, options: types.DragActionOptions & types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- await controller.run(async progress => {- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force /* performActionPreChecks */, async handle => {- return handle._retryPointerAction(progress, 'move and down', false, async point => {- await this._page.mouse._move(progress, point.x, point.y);- await this._page.mouse._down(progress);- }, {- ...options,- waitAfter: 'disabled',- position: options.sourcePosition,- });- }));- // Note: do not perform locator handlers checkpoint to avoid moving the mouse in the middle of a drag operation.- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false /* performActionPreChecks */, async handle => {- return handle._retryPointerAction(progress, 'move and up', false, async point => {- await this._page.mouse._move(progress, point.x, point.y);- await this._page.mouse._up(progress);- }, {- ...options,- waitAfter: 'disabled',- position: options.targetPosition,- });- }));- }, options.timeout);+ async dragAndDrop(progress: Progress, source: string, target: string, options: types.DragActionOptions & types.PointerActionWaitOptions) {+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, source, options.strict, !options.force /* performActionPreChecks */, async handle => {+ return handle._retryPointerAction(progress, 'move and down', false, async point => {+ await this._page.mouse._move(progress, point.x, point.y);+ await this._page.mouse._down(progress);+ }, {+ ...options,+ waitAfter: 'disabled',+ position: options.sourcePosition,+ });+ }));+ // Note: do not perform locator handlers checkpoint to avoid moving the mouse in the middle of a drag operation.+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, target, options.strict, false /* performActionPreChecks */, async handle => {+ return handle._retryPointerAction(progress, 'move and up', false, async point => {+ await this._page.mouse._move(progress, point.x, point.y);+ await this._page.mouse._up(progress);+ }, {+ ...options,+ waitAfter: 'disabled',+ position: options.targetPosition,+ });+ }));}- async tap(metadata: CallMetadata, selector: string, options: types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- if (!this._page.browserContext._options.hasTouch)- throw new Error('The page does not support tap. Use hasTouch context option to enable touch support.');- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._tap(progress, options)));- }, options.timeout);+ async tap(progress: Progress, selector: string, options: types.PointerActionWaitOptions) {+ if (!this._page.browserContext._options.hasTouch)+ throw new Error('The page does not support tap. Use hasTouch context option to enable touch support.');+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._tap(progress, options)));}- async fill(metadata: CallMetadata, selector: string, value: string, options: types.TimeoutOptions & types.StrictOptions & { force?: boolean }) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._fill(progress, value, options)));- }, options.timeout);+ async fill(progress: Progress, selector: string, value: string, options: types.StrictOptions & { force?: boolean }) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._fill(progress, value, options)));}- async focus(metadata: CallMetadata, selector: string, options: types.TimeoutOptions & types.StrictOptions) {- const controller = new ProgressController(metadata, this);- await controller.run(async progress => {- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._focus(progress)));- }, options.timeout);+ async focus(progress: Progress, selector: string, options: types.StrictOptions) {+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._focus(progress)));}- async blur(metadata: CallMetadata, selector: string, options: types.TimeoutOptions & types.StrictOptions) {- const controller = new ProgressController(metadata, this);- await controller.run(async progress => {- dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._blur(progress)));- }, options.timeout);+ async blur(progress: Progress, selector: string, options: types.StrictOptions) {+ dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._blur(progress)));}- async generateLocatorString(metadata: CallMetadata, selector: string): Promise<string | undefined> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const element = await progress.race(this.selectors.query(selector));- if (!element)- throw new Error(`No element matching ${this._asLocator(selector)}`);-- const generated = await progress.race(element.evaluateInUtility(async ([injected, node]) => {- return injected.generateSelectorSimple(node as unknown as Element);- }, {}));- if (!generated)- throw new Error(`Unable to generate locator for ${this._asLocator(selector)}`);-- let frame: Frame | null = element._frame;- const result = [generated];- while (frame?.parentFrame()) {- const frameElement = await progress.race(frame.frameElement());- if (frameElement) {- const generated = await progress.race(frameElement.evaluateInUtility(async ([injected, node]) => {- return injected.generateSelectorSimple(node as unknown as Element);- }, {}));- frameElement.dispose();- if (generated === 'error:notconnected' || !generated)- throw new Error(`Unable to generate locator for ${this._asLocator(selector)}`);- result.push(generated);- }- frame = frame.parentFrame();+ async generateLocatorString(progress: Progress, selector: string): Promise<string | undefined> {+ const element = await progress.race(this.selectors.query(selector));+ if (!element)+ throw new Error(`No element matching ${this._asLocator(selector)}`);++ const generated = await progress.race(element.evaluateInUtility(async ([injected, node]) => {+ return injected.generateSelectorSimple(node as unknown as Element);+ }, {}));+ if (!generated)+ throw new Error(`Unable to generate locator for ${this._asLocator(selector)}`);++ let frame: Frame | null = element._frame;+ const result = [generated];+ while (frame?.parentFrame()) {+ const frameElement = await progress.race(frame.frameElement());+ if (frameElement) {+ const generated = await progress.race(frameElement.evaluateInUtility(async ([injected, node]) => {+ return injected.generateSelectorSimple(node as unknown as Element);+ }, {}));+ frameElement.dispose();+ if (generated === 'error:notconnected' || !generated)+ throw new Error(`Unable to generate locator for ${this._asLocator(selector)}`);+ result.push(generated);}- return asLocator(this._page.browserContext._browser.sdkLanguage(), result.reverse().join(' >> internal:control=enter-frame >> '));- });+ frame = frame.parentFrame();+ }+ return asLocator(this._page.browserContext._browser.sdkLanguage(), result.reverse().join(' >> internal:control=enter-frame >> '));}- async textContent(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string | null> {- return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.textContent, undefined, options, scope);+ async textContent(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string | null> {+ return this._callOnElementOnceMatches(progress, selector, (injected, element) => element.textContent, undefined, options, scope);}- async innerText(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string> {- return this._callOnElementOnceMatches(metadata, selector, (injectedScript, element) => {+ async innerText(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string> {+ return this._callOnElementOnceMatches(progress, selector, (injectedScript, element) => {if (element.namespaceURI !== 'http://www.w3.org/1999/xhtml')throw injectedScript.createStacklessError('Node is not an HTMLElement');return (element as HTMLElement).innerText;}, undefined, options, scope);}- async innerHTML(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string> {- return this._callOnElementOnceMatches(metadata, selector, (injected, element) => element.innerHTML, undefined, options, scope);+ async innerHTML(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string> {+ return this._callOnElementOnceMatches(progress, selector, (injected, element) => element.innerHTML, undefined, options, scope);}- async getAttribute(metadata: CallMetadata, selector: string, name: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string | null> {- return this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => element.getAttribute(data.name), { name }, options, scope);+ async getAttribute(progress: Progress, selector: string, name: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<string | null> {+ return this._callOnElementOnceMatches(progress, selector, (injected, element, data) => element.getAttribute(data.name), { name }, options, scope);}- async inputValue(metadata: CallMetadata, selector: string, options: types.TimeoutOptions & types.StrictOptions, scope?: dom.ElementHandle): Promise<string> {- return this._callOnElementOnceMatches(metadata, selector, (injectedScript, node) => {+ async inputValue(progress: Progress, selector: string, options: types.StrictOptions, scope?: dom.ElementHandle): Promise<string> {+ return this._callOnElementOnceMatches(progress, selector, (injectedScript, node) => {const element = injectedScript.retarget(node, 'follow-label');if (!element || (element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA' && element.nodeName !== 'SELECT'))throw injectedScript.createStacklessError('Node is not an <input>, <textarea> or <select> element');@@ -1273,13 +1235,13 @@ export class Frame extends SdkObject {}, undefined, options, scope);}- async highlight(selector: string) {- const resolved = await this.selectors.resolveInjectedForSelector(selector);+ async highlight(progress: Progress, selector: string) {+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector));if (!resolved)return;- return await resolved.injected.evaluate((injected, { info }) => {+ return await progress.race(resolved.injected.evaluate((injected, { info }) => {return injected.highlight(info.parsed);- }, { info: resolved.info });+ }, { info: resolved.info }));}async hideHighlight() {@@ -1292,8 +1254,8 @@ export class Frame extends SdkObject {});}- private async _elementState(metadata: CallMetadata, selector: string, state: ElementStateWithoutStable, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {- const result = await this._callOnElementOnceMatches(metadata, selector, (injected, element, data) => {+ private async _elementState(progress: Progress, selector: string, state: ElementStateWithoutStable, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {+ const result = await this._callOnElementOnceMatches(progress, selector, (injected, element, data) => {return injected.elementState(element, data.state);}, { state }, options, scope);if (result.received === 'error:notconnected')@@ -1301,12 +1263,9 @@ export class Frame extends SdkObject {return result.matches;}- async isVisible(metadata: CallMetadata, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- progress.log(` checking visibility of ${this._asLocator(selector)}`);- return await this.isVisibleInternal(progress, selector, options, scope);- }, 0); // Note: isVisible is a one-shot operation without a timeout.+ async isVisible(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {+ progress.log(` checking visibility of ${this._asLocator(selector)}`);+ return await this.isVisibleInternal(progress, selector, options, scope);}async isVisibleInternal(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {@@ -1326,102 +1285,77 @@ export class Frame extends SdkObject {}}- async isHidden(metadata: CallMetadata, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {- return !(await this.isVisible(metadata, selector, options, scope));+ async isHidden(progress: Progress, selector: string, options: types.StrictOptions = {}, scope?: dom.ElementHandle): Promise<boolean> {+ return !(await this.isVisible(progress, selector, options, scope));}- async isDisabled(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {- return this._elementState(metadata, selector, 'disabled', options, scope);+ async isDisabled(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {+ return this._elementState(progress, selector, 'disabled', options, scope);}- async isEnabled(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {- return this._elementState(metadata, selector, 'enabled', options, scope);+ async isEnabled(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {+ return this._elementState(progress, selector, 'enabled', options, scope);}- async isEditable(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {- return this._elementState(metadata, selector, 'editable', options, scope);+ async isEditable(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {+ return this._elementState(progress, selector, 'editable', options, scope);}- async isChecked(metadata: CallMetadata, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {- return this._elementState(metadata, selector, 'checked', options, scope);+ async isChecked(progress: Progress, selector: string, options: types.QueryOnSelectorOptions, scope?: dom.ElementHandle): Promise<boolean> {+ return this._elementState(progress, selector, 'checked', options, scope);}- async hover(metadata: CallMetadata, selector: string, options: types.PointerActionOptions & types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._hover(progress, options)));- }, options.timeout);+ async hover(progress: Progress, selector: string, options: types.PointerActionOptions & types.PointerActionWaitOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._hover(progress, options)));}- async selectOption(metadata: CallMetadata, selector: string, elements: dom.ElementHandle[], values: types.SelectOption[], options: types.CommonActionOptions): Promise<string[]> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._selectOption(progress, elements, values, options));- }, options.timeout);+ async selectOption(progress: Progress, selector: string, elements: dom.ElementHandle[], values: types.SelectOption[], options: types.CommonActionOptions): Promise<string[]> {+ return await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._selectOption(progress, elements, values, options));}- async setInputFiles(metadata: CallMetadata, selector: string, params: channels.FrameSetInputFilesParams): Promise<channels.FrameSetInputFilesResult> {+ async setInputFiles(progress: Progress, selector: string, params: Omit<channels.FrameSetInputFilesParams, 'timeout'>): Promise<channels.FrameSetInputFilesResult> {const inputFileItems = await prepareFilesForUpload(this, params);- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true /* performActionPreChecks */, handle => handle._setInputFiles(progress, inputFileItems)));- }, params.timeout);+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, params.strict, true /* performActionPreChecks */, handle => handle._setInputFiles(progress, inputFileItems)));}- async type(metadata: CallMetadata, selector: string, text: string, options: { delay?: number } & types.TimeoutOptions & types.StrictOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._type(progress, text, options)));- }, options.timeout);+ async type(progress: Progress, selector: string, text: string, options: { delay?: number } & types.StrictOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._type(progress, text, options)));}- async press(metadata: CallMetadata, selector: string, key: string, options: { delay?: number, noWaitAfter?: boolean } & types.TimeoutOptions & types.StrictOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._press(progress, key, options)));- }, options.timeout);+ async press(progress: Progress, selector: string, key: string, options: { delay?: number, noWaitAfter?: boolean } & types.StrictOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, true /* performActionPreChecks */, handle => handle._press(progress, key, options)));}- async check(metadata: CallMetadata, selector: string, options: types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._setChecked(progress, true, options)));- }, options.timeout);+ async check(progress: Progress, selector: string, options: types.PointerActionWaitOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._setChecked(progress, true, options)));}- async uncheck(metadata: CallMetadata, selector: string, options: types.PointerActionWaitOptions) {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._setChecked(progress, false, options)));- }, options.timeout);+ async uncheck(progress: Progress, selector: string, options: types.PointerActionWaitOptions) {+ return dom.assertDone(await this._retryWithProgressIfNotConnected(progress, selector, options.strict, !options.force /* performActionPreChecks */, handle => handle._setChecked(progress, false, options)));}- async waitForTimeout(metadata: CallMetadata, timeout: number) {- const controller = new ProgressController(metadata, this);- return controller.run(progress => progress.wait(timeout));+ async waitForTimeout(progress: Progress, timeout: number) {+ // Silent catch to avoid the self-inflicted timeout error.+ return progress.wait(timeout).catch(() => {});}- async ariaSnapshot(metadata: CallMetadata, selector: string, options: { forAI?: boolean } & types.TimeoutOptions): Promise<string> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- return await this._retryWithProgressIfNotConnected(progress, selector, true /* strict */, true /* performActionPreChecks */, handle => progress.race(handle.ariaSnapshot(options)));- }, options.timeout);+ async ariaSnapshot(progress: Progress, selector: string, options: { forAI?: boolean }): Promise<string> {+ return await this._retryWithProgressIfNotConnected(progress, selector, true /* strict */, true /* performActionPreChecks */, handle => progress.race(handle.ariaSnapshot(options)));}- async expect(metadata: CallMetadata, selector: string | undefined, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {- const result = await this._expectImpl(metadata, selector, options);+ async expect(progress: Progress, selector: string | undefined, options: FrameExpectParams, timeout?: number): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {+ progress.log(`${renderTitleForCall(progress.metadata)}${timeout ? ` with timeout ${timeout}ms` : ''}`);+ const result = await this._expectImpl(progress, selector, options);// Library mode special case for the expect errors which are return values, not exceptions.if (result.matches === options.isNot)- metadata.error = { error: { name: 'Expect', message: 'Expect failed' } };+ progress.metadata.error = { error: { name: 'Expect', message: 'Expect failed' } };return result;}- private async _expectImpl(metadata: CallMetadata, selector: string | undefined, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {- const controller = new ProgressController(metadata, this);+ private async _expectImpl(progress: Progress, selector: string | undefined, options: FrameExpectParams): Promise<{ matches: boolean, received?: any, log?: string[], timedOut?: boolean }> {const lastIntermediateResult: { received?: any, isSet: boolean } = { isSet: false };- return await controller.run(async progress => {+ try {// Step 1: perform locator handlers checkpoint with a specified timeout.- progress.log(`${renderTitleForCall(metadata)}${options.timeout ? ` with timeout ${options.timeout}ms` : ''}`);if (selector)progress.log(`waiting for ${this._asLocator(selector)}`);await this._page.performActionPreChecks(progress);@@ -1453,18 +1387,18 @@ export class Frame extends SdkObject {}return { matches, received };});- }, options.timeout).catch(e => {+ } catch (e) {// Q: Why not throw upon isNonRetriableError(e) as in other places?// A: We want user to receive a friendly message containing the last intermediate result.if (js.isJavaScriptErrorInEvaluate(e) || isInvalidSelectorError(e))throw e;- const result: { matches: boolean, received?: any, log?: string[], timedOut?: boolean } = { matches: options.isNot, log: compressCallLog(metadata.log) };+ const result: { matches: boolean, received?: any, log?: string[], timedOut?: boolean } = { matches: options.isNot, log: compressCallLog(progress.metadata.log) };if (lastIntermediateResult.isSet)result.received = lastIntermediateResult.received;if (e instanceof TimeoutError)result.timedOut = true;return result;- });+ }}private async _expectInternal(progress: Progress, selector: string | undefined, options: FrameExpectParams, lastIntermediateResult: { received?: any, isSet: boolean }, noAbort: boolean) {@@ -1504,12 +1438,7 @@ export class Frame extends SdkObject {return { matches, received };}- async waitForFunctionExpression<R>(metadata: CallMetadata, expression: string, isFunction: boolean | undefined, arg: any, options: types.WaitForFunctionOptions): Promise<js.SmartHandle<R>> {- const controller = new ProgressController(metadata, this);- return controller.run(progress => this.waitForFunctionExpressionImpl(progress, expression, isFunction, arg, options, 'main'), options.timeout);- }-- async waitForFunctionExpressionImpl<R>(progress: Progress, expression: string, isFunction: boolean | undefined, arg: any, options: { pollingInterval?: number }, world: types.World = 'main'): Promise<js.SmartHandle<R>> {+ async waitForFunctionExpression<R>(progress: Progress, expression: string, isFunction: boolean | undefined, arg: any, options: { pollingInterval?: number }, world: types.World = 'main'): Promise<js.SmartHandle<R>> {if (typeof options.pollingInterval === 'number')assert(options.pollingInterval > 0, 'Cannot poll with non-positive interval: ' + options.pollingInterval);expression = js.normalizeEvaluationExpression(expression, isFunction);@@ -1574,7 +1503,7 @@ export class Frame extends SdkObject {return result;return JSON.stringify(result);}`;- const handle = await this.waitForFunctionExpressionImpl(progress, expression, true, undefined, {}, 'utility');+ const handle = await this.waitForFunctionExpression(progress, expression, true, undefined, {}, 'utility');return JSON.parse(handle.rawValue()) as R;}@@ -1611,33 +1540,30 @@ export class Frame extends SdkObject {this._parentFrame = null;}- private async _callOnElementOnceMatches<T, R>(metadata: CallMetadata, selector: string, body: ElementCallback<T, R>, taskData: T, options: types.TimeoutOptions & types.StrictOptions & { mainWorld?: boolean }, scope?: dom.ElementHandle): Promise<R> {- const controller = new ProgressController(metadata, this);- return controller.run(async progress => {- const callbackText = body.toString();- progress.log(`waiting for ${this._asLocator(selector)}`);- const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {- const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));- if (!resolved)- return continuePolling;- const { log, success, value } = await progress.race(resolved.injected.evaluate((injected, { info, callbackText, taskData, callId, root }) => {- const callback = injected.eval(callbackText) as ElementCallback<T, R>;- const element = injected.querySelector(info.parsed, root || document, info.strict);- if (!element)- return { success: false };- const log = ` locator resolved to ${injected.previewNode(element)}`;- if (callId)- injected.markTargetElements(new Set([element]), callId);- return { log, success: true, value: callback(injected, element, taskData as T) };- }, { info: resolved.info, callbackText, taskData, callId: progress.metadata.id, root: resolved.frame === this ? scope : undefined }));- if (log)- progress.log(log);- if (!success)- return continuePolling;- return value!;- });- return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;- }, options.timeout);+ private async _callOnElementOnceMatches<T, R>(progress: Progress, selector: string, body: ElementCallback<T, R>, taskData: T, options: types.StrictOptions & { mainWorld?: boolean }, scope?: dom.ElementHandle): Promise<R> {+ const callbackText = body.toString();+ progress.log(`waiting for ${this._asLocator(selector)}`);+ const promise = this.retryWithProgressAndTimeouts(progress, [0, 20, 50, 100, 100, 500], async continuePolling => {+ const resolved = await progress.race(this.selectors.resolveInjectedForSelector(selector, options, scope));+ if (!resolved)+ return continuePolling;+ const { log, success, value } = await progress.race(resolved.injected.evaluate((injected, { info, callbackText, taskData, callId, root }) => {+ const callback = injected.eval(callbackText) as ElementCallback<T, R>;+ const element = injected.querySelector(info.parsed, root || document, info.strict);+ if (!element)+ return { success: false };+ const log = ` locator resolved to ${injected.previewNode(element)}`;+ if (callId)+ injected.markTargetElements(new Set([element]), callId);+ return { log, success: true, value: callback(injected, element, taskData as T) };+ }, { info: resolved.info, callbackText, taskData, callId: progress.metadata.id, root: resolved.frame === this ? scope : undefined }));+ if (log)+ progress.log(log);+ if (!success)+ return continuePolling;+ return value!;+ });+ return scope ? scope._context._raceAgainstContextDestroyed(promise) : promise;}private _setContext(world: types.World, context: dom.FrameExecutionContext | null) {diff --git a/packages/playwright-core/src/server/page.ts b/packages/playwright-core/src/server/page.tsindex 59d5bce46c..2570793a9d 100644--- a/packages/playwright-core/src/server/page.ts+++ b/packages/playwright-core/src/server/page.ts@@ -489,7 +489,7 @@ export class Page extends SdkObject {const promise = handler.resolved.then(async () => {if (!handler.noWaitAfter) {progress.log(` locator handler has finished, waiting for ${asLocator(this.browserContext._browser.sdkLanguage(), handler.selector)} to be hidden`);- await this.mainFrame().waitForSelectorInternal(progress, handler.selector, false, { state: 'hidden' });+ await this.mainFrame().waitForSelector(progress, handler.selector, false, { state: 'hidden' });} else {progress.log(` locator handler has finished`);}diff --git a/packages/playwright-core/src/server/progress.ts b/packages/playwright-core/src/server/progress.tsindex fe68078572..f427ff0182 100644--- a/packages/playwright-core/src/server/progress.ts+++ b/packages/playwright-core/src/server/progress.ts@@ -18,36 +18,11 @@ import { TimeoutError } from './errors';import { assert, monotonicTime } from '../utils';import { ManualPromise } from '../utils/isomorphic/manualPromise';+import type { Progress } from '@protocol/progress';import type { CallMetadata, Instrumentation, SdkObject } from './instrumentation';import type { LogName } from './utils/debugLogger';-// Most server operations are run inside a Progress instance.-// Each method that takes a Progress must result in one of the three outcomes:-// - It finishes successfully, returning a value, before the Progress is aborted.-// - It throws some error, before the Progress is aborted.-// - It throws the Progress's aborted error, because the Progress was aborted before-// the method could finish.-// As a rule of thumb, the above is achieved by:-// - Passing the Progress instance when awaiting other methods.-// - Using `progress.race()` when awaiting other methods that do not take a Progress argument.-// In this case, it is important that awaited method has no side effects, for example-// it is a read-only browser protocol call.-// - In rare cases, when the awaited method does not take a Progress argument,-// but it does have side effects such as creating a page - a proper cleanup-// must be taken in case Progress is aborted before the awaited method finishes.-// That's usually done by `progress.raceWithCleanup()` or `progress.cleanupWhenAborted()`.-export interface Progress {- log(message: string): void;- cleanupWhenAborted(cleanup: (error: Error | undefined) => any): void;- race<T>(promise: Promise<T> | Promise<T>[]): Promise<T>;- raceWithCleanup<T>(promise: Promise<T>, cleanup: (result: T) => any): Promise<T>;- wait(timeout: number): Promise<void>;- metadata: CallMetadata;-- // Legacy lenient mode api only. To be removed.- legacyDisableTimeout(): void;- legacyEnableTimeout(): void;-}+export type { Progress } from '@protocol/progress';export class ProgressController {private _forceAbortPromise = new ManualPromise<any>();diff --git a/packages/playwright-core/src/server/recorder/recorderApp.ts b/packages/playwright-core/src/server/recorder/recorderApp.tsindex 5f69e225f2..a4862fb2fe 100644--- a/packages/playwright-core/src/server/recorder/recorderApp.ts+++ b/packages/playwright-core/src/server/recorder/recorderApp.ts@@ -91,7 +91,8 @@ export class RecorderApp extends EventEmitter implements IRecorderApp {});const mainFrame = this._page.mainFrame();- await mainFrame.goto(serverSideCallMetadata(), process.env.PW_HMR ? 'http://localhost:44225' : 'https://playwright/index.html', { timeout: 0 });+ const controller = new ProgressController(serverSideCallMetadata(), mainFrame);+ await controller.run(progress => mainFrame.goto(progress, process.env.PW_HMR ? 'http://localhost:44225' : 'https://playwright/index.html'));}static factory(context: BrowserContext): IRecorderAppFactory {diff --git a/packages/playwright-core/src/server/recorder/recorderRunner.ts b/packages/playwright-core/src/server/recorder/recorderRunner.tsindex 5253643e6d..474350ca24 100644--- a/packages/playwright-core/src/server/recorder/recorderRunner.ts+++ b/packages/playwright-core/src/server/recorder/recorderRunner.ts@@ -18,20 +18,26 @@ import { serializeExpectedTextValues } from '../../utils';import { toKeyboardModifiers } from '../codegen/language';import { serverSideCallMetadata } from '../instrumentation';import { buildFullSelector, mainFrameForAction } from './recorderUtils';+import { Progress, ProgressController } from '../progress';import type { Page } from '../page';import type * as types from '../types';import type * as actions from '@recorder/actions';+import type { Frame } from '../frames';export async function performAction(pageAliases: Map<Page, string>, actionInContext: actions.ActionInContext) {const callMetadata = serverSideCallMetadata();const mainFrame = mainFrameForAction(pageAliases, actionInContext);- const { action } = actionInContext;-+ const controller = new ProgressController(callMetadata, mainFrame);const kActionTimeout = 5000;+ return await controller.run(progress => performActionImpl(progress, mainFrame, actionInContext), kActionTimeout);+}++async function performActionImpl(progress: Progress, mainFrame: Frame, actionInContext: actions.ActionInContext) {+ const { action } = actionInContext;if (action.name === 'navigate') {- await mainFrame.goto(callMetadata, action.url, { timeout: kActionTimeout });+ await mainFrame.goto(progress, action.url);return;}@@ -47,82 +53,78 @@ export async function performAction(pageAliases: Map<Page, string>, actionInContif (action.name === 'click') {const options = toClickOptions(action);- await mainFrame.click(callMetadata, selector, { ...options, timeout: kActionTimeout, strict: true });+ await mainFrame.click(progress, selector, { ...options, strict: true });return;}if (action.name === 'press') {const modifiers = toKeyboardModifiers(action.modifiers);const shortcut = [...modifiers, action.key].join('+');- await mainFrame.press(callMetadata, selector, shortcut, { timeout: kActionTimeout, strict: true });+ await mainFrame.press(progress, selector, shortcut, { strict: true });return;}if (action.name === 'fill') {- await mainFrame.fill(callMetadata, selector, action.text, { timeout: kActionTimeout, strict: true });+ await mainFrame.fill(progress, selector, action.text, { strict: true });return;}if (action.name === 'setInputFiles') {- await mainFrame.setInputFiles(callMetadata, selector, { selector, payloads: [], timeout: kActionTimeout, strict: true });+ await mainFrame.setInputFiles(progress, selector, { selector, payloads: [], strict: true });return;}if (action.name === 'check') {- await mainFrame.check(callMetadata, selector, { timeout: kActionTimeout, strict: true });+ await mainFrame.check(progress, selector, { strict: true });return;}if (action.name === 'uncheck') {- await mainFrame.uncheck(callMetadata, selector, { timeout: kActionTimeout, strict: true });+ await mainFrame.uncheck(progress, selector, { strict: true });return;}if (action.name === 'select') {const values = action.options.map(value => ({ value }));- await mainFrame.selectOption(callMetadata, selector, [], values, { timeout: kActionTimeout, strict: true });+ await mainFrame.selectOption(progress, selector, [], values, { strict: true });return;}if (action.name === 'assertChecked') {- await mainFrame.expect(callMetadata, selector, {+ await mainFrame.expect(progress, selector, {selector,expression: 'to.be.checked',expectedValue: { checked: action.checked },isNot: !action.checked,- timeout: kActionTimeout,});return;}if (action.name === 'assertText') {- await mainFrame.expect(callMetadata, selector, {+ await mainFrame.expect(progress, selector, {selector,expression: 'to.have.text',expectedText: serializeExpectedTextValues([action.text], { matchSubstring: true, normalizeWhiteSpace: true }),isNot: false,- timeout: kActionTimeout,});return;}if (action.name === 'assertValue') {- await mainFrame.expect(callMetadata, selector, {+ await mainFrame.expect(progress, selector, {selector,expression: 'to.have.value',expectedValue: action.value,isNot: false,- timeout: kActionTimeout,});return;}if (action.name === 'assertVisible') {- await mainFrame.expect(callMetadata, selector, {+ await mainFrame.expect(progress, selector, {selector,expression: 'to.be.visible',isNot: false,- timeout: kActionTimeout,});return;}diff --git a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts b/packages/playwright-core/src/server/trace/viewer/traceViewer.tsindex 68a5fdd5c7..50e939d71b 100644--- a/packages/playwright-core/src/server/trace/viewer/traceViewer.ts+++ b/packages/playwright-core/src/server/trace/viewer/traceViewer.ts@@ -183,18 +183,18 @@ export async function openTraceViewerApp(url: string, browserName: string, optioconst controller = new ProgressController(serverSideCallMetadata(), context._browser);await controller.run(async progress => {await context._browser._defaultContext!._loadDefaultContextAsIs(progress);- });- if (process.env.PWTEST_PRINT_WS_ENDPOINT)- process.stderr.write('DevTools listening on: ' + context._browser.options.wsEndpoint + '\n');+ if (process.env.PWTEST_PRINT_WS_ENDPOINT)+ process.stderr.write('DevTools listening on: ' + context._browser.options.wsEndpoint + '\n');- if (!isUnderTest())- await syncLocalStorageWithSettings(page, 'traceviewer');+ if (!isUnderTest())+ await syncLocalStorageWithSettings(page, 'traceviewer');- if (isUnderTest())- page.on('close', () => context.close({ reason: 'Trace viewer closed' }).catch(() => {}));+ if (isUnderTest())+ page.on('close', () => context.close({ reason: 'Trace viewer closed' }).catch(() => {}));- await page.mainFrame().goto(serverSideCallMetadata(), url, { timeout: 0 });+ await page.mainFrame().goto(progress, url);+ });return page;}diff --git a/packages/playwright-core/src/server/types.ts b/packages/playwright-core/src/server/types.tsindex f0c6ec3655..50bdec8101 100644--- a/packages/playwright-core/src/server/types.ts+++ b/packages/playwright-core/src/server/types.ts@@ -25,9 +25,9 @@ export type StrictOptions = {strict?: boolean,};-export type QueryOnSelectorOptions = StrictOptions & TimeoutOptions;+export type QueryOnSelectorOptions = StrictOptions;-export type WaitForElementOptions = TimeoutOptions & StrictOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' } & { omitReturnValue?: boolean };+export type WaitForElementOptions = StrictOptions & { state?: 'attached' | 'detached' | 'visible' | 'hidden' } & { omitReturnValue?: boolean };export type WaitForFunctionOptions = TimeoutOptions & { pollingInterval?: number };@@ -38,7 +38,7 @@ export type NavigateOptions = TimeoutOptions & {waitUntil?: LifecycleEvent,};-export type CommonActionOptions = TimeoutOptions & StrictOptions & {+export type CommonActionOptions = StrictOptions & {force?: boolean,};@@ -133,7 +133,7 @@ export type MouseMultiClickOptions = PointerActionOptions & {export type World = 'main' | 'utility';-export type GotoOptions = NavigateOptions & {+export type GotoOptions = Omit<NavigateOptions, 'timeout'> & {referer?: string,};diff --git a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.tsindex 2075f076dd..3c8769d3ad 100644--- a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts+++ b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts@@ -309,3 +309,8 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri['JsonPipe.send', { internal: true, }],['JsonPipe.close', { internal: true, }]]);++export const progressTypes = new Set<string>([+ 'Frame',+ 'ElementHandle'+]);diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.tsindex 0424cd4745..fa9302563a 100644--- a/packages/protocol/src/channels.d.ts+++ b/packages/protocol/src/channels.d.ts@@ -17,6 +17,7 @@// This file is generated by generate_channels.js, do not edit manually.import type { CallMetadata } from './callMetadata';+import type { Progress } from './progress';export type Binary = Buffer;@@ -2618,53 +2619,53 @@ export interface FrameEventTarget {}export interface FrameChannel extends FrameEventTarget, Channel {_type_Frame: boolean;- evalOnSelector(params: FrameEvalOnSelectorParams, metadata?: CallMetadata): Promise<FrameEvalOnSelectorResult>;- evalOnSelectorAll(params: FrameEvalOnSelectorAllParams, metadata?: CallMetadata): Promise<FrameEvalOnSelectorAllResult>;- addScriptTag(params: FrameAddScriptTagParams, metadata?: CallMetadata): Promise<FrameAddScriptTagResult>;- addStyleTag(params: FrameAddStyleTagParams, metadata?: CallMetadata): Promise<FrameAddStyleTagResult>;- ariaSnapshot(params: FrameAriaSnapshotParams, metadata?: CallMetadata): Promise<FrameAriaSnapshotResult>;- blur(params: FrameBlurParams, metadata?: CallMetadata): Promise<FrameBlurResult>;- check(params: FrameCheckParams, metadata?: CallMetadata): Promise<FrameCheckResult>;- click(params: FrameClickParams, metadata?: CallMetadata): Promise<FrameClickResult>;- content(params?: FrameContentParams, metadata?: CallMetadata): Promise<FrameContentResult>;- dragAndDrop(params: FrameDragAndDropParams, metadata?: CallMetadata): Promise<FrameDragAndDropResult>;- dblclick(params: FrameDblclickParams, metadata?: CallMetadata): Promise<FrameDblclickResult>;- dispatchEvent(params: FrameDispatchEventParams, metadata?: CallMetadata): Promise<FrameDispatchEventResult>;- evaluateExpression(params: FrameEvaluateExpressionParams, metadata?: CallMetadata): Promise<FrameEvaluateExpressionResult>;- evaluateExpressionHandle(params: FrameEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise<FrameEvaluateExpressionHandleResult>;- fill(params: FrameFillParams, metadata?: CallMetadata): Promise<FrameFillResult>;- focus(params: FrameFocusParams, metadata?: CallMetadata): Promise<FrameFocusResult>;- frameElement(params?: FrameFrameElementParams, metadata?: CallMetadata): Promise<FrameFrameElementResult>;- generateLocatorString(params: FrameGenerateLocatorStringParams, metadata?: CallMetadata): Promise<FrameGenerateLocatorStringResult>;- highlight(params: FrameHighlightParams, metadata?: CallMetadata): Promise<FrameHighlightResult>;- getAttribute(params: FrameGetAttributeParams, metadata?: CallMetadata): Promise<FrameGetAttributeResult>;- goto(params: FrameGotoParams, metadata?: CallMetadata): Promise<FrameGotoResult>;- hover(params: FrameHoverParams, metadata?: CallMetadata): Promise<FrameHoverResult>;- innerHTML(params: FrameInnerHTMLParams, metadata?: CallMetadata): Promise<FrameInnerHTMLResult>;- innerText(params: FrameInnerTextParams, metadata?: CallMetadata): Promise<FrameInnerTextResult>;- inputValue(params: FrameInputValueParams, metadata?: CallMetadata): Promise<FrameInputValueResult>;- isChecked(params: FrameIsCheckedParams, metadata?: CallMetadata): Promise<FrameIsCheckedResult>;- isDisabled(params: FrameIsDisabledParams, metadata?: CallMetadata): Promise<FrameIsDisabledResult>;- isEnabled(params: FrameIsEnabledParams, metadata?: CallMetadata): Promise<FrameIsEnabledResult>;- isHidden(params: FrameIsHiddenParams, metadata?: CallMetadata): Promise<FrameIsHiddenResult>;- isVisible(params: FrameIsVisibleParams, metadata?: CallMetadata): Promise<FrameIsVisibleResult>;- isEditable(params: FrameIsEditableParams, metadata?: CallMetadata): Promise<FrameIsEditableResult>;- press(params: FramePressParams, metadata?: CallMetadata): Promise<FramePressResult>;- querySelector(params: FrameQuerySelectorParams, metadata?: CallMetadata): Promise<FrameQuerySelectorResult>;- querySelectorAll(params: FrameQuerySelectorAllParams, metadata?: CallMetadata): Promise<FrameQuerySelectorAllResult>;- queryCount(params: FrameQueryCountParams, metadata?: CallMetadata): Promise<FrameQueryCountResult>;- selectOption(params: FrameSelectOptionParams, metadata?: CallMetadata): Promise<FrameSelectOptionResult>;- setContent(params: FrameSetContentParams, metadata?: CallMetadata): Promise<FrameSetContentResult>;- setInputFiles(params: FrameSetInputFilesParams, metadata?: CallMetadata): Promise<FrameSetInputFilesResult>;- tap(params: FrameTapParams, metadata?: CallMetadata): Promise<FrameTapResult>;- textContent(params: FrameTextContentParams, metadata?: CallMetadata): Promise<FrameTextContentResult>;- title(params?: FrameTitleParams, metadata?: CallMetadata): Promise<FrameTitleResult>;- type(params: FrameTypeParams, metadata?: CallMetadata): Promise<FrameTypeResult>;- uncheck(params: FrameUncheckParams, metadata?: CallMetadata): Promise<FrameUncheckResult>;- waitForTimeout(params: FrameWaitForTimeoutParams, metadata?: CallMetadata): Promise<FrameWaitForTimeoutResult>;- waitForFunction(params: FrameWaitForFunctionParams, metadata?: CallMetadata): Promise<FrameWaitForFunctionResult>;- waitForSelector(params: FrameWaitForSelectorParams, metadata?: CallMetadata): Promise<FrameWaitForSelectorResult>;- expect(params: FrameExpectParams, metadata?: CallMetadata): Promise<FrameExpectResult>;+ evalOnSelector(params: FrameEvalOnSelectorParams, progress?: Progress): Promise<FrameEvalOnSelectorResult>;+ evalOnSelectorAll(params: FrameEvalOnSelectorAllParams, progress?: Progress): Promise<FrameEvalOnSelectorAllResult>;+ addScriptTag(params: FrameAddScriptTagParams, progress?: Progress): Promise<FrameAddScriptTagResult>;+ addStyleTag(params: FrameAddStyleTagParams, progress?: Progress): Promise<FrameAddStyleTagResult>;+ ariaSnapshot(params: FrameAriaSnapshotParams, progress?: Progress): Promise<FrameAriaSnapshotResult>;+ blur(params: FrameBlurParams, progress?: Progress): Promise<FrameBlurResult>;+ check(params: FrameCheckParams, progress?: Progress): Promise<FrameCheckResult>;+ click(params: FrameClickParams, progress?: Progress): Promise<FrameClickResult>;+ content(params?: FrameContentParams, progress?: Progress): Promise<FrameContentResult>;+ dragAndDrop(params: FrameDragAndDropParams, progress?: Progress): Promise<FrameDragAndDropResult>;+ dblclick(params: FrameDblclickParams, progress?: Progress): Promise<FrameDblclickResult>;+ dispatchEvent(params: FrameDispatchEventParams, progress?: Progress): Promise<FrameDispatchEventResult>;+ evaluateExpression(params: FrameEvaluateExpressionParams, progress?: Progress): Promise<FrameEvaluateExpressionResult>;+ evaluateExpressionHandle(params: FrameEvaluateExpressionHandleParams, progress?: Progress): Promise<FrameEvaluateExpressionHandleResult>;+ fill(params: FrameFillParams, progress?: Progress): Promise<FrameFillResult>;+ focus(params: FrameFocusParams, progress?: Progress): Promise<FrameFocusResult>;+ frameElement(params?: FrameFrameElementParams, progress?: Progress): Promise<FrameFrameElementResult>;+ generateLocatorString(params: FrameGenerateLocatorStringParams, progress?: Progress): Promise<FrameGenerateLocatorStringResult>;+ highlight(params: FrameHighlightParams, progress?: Progress): Promise<FrameHighlightResult>;+ getAttribute(params: FrameGetAttributeParams, progress?: Progress): Promise<FrameGetAttributeResult>;+ goto(params: FrameGotoParams, progress?: Progress): Promise<FrameGotoResult>;+ hover(params: FrameHoverParams, progress?: Progress): Promise<FrameHoverResult>;+ innerHTML(params: FrameInnerHTMLParams, progress?: Progress): Promise<FrameInnerHTMLResult>;+ innerText(params: FrameInnerTextParams, progress?: Progress): Promise<FrameInnerTextResult>;+ inputValue(params: FrameInputValueParams, progress?: Progress): Promise<FrameInputValueResult>;+ isChecked(params: FrameIsCheckedParams, progress?: Progress): Promise<FrameIsCheckedResult>;+ isDisabled(params: FrameIsDisabledParams, progress?: Progress): Promise<FrameIsDisabledResult>;+ isEnabled(params: FrameIsEnabledParams, progress?: Progress): Promise<FrameIsEnabledResult>;+ isHidden(params: FrameIsHiddenParams, progress?: Progress): Promise<FrameIsHiddenResult>;+ isVisible(params: FrameIsVisibleParams, progress?: Progress): Promise<FrameIsVisibleResult>;+ isEditable(params: FrameIsEditableParams, progress?: Progress): Promise<FrameIsEditableResult>;+ press(params: FramePressParams, progress?: Progress): Promise<FramePressResult>;+ querySelector(params: FrameQuerySelectorParams, progress?: Progress): Promise<FrameQuerySelectorResult>;+ querySelectorAll(params: FrameQuerySelectorAllParams, progress?: Progress): Promise<FrameQuerySelectorAllResult>;+ queryCount(params: FrameQueryCountParams, progress?: Progress): Promise<FrameQueryCountResult>;+ selectOption(params: FrameSelectOptionParams, progress?: Progress): Promise<FrameSelectOptionResult>;+ setContent(params: FrameSetContentParams, progress?: Progress): Promise<FrameSetContentResult>;+ setInputFiles(params: FrameSetInputFilesParams, progress?: Progress): Promise<FrameSetInputFilesResult>;+ tap(params: FrameTapParams, progress?: Progress): Promise<FrameTapResult>;+ textContent(params: FrameTextContentParams, progress?: Progress): Promise<FrameTextContentResult>;+ title(params?: FrameTitleParams, progress?: Progress): Promise<FrameTitleResult>;+ type(params: FrameTypeParams, progress?: Progress): Promise<FrameTypeResult>;+ uncheck(params: FrameUncheckParams, progress?: Progress): Promise<FrameUncheckResult>;+ waitForTimeout(params: FrameWaitForTimeoutParams, progress?: Progress): Promise<FrameWaitForTimeoutResult>;+ waitForFunction(params: FrameWaitForFunctionParams, progress?: Progress): Promise<FrameWaitForFunctionResult>;+ waitForSelector(params: FrameWaitForSelectorParams, progress?: Progress): Promise<FrameWaitForSelectorResult>;+ expect(params: FrameExpectParams, progress?: Progress): Promise<FrameExpectResult>;}export type FrameLoadstateEvent = {add?: LifecycleEvent,@@ -3395,42 +3396,42 @@ export interface ElementHandleEventTarget {}export interface ElementHandleChannel extends ElementHandleEventTarget, JSHandleChannel {_type_ElementHandle: boolean;- evalOnSelector(params: ElementHandleEvalOnSelectorParams, metadata?: CallMetadata): Promise<ElementHandleEvalOnSelectorResult>;- evalOnSelectorAll(params: ElementHandleEvalOnSelectorAllParams, metadata?: CallMetadata): Promise<ElementHandleEvalOnSelectorAllResult>;- boundingBox(params?: ElementHandleBoundingBoxParams, metadata?: CallMetadata): Promise<ElementHandleBoundingBoxResult>;- check(params: ElementHandleCheckParams, metadata?: CallMetadata): Promise<ElementHandleCheckResult>;- click(params: ElementHandleClickParams, metadata?: CallMetadata): Promise<ElementHandleClickResult>;- contentFrame(params?: ElementHandleContentFrameParams, metadata?: CallMetadata): Promise<ElementHandleContentFrameResult>;- dblclick(params: ElementHandleDblclickParams, metadata?: CallMetadata): Promise<ElementHandleDblclickResult>;- dispatchEvent(params: ElementHandleDispatchEventParams, metadata?: CallMetadata): Promise<ElementHandleDispatchEventResult>;- fill(params: ElementHandleFillParams, metadata?: CallMetadata): Promise<ElementHandleFillResult>;- focus(params?: ElementHandleFocusParams, metadata?: CallMetadata): Promise<ElementHandleFocusResult>;- getAttribute(params: ElementHandleGetAttributeParams, metadata?: CallMetadata): Promise<ElementHandleGetAttributeResult>;- hover(params: ElementHandleHoverParams, metadata?: CallMetadata): Promise<ElementHandleHoverResult>;- innerHTML(params?: ElementHandleInnerHTMLParams, metadata?: CallMetadata): Promise<ElementHandleInnerHTMLResult>;- innerText(params?: ElementHandleInnerTextParams, metadata?: CallMetadata): Promise<ElementHandleInnerTextResult>;- inputValue(params?: ElementHandleInputValueParams, metadata?: CallMetadata): Promise<ElementHandleInputValueResult>;- isChecked(params?: ElementHandleIsCheckedParams, metadata?: CallMetadata): Promise<ElementHandleIsCheckedResult>;- isDisabled(params?: ElementHandleIsDisabledParams, metadata?: CallMetadata): Promise<ElementHandleIsDisabledResult>;- isEditable(params?: ElementHandleIsEditableParams, metadata?: CallMetadata): Promise<ElementHandleIsEditableResult>;- isEnabled(params?: ElementHandleIsEnabledParams, metadata?: CallMetadata): Promise<ElementHandleIsEnabledResult>;- isHidden(params?: ElementHandleIsHiddenParams, metadata?: CallMetadata): Promise<ElementHandleIsHiddenResult>;- isVisible(params?: ElementHandleIsVisibleParams, metadata?: CallMetadata): Promise<ElementHandleIsVisibleResult>;- ownerFrame(params?: ElementHandleOwnerFrameParams, metadata?: CallMetadata): Promise<ElementHandleOwnerFrameResult>;- press(params: ElementHandlePressParams, metadata?: CallMetadata): Promise<ElementHandlePressResult>;- querySelector(params: ElementHandleQuerySelectorParams, metadata?: CallMetadata): Promise<ElementHandleQuerySelectorResult>;- querySelectorAll(params: ElementHandleQuerySelectorAllParams, metadata?: CallMetadata): Promise<ElementHandleQuerySelectorAllResult>;- screenshot(params: ElementHandleScreenshotParams, metadata?: CallMetadata): Promise<ElementHandleScreenshotResult>;- scrollIntoViewIfNeeded(params: ElementHandleScrollIntoViewIfNeededParams, metadata?: CallMetadata): Promise<ElementHandleScrollIntoViewIfNeededResult>;- selectOption(params: ElementHandleSelectOptionParams, metadata?: CallMetadata): Promise<ElementHandleSelectOptionResult>;- selectText(params: ElementHandleSelectTextParams, metadata?: CallMetadata): Promise<ElementHandleSelectTextResult>;- setInputFiles(params: ElementHandleSetInputFilesParams, metadata?: CallMetadata): Promise<ElementHandleSetInputFilesResult>;- tap(params: ElementHandleTapParams, metadata?: CallMetadata): Promise<ElementHandleTapResult>;- textContent(params?: ElementHandleTextContentParams, metadata?: CallMetadata): Promise<ElementHandleTextContentResult>;- type(params: ElementHandleTypeParams, metadata?: CallMetadata): Promise<ElementHandleTypeResult>;- uncheck(params: ElementHandleUncheckParams, metadata?: CallMetadata): Promise<ElementHandleUncheckResult>;- waitForElementState(params: ElementHandleWaitForElementStateParams, metadata?: CallMetadata): Promise<ElementHandleWaitForElementStateResult>;- waitForSelector(params: ElementHandleWaitForSelectorParams, metadata?: CallMetadata): Promise<ElementHandleWaitForSelectorResult>;+ evalOnSelector(params: ElementHandleEvalOnSelectorParams, progress?: Progress): Promise<ElementHandleEvalOnSelectorResult>;+ evalOnSelectorAll(params: ElementHandleEvalOnSelectorAllParams, progress?: Progress): Promise<ElementHandleEvalOnSelectorAllResult>;+ boundingBox(params?: ElementHandleBoundingBoxParams, progress?: Progress): Promise<ElementHandleBoundingBoxResult>;+ check(params: ElementHandleCheckParams, progress?: Progress): Promise<ElementHandleCheckResult>;+ click(params: ElementHandleClickParams, progress?: Progress): Promise<ElementHandleClickResult>;+ contentFrame(params?: ElementHandleContentFrameParams, progress?: Progress): Promise<ElementHandleContentFrameResult>;+ dblclick(params: ElementHandleDblclickParams, progress?: Progress): Promise<ElementHandleDblclickResult>;+ dispatchEvent(params: ElementHandleDispatchEventParams, progress?: Progress): Promise<ElementHandleDispatchEventResult>;+ fill(params: ElementHandleFillParams, progress?: Progress): Promise<ElementHandleFillResult>;+ focus(params?: ElementHandleFocusParams, progress?: Progress): Promise<ElementHandleFocusResult>;+ getAttribute(params: ElementHandleGetAttributeParams, progress?: Progress): Promise<ElementHandleGetAttributeResult>;+ hover(params: ElementHandleHoverParams, progress?: Progress): Promise<ElementHandleHoverResult>;+ innerHTML(params?: ElementHandleInnerHTMLParams, progress?: Progress): Promise<ElementHandleInnerHTMLResult>;+ innerText(params?: ElementHandleInnerTextParams, progress?: Progress): Promise<ElementHandleInnerTextResult>;+ inputValue(params?: ElementHandleInputValueParams, progress?: Progress): Promise<ElementHandleInputValueResult>;+ isChecked(params?: ElementHandleIsCheckedParams, progress?: Progress): Promise<ElementHandleIsCheckedResult>;+ isDisabled(params?: ElementHandleIsDisabledParams, progress?: Progress): Promise<ElementHandleIsDisabledResult>;+ isEditable(params?: ElementHandleIsEditableParams, progress?: Progress): Promise<ElementHandleIsEditableResult>;+ isEnabled(params?: ElementHandleIsEnabledParams, progress?: Progress): Promise<ElementHandleIsEnabledResult>;+ isHidden(params?: ElementHandleIsHiddenParams, progress?: Progress): Promise<ElementHandleIsHiddenResult>;+ isVisible(params?: ElementHandleIsVisibleParams, progress?: Progress): Promise<ElementHandleIsVisibleResult>;+ ownerFrame(params?: ElementHandleOwnerFrameParams, progress?: Progress): Promise<ElementHandleOwnerFrameResult>;+ press(params: ElementHandlePressParams, progress?: Progress): Promise<ElementHandlePressResult>;+ querySelector(params: ElementHandleQuerySelectorParams, progress?: Progress): Promise<ElementHandleQuerySelectorResult>;+ querySelectorAll(params: ElementHandleQuerySelectorAllParams, progress?: Progress): Promise<ElementHandleQuerySelectorAllResult>;+ screenshot(params: ElementHandleScreenshotParams, progress?: Progress): Promise<ElementHandleScreenshotResult>;+ scrollIntoViewIfNeeded(params: ElementHandleScrollIntoViewIfNeededParams, progress?: Progress): Promise<ElementHandleScrollIntoViewIfNeededResult>;+ selectOption(params: ElementHandleSelectOptionParams, progress?: Progress): Promise<ElementHandleSelectOptionResult>;+ selectText(params: ElementHandleSelectTextParams, progress?: Progress): Promise<ElementHandleSelectTextResult>;+ setInputFiles(params: ElementHandleSetInputFilesParams, progress?: Progress): Promise<ElementHandleSetInputFilesResult>;+ tap(params: ElementHandleTapParams, progress?: Progress): Promise<ElementHandleTapResult>;+ textContent(params?: ElementHandleTextContentParams, progress?: Progress): Promise<ElementHandleTextContentResult>;+ type(params: ElementHandleTypeParams, progress?: Progress): Promise<ElementHandleTypeResult>;+ uncheck(params: ElementHandleUncheckParams, progress?: Progress): Promise<ElementHandleUncheckResult>;+ waitForElementState(params: ElementHandleWaitForElementStateParams, progress?: Progress): Promise<ElementHandleWaitForElementStateResult>;+ waitForSelector(params: ElementHandleWaitForSelectorParams, progress?: Progress): Promise<ElementHandleWaitForSelectorResult>;}export type ElementHandleEvalOnSelectorParams = {selector: string,diff --git a/packages/protocol/src/progress.d.ts b/packages/protocol/src/progress.d.tsnew file mode 100644index 0000000000..586b774cac--- /dev/null+++ b/packages/protocol/src/progress.d.ts@@ -0,0 +1,45 @@+/**+ * Copyright (c) Microsoft Corporation.+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */++import type { CallMetadata } from './callMetadata';++// Most server operations are run inside a Progress instance.+// Each method that takes a Progress must result in one of the three outcomes:+// - It finishes successfully, returning a value, before the Progress is aborted.+// - It throws some error, before the Progress is aborted.+// - It throws the Progress's aborted error, because the Progress was aborted before+// the method could finish.+// As a rule of thumb, the above is achieved by:+// - Passing the Progress instance when awaiting other methods.+// - Using `progress.race()` when awaiting other methods that do not take a Progress argument.+// In this case, it is important that awaited method has no side effects, for example+// it is a read-only browser protocol call.+// - In rare cases, when the awaited method does not take a Progress argument,+// but it does have side effects such as creating a page - a proper cleanup+// must be taken in case Progress is aborted before the awaited method finishes.+// That's usually done by `progress.raceWithCleanup()` or `progress.cleanupWhenAborted()`.+export interface Progress {+ log(message: string): void;+ cleanupWhenAborted(cleanup: (error: Error | undefined) => any): void;+ race<T>(promise: Promise<T> | Promise<T>[]): Promise<T>;+ raceWithCleanup<T>(promise: Promise<T>, cleanup: (result: T) => any): Promise<T>;+ wait(timeout: number): Promise<void>;+ metadata: CallMetadata;++ // Legacy lenient mode api only. To be removed.+ legacyDisableTimeout(): void;+ legacyEnableTimeout(): void;+}diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.ymlindex be56d9af82..33d0c97f67 100644--- a/packages/protocol/src/protocol.yml+++ b/packages/protocol/src/protocol.yml@@ -2048,6 +2048,7 @@ Page:Frame:type: interface+ progress: trueinitializer:url: string@@ -2419,6 +2420,7 @@ Frame:isHidden:title: Is hiddenparameters:+ # Note: compared to other isFoo methods, isHidden is a one-shot operation without a timeout.selector: stringstrict: boolean?returns:@@ -2429,6 +2431,7 @@ Frame:isVisible:title: Is visibleparameters:+ # Note: compared to other isFoo methods, isVisible is a one-shot operation without a timeout.selector: stringstrict: boolean?returns:@@ -2802,6 +2805,7 @@ JSHandle:ElementHandle:type: interface+ progress: trueextends: JSHandlediff --git a/utils/generate_channels.js b/utils/generate_channels.jsindex 3389f16275..6fff67a4b7 100755--- a/utils/generate_channels.js+++ b/utils/generate_channels.js@@ -126,6 +126,7 @@ const channels_ts = [// This file is generated by ${path.basename(__filename).split(path.sep).join(path.posix.sep)}, do not edit manually.import type { CallMetadata } from './callMetadata';+import type { Progress } from './progress';export type Binary = Buffer;@@ -178,6 +179,7 @@ const metainfo_ts = [`];const methodMetainfo = [];+const progressTypes = new Set();const yml = fs.readFileSync(path.join(__dirname, '..', 'packages', 'protocol', 'src', 'protocol.yml'), 'utf-8');const protocol = yaml.parse(yml);@@ -242,6 +244,10 @@ for (const [name, item] of Object.entries(protocol)) {const initializerName = channelName + 'Initializer';channels_ts.push(`export type ${initializerName} = ${init.ts};`);+ const useProgress = !!item.progress;+ if (useProgress)+ progressTypes.add(name);+let ancestorInit = init;let ancestor = item;while (!ancestor.initializer) {@@ -303,7 +309,8 @@ for (const [name, item] of Object.entries(protocol)) {for (const derived of derivedClasses.get(channelName) || [])addScheme(`${derived}${titleCase(methodName)}Result`, `tType('${resultName}')`);- channels_ts.push(` ${methodName}(params${method.parameters ? '' : '?'}: ${paramsName}, metadata?: CallMetadata): Promise<${resultName}>;`);+ const secondArg = useProgress ? `progress?: Progress` : 'metadata?: CallMetadata';+ channels_ts.push(` ${methodName}(params${method.parameters ? '' : '?'}: ${paramsName}, ${secondArg}): Promise<${resultName}>;`);}channels_ts.push(`}`);@@ -331,6 +338,9 @@ for (const [name, item] of Object.entries(protocol)) {metainfo_ts.push(`export const methodMetainfo = new Map<string, { internal?: boolean, title?: string, slowMo?: boolean, snapshot?: boolean, pausesBeforeInput?: boolean }>([${methodMetainfo.join(`,\n `)}]);`);+metainfo_ts.push(`\nexport const progressTypes = new Set<string>([+ ${[...progressTypes].map(s => `'${s}'`).join(`,\n `)}+]);`);let hasChanges = false;