Skip to content

Commit 233f187

Browse files
authored
feat(inspector): remove snapshots (#6909)
1 parent a96491c commit 233f187

File tree

7 files changed

+21
-117
lines changed

7 files changed

+21
-117
lines changed

src/server/supplements/injected/recorder.ts

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ export class Recorder {
5050
private _actionPoint: Point | undefined;
5151
private _actionSelector: string | undefined;
5252
private _params: { isUnderTest: boolean; };
53-
private _snapshotIframe: HTMLIFrameElement | undefined;
54-
private _snapshotUrl: string | undefined;
55-
private _snapshotBaseUrl: string;
5653

57-
constructor(injectedScript: InjectedScript, params: { isUnderTest: boolean, snapshotBaseUrl: string }) {
54+
constructor(injectedScript: InjectedScript, params: { isUnderTest: boolean }) {
5855
this._params = params;
5956
this._injectedScript = injectedScript;
6057
this._outerGlassPaneElement = document.createElement('x-pw-glass');
@@ -66,7 +63,6 @@ export class Recorder {
6663
this._outerGlassPaneElement.style.zIndex = '2147483647';
6764
this._outerGlassPaneElement.style.pointerEvents = 'none';
6865
this._outerGlassPaneElement.style.display = 'flex';
69-
this._snapshotBaseUrl = params.snapshotBaseUrl;
7066

7167
this._tooltipElement = document.createElement('x-pw-tooltip');
7268
this._actionPointElement = document.createElement('x-pw-action-point');
@@ -160,28 +156,6 @@ export class Recorder {
160156
document.documentElement.appendChild(this._outerGlassPaneElement);
161157
}
162158

163-
private _createSnapshotIframeIfNeeded(): HTMLIFrameElement | undefined {
164-
if (this._snapshotIframe)
165-
return this._snapshotIframe;
166-
if (window.top === window) {
167-
this._snapshotIframe = document.createElement('iframe');
168-
this._snapshotIframe.src = this._snapshotBaseUrl;
169-
this._snapshotIframe.style.background = '#ff000060';
170-
this._snapshotIframe.style.position = 'fixed';
171-
this._snapshotIframe.style.top = '0';
172-
this._snapshotIframe.style.right = '0';
173-
this._snapshotIframe.style.bottom = '0';
174-
this._snapshotIframe.style.left = '0';
175-
this._snapshotIframe.style.border = 'none';
176-
this._snapshotIframe.style.width = '100%';
177-
this._snapshotIframe.style.height = '100%';
178-
this._snapshotIframe.style.zIndex = '2147483647';
179-
this._snapshotIframe.style.visibility = 'hidden';
180-
document.documentElement.appendChild(this._snapshotIframe);
181-
}
182-
return this._snapshotIframe;
183-
}
184-
185159
private async _pollRecorderMode() {
186160
const pollPeriod = 1000;
187161
if (this._pollRecorderModeTimer)
@@ -192,7 +166,7 @@ export class Recorder {
192166
return;
193167
}
194168

195-
const { mode, actionPoint, actionSelector, snapshotUrl } = state;
169+
const { mode, actionPoint, actionSelector } = state;
196170
if (mode !== this._mode) {
197171
this._mode = mode;
198172
this._clearHighlight();
@@ -221,18 +195,6 @@ export class Recorder {
221195
this._updateHighlight();
222196
this._actionSelector = actionSelector;
223197
}
224-
if (snapshotUrl !== this._snapshotUrl) {
225-
this._snapshotUrl = snapshotUrl;
226-
const snapshotIframe = this._createSnapshotIframeIfNeeded();
227-
if (snapshotIframe) {
228-
if (!snapshotUrl) {
229-
snapshotIframe.style.visibility = 'hidden';
230-
} else {
231-
snapshotIframe.style.visibility = 'visible';
232-
snapshotIframe.contentWindow?.postMessage({ snapshotUrl }, '*');
233-
}
234-
}
235-
}
236198
this._pollRecorderModeTimer = setTimeout(() => this._pollRecorderMode(), pollPeriod);
237199
}
238200

src/server/supplements/recorder/recorderTypes.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ import { Point } from '../../../common/types';
1919
export type Mode = 'inspecting' | 'recording' | 'none';
2020

2121
export type EventData = {
22-
event: 'clear' | 'resume' | 'step' | 'pause' | 'setMode' | 'selectorUpdated' | 'callLogHovered';
22+
event: 'clear' | 'resume' | 'step' | 'pause' | 'setMode' | 'selectorUpdated';
2323
params: any;
2424
};
2525

2626
export type UIState = {
2727
mode: Mode;
2828
actionPoint?: Point;
2929
actionSelector?: string;
30-
snapshotUrl?: string;
3130
};
3231

3332
export type CallLogStatus = 'in-progress' | 'done' | 'error' | 'paused';
@@ -44,11 +43,6 @@ export type CallLog = {
4443
url?: string,
4544
selector?: string,
4645
};
47-
snapshots: {
48-
before: boolean,
49-
action: boolean,
50-
after: boolean,
51-
}
5246
};
5347

5448
export type SourceHighlight = {

src/server/supplements/recorder/recorderUtils.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import { CallMetadata } from '../../instrumentation';
1818
import { CallLog, CallLogStatus } from './recorderTypes';
1919

20-
export function metadataToCallLog(metadata: CallMetadata, status: CallLogStatus, snapshots: Set<string>): CallLog {
20+
export function metadataToCallLog(metadata: CallMetadata, status: CallLogStatus): CallLog {
2121
const title = metadata.apiName || metadata.method;
2222
if (metadata.error)
2323
status = 'error';
@@ -38,23 +38,6 @@ export function metadataToCallLog(metadata: CallMetadata, status: CallLogStatus,
3838
error: metadata.error,
3939
params,
4040
duration,
41-
snapshots: {
42-
before: showBeforeSnapshot(metadata) && snapshots.has(`before@${metadata.id}`),
43-
action: showActionSnapshot(metadata) && snapshots.has(`action@${metadata.id}`),
44-
after: showAfterSnapshot(metadata) && snapshots.has(`after@${metadata.id}`),
45-
}
4641
};
4742
return callLog;
4843
}
49-
50-
function showBeforeSnapshot(metadata: CallMetadata): boolean {
51-
return metadata.method === 'close';
52-
}
53-
54-
function showActionSnapshot(metadata: CallMetadata): boolean {
55-
return ['click', 'dblclick', 'check', 'uncheck', 'fill', 'press'].includes(metadata.method);
56-
}
57-
58-
function showAfterSnapshot(metadata: CallMetadata): boolean {
59-
return ['goto', 'click', 'dblclick', 'dblclick', 'check', 'uncheck', 'fill', 'press'].includes(metadata.method);
60-
}

src/server/supplements/recorderSupplement.ts

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { CallMetadata, InstrumentationListener, internalCallMetadata, SdkObject
3333
import { Point } from '../../common/types';
3434
import { CallLog, CallLogStatus, EventData, Mode, Source, UIState } from './recorder/recorderTypes';
3535
import { isUnderTest } from '../../utils/utils';
36-
import { InMemorySnapshotter } from '../snapshot/inMemorySnapshotter';
3736
import { metadataToCallLog } from './recorder/recorderUtils';
3837
import { Debugger } from './debugger';
3938

@@ -56,9 +55,6 @@ export class RecorderSupplement implements InstrumentationListener {
5655
private _currentCallsMetadata = new Map<CallMetadata, SdkObject>();
5756
private _recorderSources: Source[];
5857
private _userSources = new Map<string, Source>();
59-
private _snapshotter: InMemorySnapshotter;
60-
private _hoveredSnapshot: { callLogId: string, phase: 'before' | 'after' | 'action' } | undefined;
61-
private _snapshots = new Set<string>();
6258
private _allMetadatas = new Map<string, CallMetadata>();
6359
private _debugger: Debugger;
6460

@@ -129,14 +125,12 @@ export class RecorderSupplement implements InstrumentationListener {
129125
});
130126
}
131127
this._generator = generator;
132-
this._snapshotter = new InMemorySnapshotter(context);
133128
}
134129

135130
async install() {
136131
const recorderApp = await RecorderApp.open(this._context);
137132
this._recorderApp = recorderApp;
138133
recorderApp.once('close', () => {
139-
this._snapshotter.dispose().catch(() => {});
140134
this._recorderApp = null;
141135
});
142136
recorderApp.on('event', (data: EventData) => {
@@ -150,13 +144,6 @@ export class RecorderSupplement implements InstrumentationListener {
150144
this._refreshOverlay();
151145
return;
152146
}
153-
if (data.event === 'callLogHovered') {
154-
this._hoveredSnapshot = undefined;
155-
if (this._debugger.isPaused() && data.params.callLogId)
156-
this._hoveredSnapshot = data.params;
157-
this._refreshOverlay();
158-
return;
159-
}
160147
if (data.event === 'step') {
161148
this._debugger.resume(true);
162149
return;
@@ -202,26 +189,18 @@ export class RecorderSupplement implements InstrumentationListener {
202189
(source: BindingSource, action: actions.Action) => this._recordAction(source.frame, action), 'utility');
203190

204191
await this._context.exposeBinding('_playwrightRecorderState', false, source => {
205-
let snapshotUrl: string | undefined;
206192
let actionSelector = this._highlightedSelector;
207193
let actionPoint: Point | undefined;
208-
if (this._hoveredSnapshot) {
209-
const metadata = this._allMetadatas.get(this._hoveredSnapshot.callLogId)!;
210-
snapshotUrl = `${metadata.pageId}?name=${this._hoveredSnapshot.phase}@${this._hoveredSnapshot.callLogId}`;
211-
actionPoint = this._hoveredSnapshot.phase === 'action' ? metadata?.point : undefined;
212-
} else {
213-
for (const [metadata, sdkObject] of this._currentCallsMetadata) {
214-
if (source.page === sdkObject.attribution.page) {
215-
actionPoint = metadata.point || actionPoint;
216-
actionSelector = actionSelector || metadata.params.selector;
217-
}
194+
for (const [metadata, sdkObject] of this._currentCallsMetadata) {
195+
if (source.page === sdkObject.attribution.page) {
196+
actionPoint = metadata.point || actionPoint;
197+
actionSelector = actionSelector || metadata.params.selector;
218198
}
219199
}
220200
const uiState: UIState = {
221201
mode: this._mode,
222202
actionPoint,
223203
actionSelector,
224-
snapshotUrl,
225204
};
226205
return uiState;
227206
}, 'utility');
@@ -236,8 +215,7 @@ export class RecorderSupplement implements InstrumentationListener {
236215
this._debugger.resume(false);
237216
}, 'main');
238217

239-
const snapshotBaseUrl = await this._snapshotter.initialize() + '/snapshot/';
240-
await this._context.extendInjectedScript('utility', recorderSource.source, { isUnderTest: isUnderTest(), snapshotBaseUrl });
218+
await this._context.extendInjectedScript('utility', recorderSource.source, { isUnderTest: isUnderTest() });
241219
await this._context.extendInjectedScript('main', consoleApiSource.source);
242220

243221
if (this._debugger.isPaused())
@@ -391,18 +369,9 @@ export class RecorderSupplement implements InstrumentationListener {
391369
this._generator.signal(pageAlias, page.mainFrame(), { name: 'dialog', dialogAlias: String(++this._lastDialogOrdinal) });
392370
}
393371

394-
_captureSnapshot(sdkObject: SdkObject, metadata: CallMetadata, phase: 'before' | 'after' | 'action') {
395-
if (sdkObject.attribution.page) {
396-
const snapshotName = `${phase}@${metadata.id}`;
397-
this._snapshots.add(snapshotName);
398-
this._snapshotter.captureSnapshot(sdkObject.attribution.page, snapshotName);
399-
}
400-
}
401-
402372
async onBeforeCall(sdkObject: SdkObject, metadata: CallMetadata) {
403373
if (this._mode === 'recording')
404374
return;
405-
this._captureSnapshot(sdkObject, metadata, 'before');
406375
this._currentCallsMetadata.set(metadata, sdkObject);
407376
this._allMetadatas.set(metadata.id, metadata);
408377
this._updateUserSources();
@@ -416,7 +385,6 @@ export class RecorderSupplement implements InstrumentationListener {
416385
async onAfterCall(sdkObject: SdkObject, metadata: CallMetadata) {
417386
if (this._mode === 'recording')
418387
return;
419-
this._captureSnapshot(sdkObject, metadata, 'after');
420388
if (!metadata.error)
421389
this._currentCallsMetadata.delete(metadata);
422390
this._updateUserSources();
@@ -458,9 +426,6 @@ export class RecorderSupplement implements InstrumentationListener {
458426
}
459427

460428
async onBeforeInputAction(sdkObject: SdkObject, metadata: CallMetadata) {
461-
if (this._mode === 'recording')
462-
return;
463-
this._captureSnapshot(sdkObject, metadata, 'action');
464429
}
465430

466431
async onCallLog(logName: string, message: string, sdkObject: SdkObject, metadata: CallMetadata): Promise<void> {
@@ -479,7 +444,7 @@ export class RecorderSupplement implements InstrumentationListener {
479444
status = 'in-progress';
480445
if (this._debugger.isPaused(metadata))
481446
status = 'paused';
482-
logs.push(metadataToCallLog(metadata, status, this._snapshots));
447+
logs.push(metadataToCallLog(metadata, status));
483448
}
484449
this._recorderApp?.updateCallLogs(logs);
485450
}

src/web/recorder/callLog.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
.call-log-call .codicon {
5050
padding: 0 4px;
51+
flex: none;
5152
}
5253

5354
.call-log .codicon-check {
@@ -66,6 +67,12 @@
6667
color: red;
6768
}
6869

70+
.call-log-details {
71+
flex: 0 1 auto;
72+
overflow-x: hidden;
73+
text-overflow: ellipsis;
74+
}
75+
6976
.call-log-url {
7077
color: var(--blue);
7178
}
@@ -75,6 +82,7 @@
7582
}
7683

7784
.call-log-time {
85+
flex: none;
7886
margin-left: 4px;
7987
color: var(--gray);
8088
}

src/web/recorder/callLog.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ import { msToString } from '../uiUtils';
2121

2222
export interface CallLogProps {
2323
log: CallLog[],
24-
onHover: (callLog: CallLog | undefined, phase?: 'before' | 'after' | 'action') => void
2524
}
2625

2726
export const CallLogView: React.FC<CallLogProps> = ({
2827
log,
29-
onHover,
3028
}) => {
3129
const messagesEndRef = React.createRef<HTMLDivElement>();
3230
const [expandOverrides, setExpandOverrides] = React.useState<Map<string, boolean>>(new Map());
@@ -47,14 +45,10 @@ export const CallLogView: React.FC<CallLogProps> = ({
4745
setExpandOverrides(newOverrides);
4846
}}></span>
4947
{ callLog.title }
50-
{ callLog.params.url ? <span>(<span className='call-log-url'>{callLog.params.url}</span>)</span> : undefined }
51-
{ callLog.params.selector ? <span>(<span className='call-log-selector'>{callLog.params.selector}</span>)</span> : undefined }
48+
{ callLog.params.url ? <span className='call-log-details'>(<span className='call-log-url' title={callLog.params.url}>{callLog.params.url}</span>)</span> : undefined }
49+
{ callLog.params.selector ? <span className='call-log-details'>(<span className='call-log-selector' title={callLog.params.selector}>{callLog.params.selector}</span>)</span> : undefined }
5250
<span className={'codicon ' + iconClass(callLog)}></span>
5351
{ typeof callLog.duration === 'number' ? <span className='call-log-time'>{msToString(callLog.duration)}</span> : undefined}
54-
{ <div style={{flex: 'auto'}}></div> }
55-
<span className={'codicon codicon-vm-outline preview' + (callLog.snapshots.before ? '' : ' invisible')} onMouseEnter={() => onHover(callLog, 'before')} onMouseLeave={() => onHover(undefined)}></span>
56-
<span className={'codicon codicon-vm-running preview' + (callLog.snapshots.action ? '' : ' invisible')} onMouseEnter={() => onHover(callLog, 'action')} onMouseLeave={() => onHover(undefined)}></span>
57-
<span className={'codicon codicon-vm-active preview' + (callLog.snapshots.after ? '' : ' invisible')} onMouseEnter={() => onHover(callLog, 'after')} onMouseLeave={() => onHover(undefined)}></span>
5852
</div>
5953
{ (isExpanded ? callLog.messages : []).map((message, i) => {
6054
return <div className='call-log-message' key={i}>

src/web/recorder/recorder.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,7 @@ export const Recorder: React.FC<RecorderProps> = ({
121121
window.dispatch({ event: 'selectorUpdated', params: { selector: event.target.value } });
122122
}} />
123123
</Toolbar>
124-
<CallLogView log={Array.from(log.values())} onHover={(callLog, phase) => {
125-
window.dispatch({ event: 'callLogHovered', params: { callLogId: callLog?.id, phase } });
126-
}}/>
124+
<CallLogView log={Array.from(log.values())}/>
127125
</div>
128126
</SplitView>
129127
</div>;

0 commit comments

Comments
 (0)