chore: remove stray codegen signal handling (#32599)

This commit is contained in:
Pavel Feldman 2024-09-12 14:38:23 -07:00 committed by GitHub
parent 7e3348eb0e
commit cd4dabef8b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,7 +25,6 @@ import { monotonicTime } from '../../utils/time';
import { mainFrameForAction, traceParamsForAction } from './recorderUtils'; import { mainFrameForAction, traceParamsForAction } from './recorderUtils';
export class RecorderCollection extends EventEmitter { export class RecorderCollection extends EventEmitter {
private _currentAction: ActionInContext | null = null;
private _lastAction: ActionInContext | null = null; private _lastAction: ActionInContext | null = null;
private _actions: ActionInContext[] = []; private _actions: ActionInContext[] = [];
private _enabled: boolean; private _enabled: boolean;
@ -39,7 +38,6 @@ export class RecorderCollection extends EventEmitter {
} }
restart() { restart() {
this._currentAction = null;
this._lastAction = null; this._lastAction = null;
this._actions = []; this._actions = [];
this.emit('change'); this.emit('change');
@ -56,8 +54,14 @@ export class RecorderCollection extends EventEmitter {
async willPerformAction(actionInContext: ActionInContext): Promise<CallMetadata | null> { async willPerformAction(actionInContext: ActionInContext): Promise<CallMetadata | null> {
if (!this._enabled) if (!this._enabled)
return null; return null;
const mainFrame = mainFrameForAction(this._pageAliases, actionInContext); const { callMetadata, mainFrame } = this._callMetadataForAction(actionInContext);
await mainFrame.instrumentation.onBeforeCall(mainFrame, callMetadata);
this._lastAction = actionInContext;
return callMetadata;
}
private _callMetadataForAction(actionInContext: ActionInContext): { callMetadata: CallMetadata, mainFrame: Frame } {
const mainFrame = mainFrameForAction(this._pageAliases, actionInContext);
const { action } = actionInContext; const { action } = actionInContext;
const callMetadata: CallMetadata = { const callMetadata: CallMetadata = {
id: `call@${createGuid()}`, id: `call@${createGuid()}`,
@ -72,25 +76,16 @@ export class RecorderCollection extends EventEmitter {
params: traceParamsForAction(actionInContext), params: traceParamsForAction(actionInContext),
log: [], log: [],
}; };
await mainFrame.instrumentation.onBeforeCall(mainFrame, callMetadata); return { callMetadata, mainFrame };
this._currentAction = actionInContext;
return callMetadata;
} }
async didPerformAction(callMetadata: CallMetadata, actionInContext: ActionInContext, error?: Error) { async didPerformAction(callMetadata: CallMetadata, actionInContext: ActionInContext, error?: Error) {
if (!this._enabled) if (!this._enabled)
return; return;
if (error) { if (!error)
// Do not clear current action on delayed error.
if (this._currentAction === actionInContext)
this._currentAction = null;
} else {
this._currentAction = null;
this._actions.push(actionInContext); this._actions.push(actionInContext);
}
this._lastAction = actionInContext;
const mainFrame = mainFrameForAction(this._pageAliases, actionInContext); const mainFrame = mainFrameForAction(this._pageAliases, actionInContext);
callMetadata.endTime = monotonicTime(); callMetadata.endTime = monotonicTime();
await mainFrame.instrumentation.onAfterCall(mainFrame, callMetadata); await mainFrame.instrumentation.onAfterCall(mainFrame, callMetadata);
@ -101,27 +96,18 @@ export class RecorderCollection extends EventEmitter {
addRecordedAction(actionInContext: ActionInContext) { addRecordedAction(actionInContext: ActionInContext) {
if (!this._enabled) if (!this._enabled)
return; return;
this._currentAction = null;
const action = actionInContext.action; const action = actionInContext.action;
let eraseLastAction = false;
if (this._lastAction && this._lastAction.frame.pageAlias === actionInContext.frame.pageAlias) { const lastAction = this._lastAction && this._lastAction.frame.pageAlias === actionInContext.frame.pageAlias ? this._lastAction.action : undefined;
const lastAction = this._lastAction.action; if (lastAction && action.name === 'navigate' && lastAction.name === 'navigate' && action.url === lastAction.url) {
// We augment last action based on the type. // Already at a target URL.
if (this._lastAction && action.name === 'fill' && lastAction.name === 'fill') { return;
if (action.selector === lastAction.selector)
eraseLastAction = true;
}
if (lastAction && action.name === 'navigate' && lastAction.name === 'navigate') {
if (action.url === lastAction.url) {
// Already at a target URL.
return;
}
}
} }
this._lastAction = actionInContext; if (lastAction && action.name === 'fill' && lastAction.name === 'fill' && action.selector === lastAction.selector)
if (eraseLastAction)
this._actions.pop(); this._actions.pop();
this._lastAction = actionInContext;
this._actions.push(actionInContext); this._actions.push(actionInContext);
this.emit('change'); this.emit('change');
} }
@ -138,18 +124,7 @@ export class RecorderCollection extends EventEmitter {
if (!this._enabled) if (!this._enabled)
return; return;
// Signal either arrives while action is being performed or shortly after. if (this._lastAction && !this._lastAction.committed) {
if (this._currentAction) {
this._currentAction.action.signals.push(signal);
return;
}
if (this._lastAction && (!this._lastAction.committed || signal.name !== 'navigation')) {
const signals = this._lastAction.action.signals;
if (signal.name === 'navigation' && signals.length && signals[signals.length - 1].name === 'download')
return;
if (signal.name === 'download' && signals.length && signals[signals.length - 1].name === 'navigation')
signals.length = signals.length - 1;
this._lastAction.action.signals.push(signal); this._lastAction.action.signals.push(signal);
this.emit('change'); this.emit('change');
return; return;