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 2) (#36438)
Dmitry Gozmanbf5fea29f240
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.tsindex abc26fb66c..f556f83716 100644--- a/packages/playwright-core/src/server/browserContext.ts+++ b/packages/playwright-core/src/server/browserContext.ts@@ -196,7 +196,7 @@ export abstract class BrowserContext extends SdkObject {}async resetForReuseImpl(progress: Progress, params: channels.BrowserNewContextForReuseParams | null) {- await progress.race(this.tracing.resetForReuse());+ await this.tracing.resetForReuse(progress);if (params) {for (const key of paramsThatAllowContextReuse)diff --git a/packages/playwright-core/src/server/dispatchers/cdpSessionDispatcher.ts b/packages/playwright-core/src/server/dispatchers/cdpSessionDispatcher.tsindex 8263870039..58d785705e 100644--- a/packages/playwright-core/src/server/dispatchers/cdpSessionDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/cdpSessionDispatcher.ts@@ -19,8 +19,8 @@ import { CDPSession } from '../chromium/crConnection';import type { BrowserContextDispatcher } from './browserContextDispatcher';import type { BrowserDispatcher } from './browserDispatcher';-import type { CallMetadata } from '../instrumentation';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export class CDPSessionDispatcher extends Dispatcher<CDPSession, channels.CDPSessionChannel, BrowserDispatcher | BrowserContextDispatcher> implements channels.CDPSessionChannel {_type_CDPSession = true;@@ -31,12 +31,12 @@ export class CDPSessionDispatcher extends Dispatcher<CDPSession, channels.CDPSesthis.addObjectListener(CDPSession.Events.Closed, () => this._dispose());}- async send(params: channels.CDPSessionSendParams): Promise<channels.CDPSessionSendResult> {- return { result: await this._object.send(params.method as any, params.params) };+ async send(params: channels.CDPSessionSendParams, progress: Progress): Promise<channels.CDPSessionSendResult> {+ return { result: await progress.race(this._object.send(params.method as any, params.params)) };}- async detach(_: any, metadata: CallMetadata): Promise<void> {- metadata.potentiallyClosesScope = true;+ async detach(_: any, progress: Progress): Promise<void> {+ progress.metadata.potentiallyClosesScope = true;await this._object.detach();}}diff --git a/packages/playwright-core/src/server/dispatchers/dialogDispatcher.ts b/packages/playwright-core/src/server/dispatchers/dialogDispatcher.tsindex b86872b133..52a29691a2 100644--- a/packages/playwright-core/src/server/dispatchers/dialogDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/dialogDispatcher.ts@@ -20,6 +20,7 @@ import { PageDispatcher } from './pageDispatcher';import type { Dialog } from '../dialog';import type { BrowserContextDispatcher } from './browserContextDispatcher';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export class DialogDispatcher extends Dispatcher<Dialog, channels.DialogChannel, BrowserContextDispatcher | PageDispatcher> implements channels.DialogChannel {_type_Dialog = true;@@ -35,11 +36,11 @@ export class DialogDispatcher extends Dispatcher<Dialog, channels.DialogChannel,});}- async accept(params: { promptText?: string }): Promise<void> {- await this._object.accept(params.promptText);+ async accept(params: channels.DialogAcceptParams, progress: Progress): Promise<void> {+ await progress.race(this._object.accept(params.promptText));}- async dismiss(): Promise<void> {- await this._object.dismiss();+ async dismiss(params: channels.DialogDismissParams, progress: Progress): Promise<void> {+ await progress.race(this._object.dismiss());}}diff --git a/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts b/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.tsindex a35aa9171a..4bd068f373 100644--- a/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/jsHandleDispatcher.ts@@ -22,8 +22,8 @@ import type * as js from '../javascript';import type { ElectronApplicationDispatcher } from './electronDispatcher';import type { FrameDispatcher } from './frameDispatcher';import type { PageDispatcher, WorkerDispatcher } from './pageDispatcher';-import type { CallMetadata } from '../instrumentation';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export type JSHandleDispatcherParentScope = PageDispatcher | FrameDispatcher | WorkerDispatcher | ElectronApplicationDispatcher;@@ -42,24 +42,25 @@ export class JSHandleDispatcher<ParentScope extends JSHandleDispatcherParentScopjsHandle._setPreviewCallback(preview => this._dispatchEvent('previewUpdated', { preview }));}- async evaluateExpression(params: channels.JSHandleEvaluateExpressionParams): Promise<channels.JSHandleEvaluateExpressionResult> {- return { value: serializeResult(await this._object.evaluateExpression(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg))) };+ async evaluateExpression(params: channels.JSHandleEvaluateExpressionParams, progress: Progress): Promise<channels.JSHandleEvaluateExpressionResult> {+ const jsHandle = await progress.race(this._object.evaluateExpression(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg)));+ return { value: serializeResult(jsHandle) };}- async evaluateExpressionHandle(params: channels.JSHandleEvaluateExpressionHandleParams): Promise<channels.JSHandleEvaluateExpressionHandleResult> {- const jsHandle = await this._object.evaluateExpressionHandle(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg));+ async evaluateExpressionHandle(params: channels.JSHandleEvaluateExpressionHandleParams, progress: Progress): Promise<channels.JSHandleEvaluateExpressionHandleResult> {+ const jsHandle = await progress.race(this._object.evaluateExpressionHandle(params.expression, { isFunction: params.isFunction }, parseArgument(params.arg)));// If "jsHandle" is an ElementHandle, it belongs to the same frame as "this".return { handle: ElementHandleDispatcher.fromJSOrElementHandle(this.parentScope() as FrameDispatcher, jsHandle) };}- async getProperty(params: channels.JSHandleGetPropertyParams): Promise<channels.JSHandleGetPropertyResult> {- const jsHandle = await this._object.getProperty(params.name);+ async getProperty(params: channels.JSHandleGetPropertyParams, progress: Progress): Promise<channels.JSHandleGetPropertyResult> {+ const jsHandle = await progress.race(this._object.getProperty(params.name));// If "jsHandle" is an ElementHandle, it belongs to the same frame as "this".return { handle: ElementHandleDispatcher.fromJSOrElementHandle(this.parentScope() as FrameDispatcher, jsHandle) };}- async getPropertyList(): Promise<channels.JSHandleGetPropertyListResult> {- const map = await this._object.getProperties();+ async getPropertyList(params: channels.JSHandleGetPropertyListParams, progress: Progress): Promise<channels.JSHandleGetPropertyListResult> {+ const map = await progress.race(this._object.getProperties());const properties = [];for (const [name, value] of map) {// If "jsHandle" is an ElementHandle, it belongs to the same frame as "this".@@ -68,12 +69,12 @@ export class JSHandleDispatcher<ParentScope extends JSHandleDispatcherParentScopreturn { properties };}- async jsonValue(): Promise<channels.JSHandleJsonValueResult> {- return { value: serializeResult(await this._object.jsonValue()) };+ async jsonValue(params: channels.JSHandleJsonValueParams, progress: Progress): Promise<channels.JSHandleJsonValueResult> {+ return { value: serializeResult(await progress.race(this._object.jsonValue())) };}- async dispose(_: any, metadata: CallMetadata) {- metadata.potentiallyClosesScope = true;+ async dispose(_: any, progress: Progress) {+ progress.metadata.potentiallyClosesScope = true;this._object.dispose();this._dispose();}diff --git a/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts b/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.tsindex 522df815be..f60e50cd92 100644--- a/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/jsonPipeDispatcher.ts@@ -19,6 +19,7 @@ import { SdkObject } from '../instrumentation';import type { LocalUtilsDispatcher } from './localUtilsDispatcher';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export class JsonPipeDispatcher extends Dispatcher<SdkObject, channels.JsonPipeChannel, LocalUtilsDispatcher> implements channels.JsonPipeChannel {_type_JsonPipe = true;@@ -26,11 +27,11 @@ export class JsonPipeDispatcher extends Dispatcher<SdkObject, channels.JsonPipeCsuper(scope, new SdkObject(scope._object, 'jsonPipe'), 'JsonPipe', {});}- async send(params: channels.JsonPipeSendParams): Promise<channels.JsonPipeSendResult> {+ async send(params: channels.JsonPipeSendParams, progress: Progress): Promise<channels.JsonPipeSendResult> {this.emit('message', params.message);}- async close(): Promise<void> {+ async close(params: channels.JsonPipeCloseParams, progress: Progress): Promise<void> {this.emit('close');if (!this._disposed) {this._dispatchEvent('closed', {});diff --git a/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts b/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.tsindex a80aa49456..3d46190884 100644--- a/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/playwrightDispatcher.ts@@ -34,6 +34,7 @@ import type { AndroidDevice } from '../android/android';import type { Browser } from '../browser';import type { Playwright } from '../playwright';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export type PlaywrightDispatcherOptions = {socksProxy?: SocksProxy;@@ -85,7 +86,7 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.Playwrthis._browserDispatcher = browserDispatcher;}- async newRequest(params: channels.PlaywrightNewRequestParams): Promise<channels.PlaywrightNewRequestResult> {+ async newRequest(params: channels.PlaywrightNewRequestParams, progress: Progress): Promise<channels.PlaywrightNewRequestResult> {const request = new GlobalAPIRequestContext(this._object, params);return { request: APIRequestContextDispatcher.from(this.parentScope(), request) };}@@ -112,23 +113,23 @@ class SocksSupportDispatcher extends Dispatcher<SdkObject, channels.SocksSupport];}- async socksConnected(params: channels.SocksSupportSocksConnectedParams): Promise<void> {+ async socksConnected(params: channels.SocksSupportSocksConnectedParams, progress: Progress): Promise<void> {this._socksProxy?.socketConnected(params);}- async socksFailed(params: channels.SocksSupportSocksFailedParams): Promise<void> {+ async socksFailed(params: channels.SocksSupportSocksFailedParams, progress: Progress): Promise<void> {this._socksProxy?.socketFailed(params);}- async socksData(params: channels.SocksSupportSocksDataParams): Promise<void> {+ async socksData(params: channels.SocksSupportSocksDataParams, progress: Progress): Promise<void> {this._socksProxy?.sendSocketData(params);}- async socksError(params: channels.SocksSupportSocksErrorParams): Promise<void> {+ async socksError(params: channels.SocksSupportSocksErrorParams, progress: Progress): Promise<void> {this._socksProxy?.sendSocketError(params);}- async socksEnd(params: channels.SocksSupportSocksEndParams): Promise<void> {+ async socksEnd(params: channels.SocksSupportSocksEndParams, progress: Progress): Promise<void> {this._socksProxy?.sendSocketEnd(params);}diff --git a/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts b/packages/playwright-core/src/server/dispatchers/streamDispatcher.tsindex 82b5319c59..2d7da4fa66 100644--- a/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/streamDispatcher.ts@@ -21,6 +21,7 @@ import { SdkObject } from '../instrumentation';import type { ArtifactDispatcher } from './artifactDispatcher';import type * as channels from '@protocol/channels';import type * as stream from 'stream';+import type { Progress } from '@protocol/progress';class StreamSdkObject extends SdkObject {readonly stream: stream.Readable;@@ -42,7 +43,7 @@ export class StreamDispatcher extends Dispatcher<StreamSdkObject, channels.Streastream.once('error', () => this._ended = true);}- async read(params: channels.StreamReadParams): Promise<channels.StreamReadResult> {+ async read(params: channels.StreamReadParams, progress: Progress): Promise<channels.StreamReadResult> {const stream = this._object.stream;if (this._ended)return { binary: Buffer.from('') };@@ -52,16 +53,17 @@ export class StreamDispatcher extends Dispatcher<StreamSdkObject, channels.Streastream.on('readable', done);stream.on('end', done);stream.on('error', done);- await readyPromise;- stream.off('readable', done);- stream.off('end', done);- stream.off('error', done);+ await progress.race(readyPromise).finally(() => {+ stream.off('readable', done);+ stream.off('end', done);+ stream.off('error', done);+ });}const buffer = stream.read(Math.min(stream.readableLength, params.size || stream.readableLength));return { binary: buffer || Buffer.from('') };}- async close() {+ async close(params: channels.StreamCloseParams, progress: Progress): Promise<void> {this._object.stream.destroy();}}diff --git a/packages/playwright-core/src/server/dispatchers/tracingDispatcher.ts b/packages/playwright-core/src/server/dispatchers/tracingDispatcher.tsindex 42a9804b36..2e295246d6 100644--- a/packages/playwright-core/src/server/dispatchers/tracingDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/tracingDispatcher.ts@@ -20,8 +20,8 @@ import { Dispatcher } from './dispatcher';import type { BrowserContextDispatcher } from './browserContextDispatcher';import type { APIRequestContextDispatcher } from './networkDispatchers';import type { Tracing } from '../trace/recorder/tracing';-import type { CallMetadata } from '@protocol/callMetadata';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';export class TracingDispatcher extends Dispatcher<Tracing, channels.TracingChannel, BrowserContextDispatcher | APIRequestContextDispatcher> implements channels.TracingChannel {_type_Tracing = true;@@ -35,30 +35,30 @@ export class TracingDispatcher extends Dispatcher<Tracing, channels.TracingChannsuper(scope, tracing, 'Tracing', {});}- async tracingStart(params: channels.TracingTracingStartParams): Promise<channels.TracingTracingStartResult> {- await this._object.start(params);+ async tracingStart(params: channels.TracingTracingStartParams, progress: Progress): Promise<channels.TracingTracingStartResult> {+ this._object.start(params);}- async tracingStartChunk(params: channels.TracingTracingStartChunkParams): Promise<channels.TracingTracingStartChunkResult> {- return await this._object.startChunk(params);+ async tracingStartChunk(params: channels.TracingTracingStartChunkParams, progress: Progress): Promise<channels.TracingTracingStartChunkResult> {+ return await this._object.startChunk(progress, params);}- async tracingGroup(params: channels.TracingTracingGroupParams, metadata: CallMetadata): Promise<channels.TracingTracingGroupResult> {+ async tracingGroup(params: channels.TracingTracingGroupParams, progress: Progress): Promise<channels.TracingTracingGroupResult> {const { name, location } = params;- await this._object.group(name, location, metadata);+ this._object.group(name, location, progress.metadata);}- async tracingGroupEnd(params: channels.TracingTracingGroupEndParams): Promise<channels.TracingTracingGroupEndResult> {- await this._object.groupEnd();+ async tracingGroupEnd(params: channels.TracingTracingGroupEndParams, progress: Progress): Promise<channels.TracingTracingGroupEndResult> {+ this._object.groupEnd();}- async tracingStopChunk(params: channels.TracingTracingStopChunkParams): Promise<channels.TracingTracingStopChunkResult> {- const { artifact, entries } = await this._object.stopChunk(params);+ async tracingStopChunk(params: channels.TracingTracingStopChunkParams, progress: Progress): Promise<channels.TracingTracingStopChunkResult> {+ const { artifact, entries } = await this._object.stopChunk(progress, params);return { artifact: artifact ? ArtifactDispatcher.from(this, artifact) : undefined, entries };}- async tracingStop(params: channels.TracingTracingStopParams): Promise<channels.TracingTracingStopResult> {- await this._object.stop();+ async tracingStop(params: channels.TracingTracingStopParams, progress: Progress): Promise<channels.TracingTracingStopResult> {+ await this._object.stop(progress);}}diff --git a/packages/playwright-core/src/server/dispatchers/webSocketRouteDispatcher.ts b/packages/playwright-core/src/server/dispatchers/webSocketRouteDispatcher.tsindex 2e59886335..6d2e5cc2ce 100644--- a/packages/playwright-core/src/server/dispatchers/webSocketRouteDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/webSocketRouteDispatcher.ts@@ -104,32 +104,32 @@ export class WebSocketRouteDispatcher extends Dispatcher<SdkObject, channels.Web}}- async connect(params: channels.WebSocketRouteConnectParams) {- await this._evaluateAPIRequest({ id: this._id, type: 'connect' });+ async connect(params: channels.WebSocketRouteConnectParams, progress: Progress) {+ await this._evaluateAPIRequest(progress, { id: this._id, type: 'connect' });}- async ensureOpened(params: channels.WebSocketRouteEnsureOpenedParams) {- await this._evaluateAPIRequest({ id: this._id, type: 'ensureOpened' });+ async ensureOpened(params: channels.WebSocketRouteEnsureOpenedParams, progress: Progress) {+ await this._evaluateAPIRequest(progress, { id: this._id, type: 'ensureOpened' });}- async sendToPage(params: channels.WebSocketRouteSendToPageParams) {- await this._evaluateAPIRequest({ id: this._id, type: 'sendToPage', data: { data: params.message, isBase64: params.isBase64 } });+ async sendToPage(params: channels.WebSocketRouteSendToPageParams, progress: Progress) {+ await this._evaluateAPIRequest(progress, { id: this._id, type: 'sendToPage', data: { data: params.message, isBase64: params.isBase64 } });}- async sendToServer(params: channels.WebSocketRouteSendToServerParams) {- await this._evaluateAPIRequest({ id: this._id, type: 'sendToServer', data: { data: params.message, isBase64: params.isBase64 } });+ async sendToServer(params: channels.WebSocketRouteSendToServerParams, progress: Progress) {+ await this._evaluateAPIRequest(progress, { id: this._id, type: 'sendToServer', data: { data: params.message, isBase64: params.isBase64 } });}- async closePage(params: channels.WebSocketRouteClosePageParams) {- await this._evaluateAPIRequest({ id: this._id, type: 'closePage', code: params.code, reason: params.reason, wasClean: params.wasClean });+ async closePage(params: channels.WebSocketRouteClosePageParams, progress: Progress) {+ await this._evaluateAPIRequest(progress, { id: this._id, type: 'closePage', code: params.code, reason: params.reason, wasClean: params.wasClean });}- async closeServer(params: channels.WebSocketRouteCloseServerParams) {- await this._evaluateAPIRequest({ id: this._id, type: 'closeServer', code: params.code, reason: params.reason, wasClean: params.wasClean });+ async closeServer(params: channels.WebSocketRouteCloseServerParams, progress: Progress) {+ await this._evaluateAPIRequest(progress, { id: this._id, type: 'closeServer', code: params.code, reason: params.reason, wasClean: params.wasClean });}- private async _evaluateAPIRequest(request: ws.APIRequest) {- await this._frame.evaluateExpression(`globalThis.__pwWebSocketDispatch(${JSON.stringify(request)})`).catch(() => {});+ private async _evaluateAPIRequest(progress: Progress, request: ws.APIRequest) {+ await progress.race(this._frame.evaluateExpression(`globalThis.__pwWebSocketDispatch(${JSON.stringify(request)})`).catch(() => {}));}override _onDispose() {diff --git a/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts b/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.tsindex 1595cae757..052b21eec6 100644--- a/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts+++ b/packages/playwright-core/src/server/dispatchers/writableStreamDispatcher.ts@@ -21,6 +21,7 @@ import { SdkObject } from '../instrumentation';import type { BrowserContextDispatcher } from './browserContextDispatcher';import type * as channels from '@protocol/channels';+import type { Progress } from '@protocol/progress';class WritableStreamSdkObject extends SdkObject {readonly streamOrDirectory: fs.WriteStream | string;@@ -40,27 +41,27 @@ export class WritableStreamDispatcher extends Dispatcher<WritableStreamSdkObjectsuper(scope, new WritableStreamSdkObject(scope._object, streamOrDirectory, lastModifiedMs), 'WritableStream', {});}- async write(params: channels.WritableStreamWriteParams): Promise<channels.WritableStreamWriteResult> {+ async write(params: channels.WritableStreamWriteParams, progress: Progress): Promise<channels.WritableStreamWriteResult> {if (typeof this._object.streamOrDirectory === 'string')throw new Error('Cannot write to a directory');const stream = this._object.streamOrDirectory;- await new Promise<void>((fulfill, reject) => {+ await progress.race(new Promise<void>((fulfill, reject) => {stream.write(params.binary, error => {if (error)reject(error);elsefulfill();});- });+ }));}- async close() {+ async close(params: channels.WritableStreamCloseParams, progress: Progress): Promise<void> {if (typeof this._object.streamOrDirectory === 'string')throw new Error('Cannot close a directory');const stream = this._object.streamOrDirectory;- await new Promise<void>(fulfill => stream.end(fulfill));+ await progress.race(new Promise<void>(fulfill => stream.end(fulfill)));if (this._object.lastModifiedMs)- await fs.promises.utimes(this.path(), new Date(this._object.lastModifiedMs), new Date(this._object.lastModifiedMs));+ await progress.race(fs.promises.utimes(this.path(), new Date(this._object.lastModifiedMs), new Date(this._object.lastModifiedMs)));}path(): string {diff --git a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts b/packages/playwright-core/src/server/trace/recorder/snapshotter.tsindex 82e1b99936..5d0139df07 100644--- a/packages/playwright-core/src/server/trace/recorder/snapshotter.ts+++ b/packages/playwright-core/src/server/trace/recorder/snapshotter.ts@@ -70,7 +70,7 @@ export class Snapshotter {await this._context.safeNonStallingEvaluateInAllFrames(`window["${this._snapshotStreamer}"].reset()`, 'main');}- async stop() {+ stop() {this._started = false;}diff --git a/packages/playwright-core/src/server/trace/recorder/tracing.ts b/packages/playwright-core/src/server/trace/recorder/tracing.tsindex 36d2048839..c23e665dfb 100644--- a/packages/playwright-core/src/server/trace/recorder/tracing.ts+++ b/packages/playwright-core/src/server/trace/recorder/tracing.ts@@ -32,6 +32,7 @@ import { SerializedFS, removeFolders } from '../../utils/fileUtils';import { HarTracer } from '../../har/harTracer';import { SdkObject } from '../../instrumentation';import { Page } from '../../page';+import { isAbortError } from '../../progress';import type { SnapshotterBlob, SnapshotterDelegate } from './snapshotter';import type { NameValue } from '../../../utils/isomorphic/types';@@ -46,6 +47,7 @@ import type { StackFrame, TracingTracingStopChunkParams } from '@protocol/channeimport type * as har from '@trace/har';import type { FrameSnapshot } from '@trace/snapshot';import type * as trace from '@trace/trace';+import type { Progress } from '@protocol/progress';const version: trace.VERSION = 8;@@ -126,14 +128,15 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsreturn this._context instanceof BrowserContext ? this._context._browser.sdkLanguage() : this._context.attribution.playwright.options.sdkLanguage;}- async resetForReuse() {+ async resetForReuse(progress: Progress) {// Discard previous chunk if any and ignore any errors there.- await this.stopChunk({ mode: 'discard' }).catch(() => {});- await this.stop();- await this._snapshotter?.resetForReuse();+ await this.stopChunk(progress, { mode: 'discard' }).catch(() => {});+ await this.stop(progress);+ if (this._snapshotter)+ await progress.race(this._snapshotter.resetForReuse());}- async start(options: TracerOptions) {+ start(options: TracerOptions) {if (this._isStopping)throw new Error('Cannot start tracing while stopping');if (this._state)@@ -170,9 +173,9 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsthis._harTracer.start({ omitScripts: !options.live });}- async startChunk(options: { name?: string, title?: string } = {}): Promise<{ traceName: string }> {+ async startChunk(progress: Progress, options: { name?: string, title?: string } = {}): Promise<{ traceName: string }> {if (this._state && this._state.recording)- await this.stopChunk({ mode: 'discard' });+ await this.stopChunk(progress, { mode: 'discard' });if (!this._state)throw new Error('Must start tracing before starting a new chunk');@@ -218,7 +221,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsreturn this._state?.groupStack.length ? this._state.groupStack[this._state.groupStack.length - 1] : undefined;}- async group(name: string, location: { file: string, line?: number, column?: number } | undefined, metadata: CallMetadata): Promise<void> {+ group(name: string, location: { file: string, line?: number, column?: number } | undefined, metadata: CallMetadata) {if (!this._state)return;const stackFrames: StackFrame[] = [];@@ -296,7 +299,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsstate.networkFile = newNetworkFile;}- async stop() {+ async stop(progress: Progress) {if (!this._state)return;if (this._isStopping)@@ -306,8 +309,9 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsthis._closeAllGroups();this._harTracer.stop();this.flushHarEntries();- await this._fs.syncAndGetError();- this._state = undefined;+ await progress.race(this._fs.syncAndGetError()).finally(() => {+ this._state = undefined;+ });}async deleteTmpTracesDir() {@@ -337,7 +341,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsthis.groupEnd();}- async stopChunk(params: TracingTracingStopChunkParams): Promise<{ artifact?: Artifact, entries?: NameValue[] }> {+ async stopChunk(progress: Progress, params: TracingTracingStopChunkParams): Promise<{ artifact?: Artifact, entries?: NameValue[] }> {if (this._isStopping)throw new Error(`Tracing is already stopping`);this._isStopping = true;@@ -357,7 +361,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsthis._stopScreencast();if (this._state.options.snapshots)- await this._snapshotter?.stop();+ this._snapshotter?.stop();this.flushHarEntries();@@ -391,7 +395,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsthis._fs.zip(entries, zipFileName);// Make sure all file operations complete.- const error = await this._fs.syncAndGetError();+ const error = await progress.race(this._fs.syncAndGetError()).catch(e => e);this._isStopping = false;if (this._state)@@ -402,7 +406,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snapsif (error) {// This check is here because closing the browser removes the tracesDir and tracing// cannot access removed files. Clients are ready for the missing artifact.- if (this._context instanceof BrowserContext && !this._context._browser.isConnected())+ if (!isAbortError(error) && this._context instanceof BrowserContext && !this._context._browser.isConnected())return {};throw error;}diff --git a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.tsindex 0f7db29834..a322b9c1de 100644--- a/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts+++ b/packages/playwright-core/src/utils/isomorphic/protocolMetainfo.ts@@ -311,10 +311,20 @@ export const methodMetainfo = new Map<string, { internal?: boolean, title?: stri]);export const progressTypes = new Set<string>([+ 'Playwright',+ 'SocksSupport','BrowserContext','Page','Frame','Worker',+ 'JSHandle','ElementHandle',- 'BindingCall'+ 'WebSocketRoute',+ 'BindingCall',+ 'Dialog',+ 'Tracing',+ 'Stream',+ 'WritableStream',+ 'CDPSession',+ 'JsonPipe']);diff --git a/packages/protocol/src/channels.d.ts b/packages/protocol/src/channels.d.tsindex 459cc1feef..6e2a4b1662 100644--- a/packages/protocol/src/channels.d.ts+++ b/packages/protocol/src/channels.d.ts@@ -638,7 +638,7 @@ export interface PlaywrightEventTarget {}export interface PlaywrightChannel extends PlaywrightEventTarget, Channel {_type_Playwright: boolean;- newRequest(params: PlaywrightNewRequestParams, metadata?: CallMetadata): Promise<PlaywrightNewRequestResult>;+ newRequest(params: PlaywrightNewRequestParams, progress?: Progress): Promise<PlaywrightNewRequestResult>;}export type PlaywrightNewRequestParams = {baseURL?: string,@@ -839,11 +839,11 @@ export interface SocksSupportEventTarget {}export interface SocksSupportChannel extends SocksSupportEventTarget, Channel {_type_SocksSupport: boolean;- socksConnected(params: SocksSupportSocksConnectedParams, metadata?: CallMetadata): Promise<SocksSupportSocksConnectedResult>;- socksFailed(params: SocksSupportSocksFailedParams, metadata?: CallMetadata): Promise<SocksSupportSocksFailedResult>;- socksData(params: SocksSupportSocksDataParams, metadata?: CallMetadata): Promise<SocksSupportSocksDataResult>;- socksError(params: SocksSupportSocksErrorParams, metadata?: CallMetadata): Promise<SocksSupportSocksErrorResult>;- socksEnd(params: SocksSupportSocksEndParams, metadata?: CallMetadata): Promise<SocksSupportSocksEndResult>;+ socksConnected(params: SocksSupportSocksConnectedParams, progress?: Progress): Promise<SocksSupportSocksConnectedResult>;+ socksFailed(params: SocksSupportSocksFailedParams, progress?: Progress): Promise<SocksSupportSocksFailedResult>;+ socksData(params: SocksSupportSocksDataParams, progress?: Progress): Promise<SocksSupportSocksDataResult>;+ socksError(params: SocksSupportSocksErrorParams, progress?: Progress): Promise<SocksSupportSocksErrorResult>;+ socksEnd(params: SocksSupportSocksEndParams, progress?: Progress): Promise<SocksSupportSocksEndResult>;}export type SocksSupportSocksRequestedEvent = {uid: string,@@ -3328,12 +3328,12 @@ export interface JSHandleEventTarget {}export interface JSHandleChannel extends JSHandleEventTarget, Channel {_type_JSHandle: boolean;- dispose(params?: JSHandleDisposeParams, metadata?: CallMetadata): Promise<JSHandleDisposeResult>;- evaluateExpression(params: JSHandleEvaluateExpressionParams, metadata?: CallMetadata): Promise<JSHandleEvaluateExpressionResult>;- evaluateExpressionHandle(params: JSHandleEvaluateExpressionHandleParams, metadata?: CallMetadata): Promise<JSHandleEvaluateExpressionHandleResult>;- getPropertyList(params?: JSHandleGetPropertyListParams, metadata?: CallMetadata): Promise<JSHandleGetPropertyListResult>;- getProperty(params: JSHandleGetPropertyParams, metadata?: CallMetadata): Promise<JSHandleGetPropertyResult>;- jsonValue(params?: JSHandleJsonValueParams, metadata?: CallMetadata): Promise<JSHandleJsonValueResult>;+ dispose(params?: JSHandleDisposeParams, progress?: Progress): Promise<JSHandleDisposeResult>;+ evaluateExpression(params: JSHandleEvaluateExpressionParams, progress?: Progress): Promise<JSHandleEvaluateExpressionResult>;+ evaluateExpressionHandle(params: JSHandleEvaluateExpressionHandleParams, progress?: Progress): Promise<JSHandleEvaluateExpressionHandleResult>;+ getPropertyList(params?: JSHandleGetPropertyListParams, progress?: Progress): Promise<JSHandleGetPropertyListResult>;+ getProperty(params: JSHandleGetPropertyParams, progress?: Progress): Promise<JSHandleGetPropertyResult>;+ jsonValue(params?: JSHandleJsonValueParams, progress?: Progress): Promise<JSHandleJsonValueResult>;}export type JSHandlePreviewUpdatedEvent = {preview: string,@@ -3909,12 +3909,12 @@ export interface WebSocketRouteEventTarget {}export interface WebSocketRouteChannel extends WebSocketRouteEventTarget, Channel {_type_WebSocketRoute: boolean;- connect(params?: WebSocketRouteConnectParams, metadata?: CallMetadata): Promise<WebSocketRouteConnectResult>;- ensureOpened(params?: WebSocketRouteEnsureOpenedParams, metadata?: CallMetadata): Promise<WebSocketRouteEnsureOpenedResult>;- sendToPage(params: WebSocketRouteSendToPageParams, metadata?: CallMetadata): Promise<WebSocketRouteSendToPageResult>;- sendToServer(params: WebSocketRouteSendToServerParams, metadata?: CallMetadata): Promise<WebSocketRouteSendToServerResult>;- closePage(params: WebSocketRouteClosePageParams, metadata?: CallMetadata): Promise<WebSocketRouteClosePageResult>;- closeServer(params: WebSocketRouteCloseServerParams, metadata?: CallMetadata): Promise<WebSocketRouteCloseServerResult>;+ connect(params?: WebSocketRouteConnectParams, progress?: Progress): Promise<WebSocketRouteConnectResult>;+ ensureOpened(params?: WebSocketRouteEnsureOpenedParams, progress?: Progress): Promise<WebSocketRouteEnsureOpenedResult>;+ sendToPage(params: WebSocketRouteSendToPageParams, progress?: Progress): Promise<WebSocketRouteSendToPageResult>;+ sendToServer(params: WebSocketRouteSendToServerParams, progress?: Progress): Promise<WebSocketRouteSendToServerResult>;+ closePage(params: WebSocketRouteClosePageParams, progress?: Progress): Promise<WebSocketRouteClosePageResult>;+ closeServer(params: WebSocketRouteCloseServerParams, progress?: Progress): Promise<WebSocketRouteCloseServerResult>;}export type WebSocketRouteMessageFromPageEvent = {message: string,@@ -4143,8 +4143,8 @@ export interface DialogEventTarget {}export interface DialogChannel extends DialogEventTarget, Channel {_type_Dialog: boolean;- accept(params: DialogAcceptParams, metadata?: CallMetadata): Promise<DialogAcceptResult>;- dismiss(params?: DialogDismissParams, metadata?: CallMetadata): Promise<DialogDismissResult>;+ accept(params: DialogAcceptParams, progress?: Progress): Promise<DialogAcceptResult>;+ dismiss(params?: DialogDismissParams, progress?: Progress): Promise<DialogDismissResult>;}export type DialogAcceptParams = {promptText?: string,@@ -4166,12 +4166,12 @@ export interface TracingEventTarget {}export interface TracingChannel extends TracingEventTarget, Channel {_type_Tracing: boolean;- tracingStart(params: TracingTracingStartParams, metadata?: CallMetadata): Promise<TracingTracingStartResult>;- tracingStartChunk(params: TracingTracingStartChunkParams, metadata?: CallMetadata): Promise<TracingTracingStartChunkResult>;- tracingGroup(params: TracingTracingGroupParams, metadata?: CallMetadata): Promise<TracingTracingGroupResult>;- tracingGroupEnd(params?: TracingTracingGroupEndParams, metadata?: CallMetadata): Promise<TracingTracingGroupEndResult>;- tracingStopChunk(params: TracingTracingStopChunkParams, metadata?: CallMetadata): Promise<TracingTracingStopChunkResult>;- tracingStop(params?: TracingTracingStopParams, metadata?: CallMetadata): Promise<TracingTracingStopResult>;+ tracingStart(params: TracingTracingStartParams, progress?: Progress): Promise<TracingTracingStartResult>;+ tracingStartChunk(params: TracingTracingStartChunkParams, progress?: Progress): Promise<TracingTracingStartChunkResult>;+ tracingGroup(params: TracingTracingGroupParams, progress?: Progress): Promise<TracingTracingGroupResult>;+ tracingGroupEnd(params?: TracingTracingGroupEndParams, progress?: Progress): Promise<TracingTracingGroupEndResult>;+ tracingStopChunk(params: TracingTracingStopChunkParams, progress?: Progress): Promise<TracingTracingStopChunkResult>;+ tracingStop(params?: TracingTracingStopParams, progress?: Progress): Promise<TracingTracingStopResult>;}export type TracingTracingStartParams = {name?: string,@@ -4292,8 +4292,8 @@ export interface StreamEventTarget {}export interface StreamChannel extends StreamEventTarget, Channel {_type_Stream: boolean;- read(params: StreamReadParams, metadata?: CallMetadata): Promise<StreamReadResult>;- close(params?: StreamCloseParams, metadata?: CallMetadata): Promise<StreamCloseResult>;+ read(params: StreamReadParams, progress?: Progress): Promise<StreamReadResult>;+ close(params?: StreamCloseParams, progress?: Progress): Promise<StreamCloseResult>;}export type StreamReadParams = {size?: number,@@ -4317,8 +4317,8 @@ export interface WritableStreamEventTarget {}export interface WritableStreamChannel extends WritableStreamEventTarget, Channel {_type_WritableStream: boolean;- write(params: WritableStreamWriteParams, metadata?: CallMetadata): Promise<WritableStreamWriteResult>;- close(params?: WritableStreamCloseParams, metadata?: CallMetadata): Promise<WritableStreamCloseResult>;+ write(params: WritableStreamWriteParams, progress?: Progress): Promise<WritableStreamWriteResult>;+ close(params?: WritableStreamCloseParams, progress?: Progress): Promise<WritableStreamCloseResult>;}export type WritableStreamWriteParams = {binary: Binary,@@ -4341,8 +4341,8 @@ export interface CDPSessionEventTarget {}export interface CDPSessionChannel extends CDPSessionEventTarget, Channel {_type_CDPSession: boolean;- send(params: CDPSessionSendParams, metadata?: CallMetadata): Promise<CDPSessionSendResult>;- detach(params?: CDPSessionDetachParams, metadata?: CallMetadata): Promise<CDPSessionDetachResult>;+ send(params: CDPSessionSendParams, progress?: Progress): Promise<CDPSessionSendResult>;+ detach(params?: CDPSessionDetachParams, progress?: Progress): Promise<CDPSessionDetachResult>;}export type CDPSessionEventEvent = {method: string,@@ -5019,8 +5019,8 @@ export interface JsonPipeEventTarget {}export interface JsonPipeChannel extends JsonPipeEventTarget, Channel {_type_JsonPipe: boolean;- send(params: JsonPipeSendParams, metadata?: CallMetadata): Promise<JsonPipeSendResult>;- close(params?: JsonPipeCloseParams, metadata?: CallMetadata): Promise<JsonPipeCloseResult>;+ send(params: JsonPipeSendParams, progress?: Progress): Promise<JsonPipeSendResult>;+ close(params?: JsonPipeCloseParams, progress?: Progress): Promise<JsonPipeCloseResult>;}export type JsonPipeMessageEvent = {message: any,diff --git a/packages/protocol/src/protocol.yml b/packages/protocol/src/protocol.ymlindex 63f30e3dbb..851b15e7ab 100644--- a/packages/protocol/src/protocol.yml+++ b/packages/protocol/src/protocol.yml@@ -786,6 +786,7 @@ Root:Playwright:type: interface+ progress: trueinitializer:chromium: BrowserType@@ -963,6 +964,7 @@ DebugController:SocksSupport:type: interface+ progress: truecommands:socksConnected:@@ -2745,6 +2747,7 @@ Worker:JSHandle:type: interface+ progress: trueinitializer:preview: string@@ -3327,6 +3330,7 @@ Route:WebSocketRoute:type: interface+ progress: trueinitializer:url: string@@ -3528,6 +3532,7 @@ BindingCall:Dialog:type: interface+ progress: trueinitializer:page: Page?@@ -3547,6 +3552,7 @@ Dialog:Tracing:type: interface+ progress: truecommands:@@ -3646,6 +3652,7 @@ Artifact:Stream:type: interface+ progress: truecommands:@@ -3662,6 +3669,7 @@ Stream:WritableStream:type: interface+ progress: truecommands:@@ -3676,6 +3684,7 @@ WritableStream:CDPSession:type: interface+ progress: truecommands:@@ -4134,6 +4143,7 @@ AndroidElementInfo:JsonPipe:type: interface+ progress: truecommands:send: