chore: make InjectedScript know the frameSeq (#41635)

This commit is contained in:
Dmitry Gozman
2026-07-06 13:31:13 +01:00
committed by GitHub
parent 7eab458bf7
commit bd93b1441e
4 changed files with 7 additions and 3 deletions
+4
View File
@@ -78,6 +78,7 @@ interface WebKitLegacyDeviceMotionEvent extends DeviceMotionEvent {
export type InjectedScriptOptions = {
isUnderTest: boolean;
sdkLanguage: Language;
frameSeq: number;
// For strict error and codegen
testIdAttributeName: string;
stableRafCount: number;
@@ -99,6 +100,7 @@ export class InjectedScript {
private _highlight: Highlight | undefined;
readonly isUnderTest: boolean;
private _sdkLanguage: Language;
private _frameSeq: number;
private _testIdAttributeNameForStrictErrorAndConsoleCodegen: string = 'data-testid';
readonly window: Window & typeof globalThis;
readonly document: Document;
@@ -141,6 +143,7 @@ export class InjectedScript {
// inside a trace viewer snapshot, where "window" differs from "globalThis".
this.utils.builtins = new UtilityScript(window, options.isUnderTest).builtins;
this._sdkLanguage = options.sdkLanguage;
this._frameSeq = options.frameSeq;
this._testIdAttributeNameForStrictErrorAndConsoleCodegen = options.testIdAttributeName;
this._evaluator = new SelectorEvaluatorImpl();
this.consoleApi = new ConsoleAPI(this);
@@ -318,6 +321,7 @@ export class InjectedScript {
ariaSnapshotWithRefs(node: Node, options: AriaTreeOptions & { depth?: number }): { text: string, iframeRefs: string[], iframeDepths: Record<string, number> } {
if (node.nodeType !== Node.ELEMENT_NODE)
throw this.createStacklessError('Can only capture aria snapshot of Element nodes.');
options = { ...options, refPrefix: this._frameSeq && options.mode === 'ai' ? 'f' + this._frameSeq : '' };
const ariaSnapshot = generateAriaTree(node as Element, options);
const rendered = renderAriaTree(ariaSnapshot, options);
this._lastAriaSnapshotForQuery = ariaSnapshot;
@@ -91,6 +91,7 @@ export class FrameExecutionContext extends js.ExecutionContext {
const options: InjectedScriptOptions = {
isUnderTest: isUnderTest(),
sdkLanguage,
frameSeq: this.frame.seq,
testIdAttributeName: selectorsRegistry.testIdAttributeName(),
stableRafCount: this.frame._page.delegate.rafCountForStablePosition(),
browserName: this.frame._page.browserContext._browser.options.name,
@@ -1121,7 +1121,6 @@ export async function ariaSnapshotForFrame(progress: Progress, frame: frames.Fra
return injected.ariaSnapshotWithRefs(element, options);
}, {
mode: options.mode ?? 'default',
refPrefix: resolvedFrame.seq ? 'f' + resolvedFrame.seq : '',
doNotRenderActive: options.doNotRenderActive,
info: resolved.info,
depth: options.depth,
+2 -2
View File
@@ -86,7 +86,7 @@ export const SnapshotTabsView: React.FunctionComponent<{
<ToolbarButton icon='link-external' title='Open snapshot in a new tab' disabled={!snapshotUrls?.popoutUrl} onClick={() => {
const win = window.open(snapshotUrls?.popoutUrl || '', '_blank');
win?.addEventListener('DOMContentLoaded', () => {
const injectedScript = new InjectedScript(win as any, { isUnderTest, sdkLanguage, testIdAttributeName, stableRafCount: 1, browserName: 'chromium', customEngines: [] });
const injectedScript = new InjectedScript(win as any, { isUnderTest, frameSeq: 0, sdkLanguage, testIdAttributeName, stableRafCount: 1, browserName: 'chromium', customEngines: [] });
injectedScript.consoleApi.install();
});
}} />
@@ -311,7 +311,7 @@ function createRecorders(recorders: { recorder: Recorder, frameSelector: string
return;
const win = frameWindow as any;
if (!win._recorder && force) {
const injectedScript = new InjectedScript(frameWindow as any, { isUnderTest, sdkLanguage, testIdAttributeName, stableRafCount: 1, browserName: 'chromium', customEngines: [] });
const injectedScript = new InjectedScript(frameWindow as any, { isUnderTest, frameSeq: 0, sdkLanguage, testIdAttributeName, stableRafCount: 1, browserName: 'chromium', customEngines: [] });
const recorder = new Recorder(injectedScript);
win._injectedScript = injectedScript;
win._recorder = { recorder, frameSelector: parentFrameSelector };