From b7b5a33e32c4d1a4d900c47c4d23f9f42161f599 Mon Sep 17 00:00:00 2001 From: DavertMik Date: Sun, 26 Apr 2026 17:27:06 +0300 Subject: [PATCH 1/4] feat(mcp): snapshot tool, run_code return/console capture, storage state, HTML cleanup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a `snapshot` MCP tool that captures the current browser state without performing any action. `run_code` now also returns the value the code produced and captures `console.*` output (level + message + relative time) using the existing `safeStringify` from lib/utils.js with a `truncateString` helper, so models can use debug statements and inspect return values. Captures cookies + localStorage via Playwright's `grabStorageState()` (with a `grabCookie + executeScript` fallback for Puppeteer/WebDriver), normalized to a single shape and saved as `_storage.json` alongside the other artifacts. Centralizes the artifact-grab + trace-record glue: - New `lib/utils/captureSnapshot.js` is the single funnel for HTML / ARIA / screenshot / console / storage capture. - New `lib/utils/trace.js` holds shared helpers (`pickActingHelper`, `traceDirFor`, `snapshotDirFor`, `artifactLinks`, `artifactsToFileUrls`) used by `aiTrace`, `pageInfo`, and the MCP server. - aiTrace and pageInfo now go through the same funnel — pageInfo's three serial recorder steps collapse to one delegated capture. HTML processing pipeline (`formatHtml` in `lib/html.js`): minify -> cleanHtml -> beautify. `cleanHtml` (new) drops `' + + 'hi' + + '' + + '' + + '' + + '' + + it('drops ' + + '
' + + 'hi
' + const out = await formatHtml(fixture) + // beautify: multiline output + expect(out.split('\n').length).to.be.greaterThan(3) + // comment removed by minifier + expect(out).not.to.include('