Skip to content

Commit 8b8a4e5

Browse files
authored
fix: filter base64 image from screenshot result (#105)
1 parent 316fcec commit 8b8a4e5

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

src/_internal/browser-eval-manager.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export async function startBrowserEvalMCP(options?: {
6363
console.error("[Browser Eval Manager] Starting playwright-mcp server with verbose logging...")
6464

6565
// Build args for playwright-mcp
66-
const args: string[] = ["@playwright/mcp@latest"]
66+
const args: string[] = ["@playwright/mcp@latest", "--image-responses", "omit"]
6767

6868
if (options?.browser) {
6969
args.push("--browser", options.browser)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest"
2+
3+
// Mock the mcp-client module before importing browser-eval-manager
4+
vi.mock("../../src/_internal/mcp-client.js", () => ({
5+
connectToMCPServer: vi.fn(),
6+
callServerTool: vi.fn(),
7+
listServerTools: vi.fn(),
8+
}))
9+
10+
// Mock the exec function to skip installation check
11+
vi.mock("child_process", () => ({
12+
exec: vi.fn((cmd, callback) => {
13+
callback(null, { stdout: "@playwright/mcp@1.0.0" })
14+
}),
15+
}))
16+
17+
import { connectToMCPServer, callServerTool } from "../../src/_internal/mcp-client.js"
18+
import {
19+
startBrowserEvalMCP,
20+
stopBrowserEvalMCP,
21+
} from "../../src/_internal/browser-eval-manager.js"
22+
import { handler } from "../../src/tools/browser-eval.js"
23+
24+
describe("browser-eval playwright-mcp screenshot tool", () => {
25+
beforeEach(() => {
26+
vi.clearAllMocks()
27+
vi.mocked(connectToMCPServer).mockResolvedValue({
28+
client: { close: vi.fn() },
29+
transport: { close: vi.fn() },
30+
} as never)
31+
})
32+
33+
afterEach(async () => {
34+
await stopBrowserEvalMCP()
35+
})
36+
37+
it("should pass --image-responses omit flag to playwright-mcp", async () => {
38+
await startBrowserEvalMCP()
39+
40+
expect(connectToMCPServer).toHaveBeenCalledWith(
41+
"npx",
42+
expect.arrayContaining(["--image-responses", "omit"]),
43+
expect.any(Object)
44+
)
45+
})
46+
47+
it("should return screenshot file path without base64 image data", async () => {
48+
await startBrowserEvalMCP()
49+
50+
const screenshotPath = "/var/folders/tmp/screenshot-1234.png"
51+
vi.mocked(callServerTool).mockResolvedValue({
52+
content: [{ type: "text", text: `Screenshot saved to ${screenshotPath}` }],
53+
})
54+
55+
const result = await handler({ action: "screenshot" })
56+
const parsed = JSON.parse(result)
57+
58+
expect(parsed.success).toBe(true)
59+
expect(parsed.action).toBe("screenshot")
60+
61+
// Verify response contains file path
62+
const textContent = parsed.result.content.find(
63+
(block: { type: string }) => block.type === "text"
64+
)
65+
expect(textContent.text).toContain(screenshotPath)
66+
67+
// Verify no base64 image data in response
68+
const imageContent = parsed.result.content.find(
69+
(block: { type: string }) => block.type === "image"
70+
)
71+
expect(imageContent).toBeUndefined()
72+
})
73+
})

0 commit comments

Comments
 (0)