implement dimas suggestion
This commit is contained in:
parent
93cf919c30
commit
6528ec3aba
|
|
@ -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 '';
|
return '';
|
||||||
const parts = splitSelectorByFrame(this._highlightedSelector);
|
|
||||||
const selectorDepth = parts.length - 1;
|
// selector points to no specific frame, highlight in all frames
|
||||||
const frameDepth = frame.depth();
|
if (resolved?.frame === mainFrame)
|
||||||
if (frameDepth < selectorDepth)
|
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 '';
|
||||||
return stringifySelector(parts[parts.length - 1]);
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setOutput(codegenId: string, outputFile: string | undefined) {
|
setOutput(codegenId: string, outputFile: string | undefined) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue