You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cap execute_playwright_code output and fix snapshot tip
The tool returned executed-code output verbatim and unbounded, so a single
whole-page read (innerText/ariaSnapshot on body) could dump tens to hundreds
of KB into the model context. The code param also recommended
page._snapshotForAI(), which is a large full-page dump and is not reliably
available in the execution runtime.
- Cap each returned field at 25k chars with a truncation marker that nudges
toward targeted selectors. Small structured results keep their shape.
- Replace the _snapshotForAI() tip with guidance to scope reads to a selector
or region.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
// Cap per-field output so a single call can't flood the model's context. Whole-page
6
+
// reads (innerText/ariaSnapshot on body) routinely run tens to hundreds of KB.
7
+
constMAX_FIELD_CHARS=25_000;
8
+
9
+
functioncap(value: unknown): unknown{
10
+
if(value===undefined||value===null)returnvalue;
11
+
consttext=typeofvalue==="string" ? value : JSON.stringify(value);
12
+
if(text.length<=MAX_FIELD_CHARS)returnvalue;
13
+
constdropped=text.length-MAX_FIELD_CHARS;
14
+
return`${text.slice(0,MAX_FIELD_CHARS)}\n\n[output truncated: showing ${MAX_FIELD_CHARS} of ${text.length} chars, ${dropped} dropped. Return a targeted selector instead of a whole-page read.]`;
// execute_playwright_code -- Run Playwright/TypeScript code against a browser
7
19
server.tool(
@@ -11,7 +23,7 @@ export function registerPlaywrightTool(server: McpServer) {
11
23
code: z
12
24
.string()
13
25
.describe(
14
-
'Playwright/TypeScript code with a `page` object in scope. Example: "await page.goto(\\"https://example.com\\"); return await page.title();" Tip: Use `await page._snapshotForAI()` for a comprehensive page state snapshot.',
26
+
'Playwright/TypeScript code with a `page` object in scope. Example: "await page.goto(\\"https://example.com\\"); return await page.title();" Return only what you need: prefer a targeted selector (e.g. `await page.locator(SELECTOR).innerText()`) over reading a whole page. Whole-page dumps like `innerText()`/`ariaSnapshot()` on `body` return large output that is truncated. To understand an unfamiliar page, scope the snapshot to a region (e.g. `await page.locator("main").ariaSnapshot()`).',
15
27
),
16
28
session_id: z
17
29
.string()
@@ -44,10 +56,10 @@ export function registerPlaywrightTool(server: McpServer) {
0 commit comments