From dd0c39e7a9b5c1db4f88b2fb472600434162eae7 Mon Sep 17 00:00:00 2001 From: Nelson Spence Date: Thu, 16 Jul 2026 12:15:23 -0400 Subject: [PATCH] fix: MCP screenshot returns invalid base64 with puppeteer >=22 page.screenshot() returns Uint8Array since Puppeteer v22, and Uint8Array.prototype.toString() ignores the 'base64' argument, producing comma-separated byte values that fail MCP image content validation ('Invalid Base64 string'). Wrap the result in Buffer.from() so the base64 encoding applies regardless of the returned type. Co-Authored-By: Claude Fable 5 --- lib/headless-browser.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/headless-browser.js b/lib/headless-browser.js index 46f6a02..2664583 100644 --- a/lib/headless-browser.js +++ b/lib/headless-browser.js @@ -464,7 +464,9 @@ class HeadlessBrowser { } return { - data: screenshotBuffer.toString('base64'), + // Puppeteer >=22 returns Uint8Array, whose toString() ignores the + // 'base64' argument — wrap in Buffer so encoding applies. + data: Buffer.from(screenshotBuffer).toString('base64'), mimeType: 'image/jpeg' }; }