Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/server/browserContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,12 +31,12 @@ export class CDPSessionDispatcher extends Dispatcher<CDPSession, channels.CDPSes
this.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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -42,24 +42,25 @@ export class JSHandleDispatcher<ParentScope extends JSHandleDispatcherParentScop
jsHandle._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".
Expand All @@ -68,12 +69,12 @@ export class JSHandleDispatcher<ParentScope extends JSHandleDispatcherParentScop
return { 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ 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;
constructor(scope: LocalUtilsDispatcher) {
super(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', {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,7 +86,7 @@ export class PlaywrightDispatcher extends Dispatcher<Playwright, channels.Playwr
this._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) };
}
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -42,7 +43,7 @@ export class StreamDispatcher extends Dispatcher<StreamSdkObject, channels.Strea
stream.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('') };
Expand All @@ -52,16 +53,17 @@ export class StreamDispatcher extends Dispatcher<StreamSdkObject, channels.Strea
stream.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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,30 +35,30 @@ export class TracingDispatcher extends Dispatcher<Tracing, channels.TracingChann
super(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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -40,27 +41,27 @@ export class WritableStreamDispatcher extends Dispatcher<WritableStreamSdkObject
super(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);
else
fulfill();
});
});
}));
}

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class Snapshotter {
await this._context.safeNonStallingEvaluateInAllFrames(`window["${this._snapshotStreamer}"].reset()`, 'main');
}

async stop() {
stop() {
this._started = false;
}

Expand Down
Loading
Loading