Skip to content
Closed
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/client/channelOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { EventEmitter } from './eventEmitter';
import { ValidationError, maybeFindValidator } from '../protocol/validator';
import { getMetainfo } from '../utils/isomorphic/protocolFormatter';
import { getMetainfo } from '../utils/isomorphic/protocolMetainfo';
import { captureLibraryStackTrace } from './clientStackTrace';
import { stringifyStackFrames } from '../utils/isomorphic/stackTrace';

Expand Down
30 changes: 13 additions & 17 deletions packages/playwright-core/src/server/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { SdkObject } from './instrumentation';
import { monotonicTime } from '../utils';
import { BrowserContext } from './browserContext';
import { getMetainfo } from '../utils/isomorphic/protocolFormatter';
import { getMetainfo } from '../utils/isomorphic/protocolMetainfo';

import type { CallMetadata, InstrumentationListener } from './instrumentation';

Expand All @@ -29,7 +29,7 @@ export class Debugger extends SdkObject implements InstrumentationListener {
private _pauseAt: PauseAt = {};
private _pausedCallsMetadata = new Map<CallMetadata, { resolve: () => void, sdkObject: SdkObject }>();
private _enabled = false;
private _pauseBeforeInputActions = false; // instead of inside input actions
private _pauseBeforeWaitingActions = false; // instead of inside input actions
private _context: BrowserContext;

static Events = {
Expand All @@ -52,24 +52,27 @@ export class Debugger extends SdkObject implements InstrumentationListener {
}

async onBeforeCall(sdkObject: SdkObject, metadata: CallMetadata): Promise<void> {
if (this._muted)
if (this._muted || metadata.internal)
return;
const metainfo = getMetainfo(metadata);
const pauseOnPauseCall = this._enabled && metadata.type === 'BrowserContext' && metadata.method === 'pause';
const pauseOnNextStep = !!this._pauseAt.next && shouldPauseBeforeStep(metadata, this._pauseBeforeInputActions);
const pauseBeforeAction = !!this._pauseAt.next && !!metainfo?.pause && (this._pauseBeforeWaitingActions || !metainfo?.isAutoWaiting);
const pauseOnLocation = !!this._pauseAt.location && matchesLocation(metadata, this._pauseAt.location);
if (pauseOnPauseCall || pauseOnNextStep || pauseOnLocation)
if (pauseOnPauseCall || pauseBeforeAction || pauseOnLocation)
await this._pause(sdkObject, metadata);
}

async onBeforeInputAction(sdkObject: SdkObject, metadata: CallMetadata): Promise<void> {
if (this._muted)
if (this._muted || metadata.internal)
return;
if (!!this._pauseAt.next && !this._pauseBeforeInputActions)
const metainfo = getMetainfo(metadata);
const pauseBeforeInput = !!this._pauseAt.next && !!metainfo?.pause && !!metainfo?.isAutoWaiting && !this._pauseBeforeWaitingActions;
if (pauseBeforeInput)
await this._pause(sdkObject, metadata);
}

private async _pause(sdkObject: SdkObject, metadata: CallMetadata) {
if (this._muted)
if (this._muted || metadata.internal)
return;
this._pauseAt = {};
metadata.pauseStartTime = monotonicTime();
Expand All @@ -93,8 +96,8 @@ export class Debugger extends SdkObject implements InstrumentationListener {
this.emit(Debugger.Events.PausedStateChanged);
}

setPauseBeforeInputActions() {
this._pauseBeforeInputActions = true;
setPauseBeforeWaitingActions() {
this._pauseBeforeWaitingActions = true;
}

setPauseAt(at: { next?: boolean, location?: { file: string, line?: number, column?: number } } = {}) {
Expand All @@ -121,10 +124,3 @@ function matchesLocation(metadata: CallMetadata, location: { file: string, line?
(location.line === undefined || metadata.location.line === location.line) &&
(location.column === undefined || metadata.location.column === location.column);
}

function shouldPauseBeforeStep(metadata: CallMetadata, includeInputActions: boolean): boolean {
if (metadata.internal)
return false;
const metainfo = getMetainfo(metadata);
return !!metainfo?.pausesBeforeAction || (includeInputActions && !!metainfo?.pausesBeforeInput);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DebuggerDispatcher extends Dispatcher<Debugger, channels.DebuggerCh
async pause(params: channels.DebuggerPauseParams, progress: Progress): Promise<void> {
if (this._object.isPaused())
throw new Error('Debugger is already paused');
this._object.setPauseBeforeInputActions();
this._object.setPauseBeforeWaitingActions();
this._object.setPauseAt({ next: true });
}

Expand All @@ -66,15 +66,15 @@ export class DebuggerDispatcher extends Dispatcher<Debugger, channels.DebuggerCh
async next(params: channels.DebuggerNextParams, progress: Progress): Promise<void> {
if (!this._object.isPaused())
throw new Error('Debugger is not paused');
this._object.setPauseBeforeInputActions();
this._object.setPauseBeforeWaitingActions();
this._object.setPauseAt({ next: true });
this._object.resume();
}

async runTo(params: channels.DebuggerRunToParams, progress: Progress): Promise<void> {
if (!this._object.isPaused())
throw new Error('Debugger is not paused');
this._object.setPauseBeforeInputActions();
this._object.setPauseBeforeWaitingActions();
this._object.setPauseAt({ location: params.location });
this._object.resume();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { TargetClosedError, isTargetClosedError, serializeError } from '../error
import { createRootSdkObject, SdkObject } from '../instrumentation';
import { isProtocolError } from '../protocolError';
import { compressCallLog } from '../callLog';
import { getMetainfo } from '../../utils/isomorphic/protocolFormatter';
import { getMetainfo } from '../../utils/isomorphic/protocolMetainfo';
import { Progress, ProgressController } from '../progress';

import type { CallMetadata } from '../instrumentation';
Expand Down
28 changes: 17 additions & 11 deletions packages/playwright-core/src/server/trace/recorder/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import os from 'os';
import path from 'path';

import { Snapshotter } from './snapshotter';
import { getMetainfo } from '../../../utils/isomorphic/protocolFormatter';
import { getMetainfo } from '../../../utils/isomorphic/protocolMetainfo';
import { assert } from '../../../utils/isomorphic/assert';
import { monotonicTime } from '../../../utils/isomorphic/time';
import { eventsHelper } from '../../utils/eventsHelper';
Expand Down Expand Up @@ -435,8 +435,19 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
await this._snapshotter?.captureSnapshot(sdkObject.attribution.page, metadata.id, snapshotName).catch(() => {});
}

private _shouldCaptureSnapshot(sdkObject: SdkObject, metadata: CallMetadata) {
return !!this._snapshotter?.started() && shouldCaptureSnapshot(metadata) && !!sdkObject.attribution.page;
private _shouldCaptureSnapshot(sdkObject: SdkObject, metadata: CallMetadata, phase: 'before' | 'after' | 'input') {
if (!sdkObject.attribution.page || !this._snapshotter?.started())
return;

const metainfo = getMetainfo(metadata);
if (!metainfo?.snapshot)
return false;

switch (phase) {
case 'before': return !metainfo.input || !!metainfo.isAutoWaiting;
case 'input': return !!metainfo.input;
case 'after': return true;
}
}

onBeforeCall(sdkObject: SdkObject, metadata: CallMetadata, parentId?: string) {
Expand All @@ -445,7 +456,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
if (!event)
return Promise.resolve();
sdkObject.attribution.page?.screencast.temporarilyDisableThrottling();
if (this._shouldCaptureSnapshot(sdkObject, metadata))
if (this._shouldCaptureSnapshot(sdkObject, metadata, 'before'))
event.beforeSnapshot = `before@${metadata.id}`;
this._state?.callIds.add(metadata.id);
this._appendTraceEvent(event);
Expand All @@ -460,7 +471,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
if (!event)
return Promise.resolve();
sdkObject.attribution.page?.screencast.temporarilyDisableThrottling();
if (this._shouldCaptureSnapshot(sdkObject, metadata))
if (this._shouldCaptureSnapshot(sdkObject, metadata, 'input'))
event.inputSnapshot = `input@${metadata.id}`;
this._appendTraceEvent(event);
return this._captureSnapshot(event.inputSnapshot, sdkObject, metadata);
Expand All @@ -487,7 +498,7 @@ export class Tracing extends SdkObject implements InstrumentationListener, Snaps
if (!event)
return Promise.resolve();
sdkObject.attribution.page?.screencast.temporarilyDisableThrottling();
if (this._shouldCaptureSnapshot(sdkObject, metadata))
if (this._shouldCaptureSnapshot(sdkObject, metadata, 'after'))
event.afterSnapshot = `after@${metadata.id}`;
this._appendTraceEvent(event);
return this._captureSnapshot(event.afterSnapshot, sdkObject, metadata);
Expand Down Expand Up @@ -659,11 +670,6 @@ function visitTraceEvent(object: any, sha1s: Set<string>): any {
return object;
}

function shouldCaptureSnapshot(metadata: CallMetadata): boolean {
const metainfo = getMetainfo(metadata);
return !!metainfo?.snapshot;
}

function createBeforeActionTraceEvent(metadata: CallMetadata, parentId?: string): trace.BeforeActionTraceEvent | null {
if (metadata.internal || metadata.method.startsWith('tracing'))
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
* limitations under the License.
*/

import { methodMetainfo } from './protocolMetainfo';
import type { MethodMetainfo } from './protocolMetainfo';
import { getMetainfo } from './protocolMetainfo';

export function formatProtocolParam(params: Record<string, string> | undefined, alternatives: string): string | undefined {
return _formatProtocolParam(params, alternatives)?.replaceAll('\n', '\\n');
Expand Down Expand Up @@ -70,10 +69,6 @@ export function renderTitleForCall(metadata: { title?: string, type: string, met
});
}

export function getMetainfo(metadata: { type: string, method: string }): MethodMetainfo | undefined {
return methodMetainfo.get(metadata.type + '.' + metadata.method);
}

export type ActionGroup = 'configuration' | 'route' | 'getter';

export function getActionGroup(metadata: { type: string, method: string }) {
Expand Down
Loading
Loading