Skip to content

Fix execute_playwright_code snapshot tip#125

Merged
dprevoznik merged 7 commits into
mainfrom
hypeship/playwright-output-cap
Jul 21, 2026
Merged

Fix execute_playwright_code snapshot tip#125
dprevoznik merged 7 commits into
mainfrom
hypeship/playwright-output-cap

Conversation

@dprevoznik

@dprevoznik dprevoznik commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Summary

The execute_playwright_code tool's code param tip recommended await page._snapshotForAI() for "a comprehensive page state snapshot." Two problems with that:

  • It's a whole-page dump whose size scales with page complexity — a major context-window driver, which is the opposite of what we want by default.
  • It's a Playwright internal that isn't exposed in the stealth-patched execution runtime, so it throws TypeError: page._snapshotForAI is not a function. Agents then fall back to an even larger body.innerText().

Change

Replaced the tip with a one-liner that lists the in-scope objects, makes the return contract explicit, and steers agents off full-page dumps toward the supported public API:

Playwright/TypeScript code with page, context, and browser objects in scope; the value you return is sent back. 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('h1').innerText()) or a region-scoped snapshot (e.g. await page.locator('main').ariaSnapshot()) rather than dumping the whole page.

page/context/browser scope matches the docs. Description-only; no change to execution or output behavior. Typechecks clean.

Also

Removed tsconfig.tsbuildinfo from tracking and added it to .gitignore — it's a generated, volatile TS build cache that shouldn't be versioned.

Follow-ups (not in this PR)

The public docs (kernel/docs → reference/mcp-server/tools/execute-playwright-code.mdx) and the SDK example repos still reference _snapshotForAI() and need the same fix.


Note

Low Risk
Documentation and gitignore-only changes with no runtime or auth impact.

Overview
Updates the execute_playwright_code MCP tool’s code parameter description so agents know page, context, and browser are in scope and that only the return value is echoed back. The old tip pointed at page._snapshotForAI(), which blows up context and isn’t available in the stealth runtime; the new copy steers toward small, targeted reads (locator(...).innerText(), region-scoped ariaSnapshot()) instead of whole-page dumps. No execution or API behavior changes—description only.

Also stops tracking tsconfig.tsbuildinfo and adds it to .gitignore, with a minor .gitignore newline fix for mcp-key.pem.

Reviewed by Cursor Bugbot for commit b58ed95. Bugbot is set up for automated code reviews on this repo. Configure here.

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>
@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mcp Ready Ready Preview, Comment Jul 21, 2026 9:35pm

Replace the single all-or-nothing snapshot tip with a broad-to-narrow
workflow: orient cheaply (title + heading outline, or a landmark map of
region/label/control-count), then scope ariaSnapshot to one region, then
extract with a targeted locator. Explicitly warns off whole-page innerText/
ariaSnapshot on body.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dprevoznik dprevoznik changed the title Cap execute_playwright_code output and fix snapshot tip Rework execute_playwright_code tip into a recon funnel (+ output cap) Jul 21, 2026
Trim the recon-funnel walkthrough back to a single Tip: line matching the
original description's shape — prefer targeted selectors and scope reads to a
region instead of dumping the whole page.
@dprevoznik dprevoznik changed the title Rework execute_playwright_code tip into a recon funnel (+ output cap) Fix execute_playwright_code snapshot tip + cap output Jul 21, 2026
Revert the per-field output truncation. The only change vs main is the code
param tip: prefer a targeted selector and scope reads to a region instead of
the removed _snapshotForAI() whole-page snapshot.
@dprevoznik dprevoznik changed the title Fix execute_playwright_code snapshot tip + cap output Fix execute_playwright_code snapshot tip Jul 21, 2026
@masnwilliams
masnwilliams marked this pull request as ready for review July 21, 2026 17:41
It's TypeScript's incremental build cache — generated, volatile (re-churns on
every tsc run), and shouldn't be versioned. Remove it from tracking and add it
to .gitignore so it stays out of diffs.
State that the returned value is what's sent back, and use concrete selector
examples (h1/main) instead of a SELECTOR placeholder.
Match the docs: execute_playwright_code exposes page, context, and browser.

@masnwilliams masnwilliams left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed — clean. verified the description change against the executor and it's accurate.

  • src/lib/mcp/tools/playwright.ts:14 — new scope claim (page, context, browser all in scope + return value sent back) checks out against kernel-images server/runtime/playwright-daemon.ts (new AsyncFunction('page','context','browser', code)). steering away from _snapshotForAI() toward scoped extraction is the right call for token cost. ariaSnapshot() example is valid public API.
  • .gitignore / tsconfig.tsbuildinfo — housekeeping looks right: ignore the incremental build cache + remove the tracked copy in the same PR.

lgtm 👍

@dprevoznik
dprevoznik merged commit 28f5a61 into main Jul 21, 2026
10 checks passed
@dprevoznik
dprevoznik deleted the hypeship/playwright-output-cap branch July 21, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants