fix(preview): keep snapshots slim unless the agent asks #7302
Closedgb1095(GitHub profile, opens in a new tab)wants to merge 15 commits into
main fromrefs/pull/7302/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/desktop/src/preview/Manager.ts line 2924OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2905,6 +2912,13 @@29052912 const rect = element.getBoundingClientRect();29062913 return style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;29072914 };2915+ const clickable = (element) => {2916+ if (element.matches("a[href],button,input,textarea,select,[role],[tabindex]")) return true;2917+ const role = element.getAttribute("role");2918+ if (role === "row" || role === "gridcell" || role === "option") return true;2919+ const style = getComputedStyle(element);2920+ return style.cursor === "pointer" && (element.tagName === "TR" || element.tagName === "TD" || element.tagName === "DIV");2921+ };2922+ const seen = new Set();29082923 const elements = Array.from(document.querySelectorAll(2909- "a[href],button,input,textarea,select,[role],[tabindex]"2910- )).filter(visible).slice(0, ${MAX_INTERACTIVE_ELEMENTS}).map((element) => {2924+ "a[href],button,input,textarea,select,[role],[tabindex],[role=row],tr,[role=gridcell]"apps/desktop/src/preview/Manager.ts line 2948OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2911,17 +2930,19 @@29112930 const rect = element.getBoundingClientRect();29122931 return {2932+ id: "e" + (index + 1),29132933 tag: element.tagName.toLowerCase(),29142934 role: element.getAttribute("role"),2915- name: element.getAttribute("aria-label") || element.innerText || element.getAttribute("name") || "",2935+ name: (element.getAttribute("aria-label") || element.innerText || element.getAttribute("name") || "").slice(0, 160),29162936 selector: selectorFor(element),29172937 x: rect.x,29182938 y: rect.y,29192939 width: rect.width,29202940 height: rect.height29212941 };29222942 });2943+ const main = document.querySelector("main");29232944 return {29242945 url: location.href,29252946 title: document.title,29262947 loading: document.readyState !== "complete",2927- visibleText: (document.body?.innerText || "").slice(0, ${MAX_VISIBLE_TEXT_LENGTH}),2948+ visibleText: ((main && main.innerText) || document.body?.innerText || "").slice(0, ${MAX_VISIBLE_TEXT_LENGTH}),
- apps/desktop/src/preview/Manager.ts lines 3725 to 3727Resolvedby gb1095(GitHub profile, opens in a new tab)@@ -2952,6 +2988,6 @@29522988 const browserDiagnostics = diagnostics.get(wc.id);29532989 return {29542990 ...page,2955- accessibilityTree: accessibility,2956- consoleEntries: [...(browserDiagnostics?.consoleEntries ?? [])],2957- networkEntries: [...(browserDiagnostics?.networkEntries ?? [])],2991+ ...(includeAx ? { accessibilityTree: accessibility } : {}),2992+ consoleEntries: includeConsole ? [...(browserDiagnostics?.consoleEntries ?? [])] : [],2993+ networkEntries: includeNetwork ? [...(browserDiagnostics?.networkEntries ?? [])] : [],apps/desktop/src/preview/Manager.ts lines 2967 to 2980OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -2942 +2960,21 @@2960+ {2961+ operation: "automationSnapshot.capturePage",2962+ tabId,2963+ webContentsId: wc.id,2964+ },2965+ () => wc.capturePage(),2966+ ).pipe(2967+ Effect.catch(() =>2968+ send("Page.captureScreenshot", { format: "png" }).pipe(2969+ Effect.map((result) => {2970+ const data =2971+ result !== null &&2972+ typeof result === "object" &&2973+ "data" in result &&2974+ typeof result.data === "string"2975+ ? result.data2976+ : "";2977+ return nativeImage.createFromBuffer(Buffer.from(data, "base64"));2978+ }),2979+ ),29422980 ),
- apps/desktop/src/preview/Manager.ts line 3665Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2905,6 +2912,18 @@29052912 const rect = element.getBoundingClientRect();29062913 return style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;29072914 };2915+ const clickable = (element) => {2916+ if (element.matches("a[href],button,input,textarea,select,[role],[tabindex]")) return true;2917+ const role = element.getAttribute("role");2918+ if (role === "row" || role === "gridcell" || role === "option") return true;2919+ const style = getComputedStyle(element);2920+ return style.cursor === "pointer" && (element.tagName === "TR" || element.tagName === "TD" || element.tagName === "DIV");2921+ };2922+ const seen = new Set();29082923 const elements = Array.from(document.querySelectorAll(2909- "a[href],button,input,textarea,select,[role],[tabindex]"2910- )).filter(visible).slice(0, ${MAX_INTERACTIVE_ELEMENTS}).map((element) => {2924+ "a[href],button,input,textarea,select,[role],[tabindex],[role=row],tr,[role=gridcell],div,td"2925+ )).filter((element) => {2926+ if (!visible(element) || !clickable(element) || seen.has(element)) return false;2927+ seen.add(element);2928+ return true;2929+ }).slice(0, ${MAX_INTERACTIVE_ELEMENTS}).map((element, index) => {
- apps/desktop/src/preview/Manager.ts line 2925OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -2905,3 +2912,14 @@29052912 const rect = element.getBoundingClientRect();29062913 return style.visibility !== "hidden" && style.display !== "none" && rect.width > 0 && rect.height > 0;29072914 };2915+ const clickable = (element) => {2916+ if (element.matches("a[href],button,input,textarea,select,[role],[tabindex]")) return true;2917+ const role = element.getAttribute("role");2918+ if (role === "row" || role === "gridcell" || role === "option") return true;2919+ if (element.tagName !== "TR" && element.tagName !== "TD" && element.tagName !== "DIV") return false;2920+ const style = getComputedStyle(element);2921+ if (style.cursor !== "pointer") return false;2922+ // cursor is inherited. Keep the outermost pointer container so2923+ // nested layout nodes do not fill the interactive-element cap.2924+ const parent = element.parentElement;2925+ return !parent || getComputedStyle(parent).cursor !== "pointer";
- apps/desktop/src/preview/Manager.ts line 4030OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -3969,4 +4018,13 @@39694018 send,39704019 `(() => {39714020 try {3972- const selectorMatched = ${locatorJson ? `(() => { const injected = globalThis.__t3PlaywrightInjected; return injected.querySelector(injected.parseSelector(${locatorJson}), document, false) !== null; })()` : "true"};4021+ const root = ${scopeJson} === "document"4022+ ? document.documentElement4023+ : (document.querySelector("main") || document.documentElement);4024+ const selectorMatched = ${4025+ locatorJson4026+ ? `(() => {4027+ const injected = globalThis.__t3PlaywrightInjected;4028+ const parsed = injected.parseSelector(${locatorJson});4029+ const element = injected.querySelector(parsed, root, false);4030+ if (!element) return false;apps/desktop/src/preview/Manager.ts line 4023OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -3969,4 +4018,6 @@39694018 send,39704019 `(() => {39714020 try {3972- const selectorMatched = ${locatorJson ? `(() => { const injected = globalThis.__t3PlaywrightInjected; return injected.querySelector(injected.parseSelector(${locatorJson}), document, false) !== null; })()` : "true"};4021+ const root = ${scopeJson} === "document"4022+ ? document.documentElement4023+ : (document.querySelector("main") || document.documentElement);
- apps/desktop/src/preview/Manager.ts line 4038OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3970,3 +4019,20 @@39704019 `(() => {39714020 try {3972- const selectorMatched = ${locatorJson ? `(() => { const injected = globalThis.__t3PlaywrightInjected; return injected.querySelector(injected.parseSelector(${locatorJson}), document, false) !== null; })()` : "true"};4021+ const root = ${scopeJson} === "document"4022+ ? document.documentElement4023+ : (document.querySelector('main, [role="main"]') || document.documentElement);4024+ const searchRoots = ${scopeJson} === "document"4025+ ? [root]4026+ : [4027+ root,4028+ ...Array.from(document.querySelectorAll(4029+ '[aria-modal="true"], [role="dialog"], [role="alertdialog"], [data-slot$="-popup"], [data-slot$="-viewport"], [data-slot$="-positioner"], [data-slot$="-portal"], [data-radix-portal], [data-radix-popper-content-wrapper]'4030+ )),4031+ ];4032+ const selectorMatched = ${4033+ locatorJson4034+ ? `(() => {4035+ const injected = globalThis.__t3PlaywrightInjected;4036+ const parsed = injected.parseSelector(${locatorJson});4037+ return searchRoots.some((searchRoot) => {4038+ const element = injected.querySelector(parsed, searchRoot, false);
- @@ -3973,2 +4035,20 @@4035+ const injected = globalThis.__t3PlaywrightInjected;4036+ const parsed = injected.parseSelector(${locatorJson});4037+ return searchRoots.some((searchRoot) => {4038+ const element = injected.querySelector(parsed, searchRoot, false);4039+ if (!element) return false;4040+ const visible = injected.elementState(element, "visible");4041+ if (!visible.matches) return false;4042+ if (element.getAttribute("role") === "dialog") {4043+ const slot = element.getAttribute("data-slot") || "";4044+ if (slot.includes("trigger")) return false;4045+ }4046+ return true;4047+ });4048+ })()`4049+ : "true"4050+ };39734051 const textMatched = ${3974- textJson ? `(document.body?.innerText || "").includes(${textJson})` : "true"4052+ textJson4053+ ? `searchRoots.some((searchRoot) => (searchRoot.innerText || "").includes(${textJson}))`4054+ : "true"
- apps/desktop/src/preview/Manager.ts line 4224Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3972,0 +4022,21 @@4022+ ? document.documentElement4023+ : (document.querySelector('main, [role="main"]') || document.documentElement);4024+ const searchRoots = ${scopeJson} === "document"4025+ ? [root]4026+ : [4027+ root,4028+ ...Array.from(document.querySelectorAll(4029+ '[aria-modal="true"], [role="dialog"], [role="alertdialog"], [data-slot$="-popup"], [data-slot$="-positioner"], [data-slot$="-portal"], [data-radix-portal], [data-radix-popper-content-wrapper]'4030+ )),4031+ ];4032+ const selectorMatched = ${4033+ locatorJson4034+ ? `(() => {4035+ const injected = globalThis.__t3PlaywrightInjected;4036+ const parsed = injected.parseSelector(${locatorJson});4037+ const elements = injected.querySelectorAll(parsed, document);4038+ return searchRoots.some((searchRoot) => {4039+ return elements.some((element) => {4040+ if (element !== searchRoot && !searchRoot.contains(element)) return false;4041+ const visible = injected.elementState(element, "visible");4042+ if (!visible.matches) return false;
- apps/desktop/src/preview/Manager.ts line 3600Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3414,8 +3415,13 @@34143415 });3415341634163417 const captureAutomationSnapshot = Effect.fn("PreviewManager.captureAutomationSnapshot")(3417- function* (tabId: string, wc: Electron.WebContents, send: SendCommand) {3418- yield* Effect.all([send("Runtime.enable"), send("Accessibility.enable")], {3419- concurrency: 2,3420- discard: true,3421- });3418+ function* (3419+ tabId: string,3420+ wc: Electron.WebContents,3421+ send: SendCommand,3422+ include: ReadonlyArray<PreviewAutomationSnapshotInclude> = [],3423+ ) {3424+ const includeAx = include.includes("ax");3425+ const includeConsole = include.includes("console");3426+ const includeNetwork = include.includes("network");3427+ yield* send("Runtime.enable");
- apps/desktop/src/preview/Manager.ts line 4105OutdatedResolvedby gb1095(GitHub profile, opens in a new tab)@@ -4037 +4086,20 @@4037- const selectorMatched = ${locatorJson ? `(() => { const injected = globalThis.__t3PlaywrightInjected; return injected.querySelector(injected.parseSelector(${locatorJson}), document, false) !== null; })()` : "true"};4086+ const root = ${scopeJson} === "document"4087+ ? document.documentElement4088+ : (document.querySelector('main, [role="main"]') || document.documentElement);4089+ const searchRoots = ${scopeJson} === "document"4090+ ? [root]4091+ : [4092+ root,4093+ ...Array.from(document.querySelectorAll(4094+ '[aria-modal="true"], [role="dialog"], [role="alertdialog"], [data-slot$="-popup"], [data-slot$="-positioner"], [data-slot$="-portal"], [data-radix-portal], [data-radix-popper-content-wrapper]'4095+ )),4096+ ];4097+ const selectorMatched = ${4098+ locatorJson4099+ ? `(() => {4100+ const injected = globalThis.__t3PlaywrightInjected;4101+ const parsed = injected.parseSelector(${locatorJson});4102+ const elements = injected.querySelectorAll(parsed, document);4103+ return searchRoots.some((searchRoot) => {4104+ return elements.some((element) => {4105+ if (element !== searchRoot && !searchRoot.contains(element)) return false;
- apps/desktop/src/preview/Manager.ts line 1217OutdatedResolvedby gb1095(GitHub profile, opens in a new tab)@@ -1166,4 +1211,7 @@11661211 PreviewManagerError11671212 > => {11681213 const existing = sessions.get(wc.id);1169- if (existing) return Effect.succeed([existing, sessions] as const);1214+ if (existing) {1215+ return enableDiagnosticDomains(existing, wc, requestedDiagnosticDomains).pipe(1216+ Effect.as([existing, sessions] as const),1217+ );apps/desktop/src/preview/Manager.ts line 4183OutdatedResolvedby gb1095(GitHub profile, opens in a new tab)@@ -4037,0 +4163,21 @@4163+ const searchRoots = ${scopeJson} === "document"4164+ ? [root]4165+ : [4166+ root,4167+ ...Array.from(document.querySelectorAll(4168+ '[aria-modal="true"], [role="dialog"], [role="alertdialog"], [data-slot$="-popup"], [data-slot$="-positioner"], [data-slot$="-portal"], [data-radix-portal], [data-radix-popper-content-wrapper]'4169+ )),4170+ ];4171+ const selectorMatched = ${4172+ locatorJson4173+ ? `(() => {4174+ const injected = globalThis.__t3PlaywrightInjected;4175+ const parsed = injected.parseSelector(${locatorJson});4176+ const elements = injected.querySelectorAll(parsed, document);4177+ return searchRoots.some((searchRoot) => {4178+ return elements.some((element) => {4179+ if (!isWithinSearchRoot(element, searchRoot)) return false;4180+ const visible = injected.elementState(element, "visible");4181+ if (!visible.matches) return false;4182+ const slot = element.getAttribute("data-slot") || "";4183+ if (slot.includes("trigger")) return false;
- apps/desktop/src/preview/Manager.ts line 1421OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1350,5 +1418,4 @@13501418 };13511419 yield* pushAction(tabId, actionEvent);13521420 const epoch = (yield* Ref.get(controlEpochRef)).get(tabId) ?? 0;1353- const control = yield* ensureControlSession(wc);1354- const execute = Effect.fn("PreviewManager.executeControlAction")(function* () {1421+ const requestedWc = yield* requireWebContents(tabId);
- apps/desktop/src/preview/Manager.ts line 1507OutdatedResolvedby gb1095(GitHub profile, opens in a new tab)@@ -1427,4 +1504,4 @@14271504 const tabs = yield* SynchronizedRef.get(tabsRef);14281505 if (tabs.has(tabId)) yield* update(tabId, { controller: "none" });14291506 });1430- return yield* control.semaphore.withPermit(execute().pipe(Effect.onExit(finalize)));1507+ return yield* control.semaphore.withPermit(execute(activeWc).pipe(Effect.onExit(finalize)));
- apps/desktop/src/preview/Manager.ts line 1530OutdatedResolvedby gb1095(GitHub profile, opens in a new tab)@@ -1438,0 +1510,21 @@1510+ const controlWc = yield* requireWebContents(tabId);1511+ const control = yield* ensureControlSession(controlWc, requestedDiagnosticDomains);1512+ const result = yield* control.semaphore.withPermit(1513+ Effect.gen(function* () {1514+ const liveWc = yield* requireWebContents(tabId);1515+ const liveControl = (yield* SynchronizedRef.get(controlSessionsRef)).get(liveWc.id);1516+ if (liveWc !== controlWc || liveControl !== control) return Option.none<A>();1517+ return Option.some(yield* execute(controlWc, control));1518+ }),1519+ );1520+ if (Option.isSome(result)) return result.value;1521+ if (remainingAttempts > 1) {1522+ return yield* Effect.suspend(() => acquireAndExecute(remainingAttempts - 1));1523+ }1524+ return yield* new PreviewAutomationControlInterruptedError({1525+ operation: action,1526+ tabId,1527+ webContentsId: controlWc.id,1528+ });1529+ });1530+ return yield* acquireAndExecute(3).pipe(Effect.onExit(finalize));
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
8834cb66-be84-4273-a921-43d3e4b089ceYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share