implement dimas suggestion

This commit is contained in:
Simon Knott 2024-11-04 11:17:31 +01:00
parent 93cf919c30
commit 6528ec3aba
No known key found for this signature in database
GPG key ID: 8CEDC00028084AEC

View file

@ -148,12 +148,12 @@ export class Recorder implements InstrumentationListener, IRecorder {
this._pushAllSources(); this._pushAllSources();
}); });
await this._context.exposeBinding('__pw_recorderState', false, source => { await this._context.exposeBinding('__pw_recorderState', false, async source => {
let actionSelector = ''; let actionSelector = '';
let actionPoint: Point | undefined; let actionPoint: Point | undefined;
const hasActiveScreenshotCommand = [...this._currentCallsMetadata.keys()].some(isScreenshotCommand); const hasActiveScreenshotCommand = [...this._currentCallsMetadata.keys()].some(isScreenshotCommand);
if (!hasActiveScreenshotCommand) { if (!hasActiveScreenshotCommand) {
actionSelector = this._scopeHighlightedSelectorToFrame(source.frame); actionSelector = await this._scopeHighlightedSelectorToFrame(source.frame);
for (const [metadata, sdkObject] of this._currentCallsMetadata) { for (const [metadata, sdkObject] of this._currentCallsMetadata) {
if (source.page === sdkObject.attribution.page) { if (source.page === sdkObject.attribution.page) {
actionPoint = metadata.point || actionPoint; actionPoint = metadata.point || actionPoint;
@ -245,15 +245,27 @@ export class Recorder implements InstrumentationListener, IRecorder {
this._refreshOverlay(); this._refreshOverlay();
} }
private _scopeHighlightedSelectorToFrame(frame: Frame): string { private async _scopeHighlightedSelectorToFrame(frame: Frame): Promise<string> {
if (this._highlightedSelector === '') try {
const mainFrame = frame._page.mainFrame();
const resolved = await mainFrame.selectors.resolveFrameForSelector(this._highlightedSelector);
// selector couldn't be found, don't highlight anything
if (!resolved)
return '';
// selector points to no specific frame, highlight in all frames
if (resolved?.frame === mainFrame)
return stringifySelector(resolved.info.parsed);
// selector points to this frame, highlight it
if (resolved?.frame === frame)
return stringifySelector(resolved.info.parsed);
// selector points to a different frame, highlight nothing
return ''; return '';
const parts = splitSelectorByFrame(this._highlightedSelector); } catch {
const selectorDepth = parts.length - 1;
const frameDepth = frame.depth();
if (frameDepth < selectorDepth)
return ''; return '';
return stringifySelector(parts[parts.length - 1]); }
} }
setOutput(codegenId: string, outputFile: string | undefined) { setOutput(codegenId: string, outputFile: string | undefined) {