fix: filter base64 image from screenshot result#105
Conversation
- Filter out base64 image data from the `screenshot` result to reduce context usage. - Extract file paths from text content and attach guidance.
a7e4b0d to
287d15f
Compare
gaojude
left a comment
There was a problem hiding this comment.
Thanks for tackling this issue! However, I discovered that playwright-mcp actually has a built-in flag for this use case.
Better Solution: --image-responses Flag
Instead of filtering the response after the fact, we can prevent the base64 image data from being sent in the first place by using the --image-responses flag when starting the playwright-mcp server:
// In src/_internal/browser-eval-manager.ts:66
const args: string[] = [
"@playwright/mcp@latest",
"--image-responses", "omit" // Add this
]Why This Approach is Better
- Cleaner - Prevents image data at the source rather than filtering after transmission
- More efficient - Never transmits base64 data over the stdio transport in the first place
- Simpler - No need for filtering logic, regex parsing, or unit tests
- More reliable - Doesn't depend on parsing text formats that might change
The screenshot will still be saved to disk (as your tests confirm), and the response will include the file path in the text - we just won't get the massive base64 blob consuming context.
Reference
The --image-responses flag accepts:
"allow"(default) - sends base64 image data"omit"- excludes base64 image data from responses"auto"- sends images only if client can display them
See the playwright-mcp documentation for more details.
Would you be interested in updating this PR to use the flag approach instead?
9ec4149 to
f0bf89e
Compare
|
@gaojude Thanks for the review. Good find—that's much cleaner! I just pushed a change to use that flag. |
|
Would be great if this fix is merged. Getting the same issues as reported by @Burry. |
|
@gaojude Any chance you could give this another look? |
Filter out base64 image data from the
screenshotresult to reduce context usage.See #104
I have emailed cla@vercel.com with a signed CLA.