fix: MCP screenshot returns invalid base64 with puppeteer >=22#1
Merged
svincent240 merged 1 commit intoJul 20, 2026
Conversation
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 <noreply@anthropic.com>
Contributor
|
Thank you for the contribution! The fix looks good and is much appreciated! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
coursecode_screenshotMCP tool fails on every call with MCP error-32602: Invalid tools/call result: ... "Invalid Base64 string", so MCP clients (Claude Code, Cursor, etc.) can never receive screenshots.Root cause:
page.screenshot()/elementHandle.screenshot()return aUint8Arraysince Puppeteer v22 (this project pinspuppeteer-core@^24.43.1).lib/headless-browser.jscallsscreenshotBuffer.toString('base64'), butUint8Array.prototype.toString()ignores the encoding argument and returns comma-separated byte values ("255,216,255,..."), which then fails the MCP SDK's image-content validation.Fix: wrap the result in
Buffer.from(...)before encoding, which is correct whether Puppeteer returns aBufferor aUint8Array.Repro
coursecode create test-course && cd test-course && coursecode previewcoursecode mcpand send over stdio:{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"coursecode_screenshot","arguments":{}}}MCP error -32602 ... "Invalid Base64 string". After: valid base64 JPEG (/9j/4AAQSkZJRg...).Related Issue
None filed — happy to open one first if you prefer issues for tracking.
Type of Change
Checklist
npm run lintand it passesnpm run previewTesting
npm test).coursecode_screenshotpreviously returned the -32602 validation error on every call; with this change it returns a validimage/jpegcontent block (base64 starts with the JFIF magic/9j/). Also exercisedcoursecode_state,coursecode_navigate, andcoursecode_lintin the same session to confirm no regressions in the MCP surface.Screenshots (if applicable)
N/A (the fix is screenshots 🙂)
🤖 Generated with Claude Code