Skip to content

Commit 4da9ea1

Browse files
committed
chore(mcp): share the snapshot assembly tail between aria and skip paths
1 parent 000541d commit 4da9ea1

1 file changed

Lines changed: 22 additions & 21 deletions

File tree

  • packages/playwright-core/src/tools/backend

packages/playwright-core/src/tools/backend/tab.ts

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -408,28 +408,29 @@ export class Tab extends EventEmitter<TabEventsInterface> {
408408

409409
async captureSnapshot(root: playwright.Locator | undefined, depth: number | undefined, boxes: boolean | undefined, relativeTo: string | undefined, includeAria: boolean = true): Promise<TabSnapshot> {
410410
await this._initializedPromise;
411-
// The caller will not render the aria snapshot, so skip the accessibility
412-
// tree walk, which dominates response latency on heavy pages. Console,
413-
// events and modal states are still reported.
414-
if (!includeAria) {
415-
if (this.modalStates().length)
416-
return { ariaSnapshot: '', modalStates: this.modalStates(), events: [] };
417-
const tabSnapshot: TabSnapshot = { ariaSnapshot: '', modalStates: [], events: this._recentEventEntries };
418-
this._recentEventEntries = [];
419-
tabSnapshot.consoleLink = await this._consoleLog.take(relativeTo);
420-
return tabSnapshot;
421-
}
422411
let tabSnapshot: TabSnapshot | undefined;
423-
const modalStates = await this._raceAgainstModalStates(async () => {
424-
const ariaSnapshot = root
425-
? await root.ariaSnapshot({ mode: 'ai', depth, boxes })
426-
: await this.page.ariaSnapshot({ mode: 'ai', depth, boxes });
427-
tabSnapshot = {
428-
ariaSnapshot,
429-
modalStates: [],
430-
events: [],
431-
};
432-
});
412+
let modalStates: ModalState[] = [];
413+
if (includeAria) {
414+
modalStates = await this._raceAgainstModalStates(async () => {
415+
const ariaSnapshot = root
416+
? await root.ariaSnapshot({ mode: 'ai', depth, boxes })
417+
: await this.page.ariaSnapshot({ mode: 'ai', depth, boxes });
418+
tabSnapshot = {
419+
ariaSnapshot,
420+
modalStates: [],
421+
events: [],
422+
};
423+
});
424+
} else if (this.modalStates().length) {
425+
// Matches the aria path's modal fallback below, without the race: there
426+
// is no tree walk for a modal to interrupt.
427+
modalStates = this.modalStates();
428+
} else {
429+
// The caller will not render the aria snapshot, so skip the accessibility
430+
// tree walk, which dominates response latency on heavy pages. Console and
431+
// events are still reported via the shared tail below.
432+
tabSnapshot = { ariaSnapshot: '', modalStates: [], events: [] };
433+
}
433434
if (tabSnapshot) {
434435
tabSnapshot.consoleLink = await this._consoleLog.take(relativeTo);
435436
tabSnapshot.events = this._recentEventEntries;

0 commit comments

Comments
 (0)