Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): RSB webview 截图支持 type=jpeg 并明确拒绝 fullPage (#1889)
happy9 Zhangca5fe3d5c886
diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-backend.test.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-backend.test.tsindex d80cadc096..605d570ec2 100644--- a/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-backend.test.ts+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/__tests__/rsb-webview-backend.test.ts@@ -77,7 +77,10 @@ function fakeWc(opts?: { url?: string; title?: string }): WebContents & {getTitle: () => opts?.title ?? 'Example',isDestroyed: () => false,loadURL: vi.fn(async () => undefined),- capturePage: vi.fn(async () => ({ toPNG: () => Buffer.from('PNGDATA') })),+ capturePage: vi.fn(async () => ({+ toPNG: () => Buffer.from('PNGDATA'),+ toJPEG: (quality: number) => Buffer.from(`JPEGDATA-${quality}`),+ })),printToPDF: vi.fn(async () => Buffer.from('PDFDATA')),on: vi.fn(),consoleListeners: [] as Array<(...args: unknown[]) => void>,@@ -432,6 +435,53 @@ describe('RsbWebviewBackend — direct WebContents actions', () => {});});+ it('screenshot honors type=jpeg with jpeg MIME and encoding', async () => {+ const wc = fakeWc();+ const registry = fakeRegistry(+ [{ sessionId: 's1', tabId: 't1', webContentsId: 101 }],+ new Map([['t1', wc]]),+ );+ const backend = new RsbWebviewBackend({+ registry,+ getActiveSessionId: () => 's1',+ bridge: { getHostWebContents: () => null, logger: logger() },+ logger: logger(),+ });+ const res = await backend.call({+ action: 'screenshot',+ targetId: 't1',+ type: 'jpeg',+ } as never);+ expect(wc.capturePageMock).toHaveBeenCalledTimes(1);+ expect(res.data).toMatchObject({+ mimeType: 'image/jpeg',+ data: Buffer.from('JPEGDATA-85').toString('base64'),+ bytes: Buffer.from('JPEGDATA-85').length,+ });+ });++ it('screenshot rejects fullPage explicitly', async () => {+ const wc = fakeWc();+ const registry = fakeRegistry(+ [{ sessionId: 's1', tabId: 't1', webContentsId: 101 }],+ new Map([['t1', wc]]),+ );+ const backend = new RsbWebviewBackend({+ registry,+ getActiveSessionId: () => 's1',+ bridge: { getHostWebContents: () => null, logger: logger() },+ logger: logger(),+ });+ const res = await backend.call({+ action: 'screenshot',+ targetId: 't1',+ fullPage: true,+ } as never);+ expect(res.ok).toBe(false);+ expect(res.message).toMatch(/fullPage is not supported/);+ expect(wc.capturePageMock).not.toHaveBeenCalled();+ });+it('pdf returns base64-encoded PDF', async () => {const wc = fakeWc();const registry = fakeRegistry(diff --git a/apps/desktop/src/main/mcp-integrations/browser-backend/rsb-webview-backend.ts b/apps/desktop/src/main/mcp-integrations/browser-backend/rsb-webview-backend.tsindex d1a7df957b..f1d91ff02b 100644--- a/apps/desktop/src/main/mcp-integrations/browser-backend/rsb-webview-backend.ts+++ b/apps/desktop/src/main/mcp-integrations/browser-backend/rsb-webview-backend.ts@@ -570,15 +570,28 @@ export class RsbWebviewBackend implements BrowserBackend {private async handleScreenshot(req: BackendRequest): Promise<BackendResult> {const tabId = await this.resolveDirectActionTarget(req);if (!tabId) return actionFailed(req.action, 'targetId required');+ if (req.fullPage) {+ // The RSB webview backend captures the guest WebContents viewport only;+ // full-page capture is not implemented here. Reject explicitly instead of+ // silently returning a viewport crop (matches the vendored runtime's+ // "explicitly reject unsupported params" contract).+ return actionFailed(+ req.action,+ 'fullPage is not supported by the RSB webview backend (captures the visible viewport only)',+ );+ }const resolved = await this.resolveTabForDirectAction(req, tabId);if (!resolved.ok) return resolved.result;return this.withTabPin(tabId, async () => {const image = await resolved.wc.capturePage();- const buffer = image.toPNG();+ // Honor `type` instead of always encoding PNG: JPEG via toJPEG(85),+ // matching the CDP path's default quality. MIME/bytes follow the buffer.+ const type = req.type === 'jpeg' ? 'jpeg' : 'png';+ const buffer = type === 'jpeg' ? image.toJPEG(85) : image.toPNG();return actionOk(req.action, {tabId,- mimeType: 'image/png',- // Base64-encoded PNG — same shape the vendored runtime returns for+ mimeType: type === 'jpeg' ? 'image/jpeg' : 'image/png',+ // Base64-encoded image — same shape the vendored runtime returns for// `screenshot` so MCP callers don't need to know which backend ran.data: buffer.toString('base64'),bytes: buffer.length,