MCPcopy
hub / github.com/virattt/dexter / takeSnapshot

Function takeSnapshot

src/tools/browser/browser.ts:224–250  ·  view source on GitHub ↗

* Take an AI-optimized snapshot using Playwright's _snapshotForAI method. * Falls back to ariaSnapshot if _snapshotForAI is not available.

(p: Page, maxChars?: number)

Source from the content-addressed store, hash-verified

222 * Falls back to ariaSnapshot if _snapshotForAI is not available.
223 */
224async function takeSnapshot(p: Page, maxChars?: number): Promise<{ snapshot: string; truncated: boolean }> {
225 const pageWithSnapshot = p as PageWithSnapshotForAI;
226
227 let snapshot: string;
228
229 if (pageWithSnapshot._snapshotForAI) {
230 // Use the AI-optimized snapshot method
231 const result = await pageWithSnapshot._snapshotForAI({ timeout: 10000, track: 'response' });
232 snapshot = String(result?.full ?? '');
233 } else {
234 // Fallback to standard ariaSnapshot
235 snapshot = await p.locator(':root').ariaSnapshot();
236 }
237
238 // Parse and store refs for later action resolution
239 currentRefs = parseRefsFromSnapshot(snapshot);
240
241 // Truncate if needed
242 let truncated = false;
243 const limit = maxChars ?? 50000;
244 if (snapshot.length > limit) {
245 snapshot = `${snapshot.slice(0, limit)}\n\n[...TRUNCATED - page too large, use read action for full text]`;
246 truncated = true;
247 }
248
249 return { snapshot, truncated };
250}
251
252// Schema for the act action's request object
253const actRequestSchema = z.object({

Callers 1

browser.tsFile · 0.85

Calls 1

parseRefsFromSnapshotFunction · 0.85

Tested by

no test coverage detected