From 36ea8ecb55933f832d2c354e778488d201317145 Mon Sep 17 00:00:00 2001 From: Zach Warunek <58487828+zwarunek@users.noreply.github.com> Date: Fri, 23 Jan 2026 15:50:11 -0800 Subject: [PATCH] fix: allow null selector in screenshot command schema (#236) The screenshot command was failing with 'Validation error: selector: Expected string, received null' when only a path was provided (e.g., 'agent-browser screenshot ~/Desktop/test.png'). The Rust CLI serializes None values as null in JSON, but the Zod schema only allowed undefined (via .optional()), not null. Changed selector field to use .nullish() which accepts both null and undefined. Fixes issue where screenshot command without selector fails validation. --- src/protocol.test.ts | 7 +++++++ src/protocol.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/protocol.test.ts b/src/protocol.test.ts index d886cc0..22b1eac 100644 --- a/src/protocol.test.ts +++ b/src/protocol.test.ts @@ -122,6 +122,13 @@ describe('parseCommand', () => { const result = parseCommand(cmd({ id: '1', action: 'screenshot', fullPage: true })); expect(result.success).toBe(true); }); + + it('should parse screenshot with null selector', () => { + const result = parseCommand( + cmd({ id: '1', action: 'screenshot', path: 'test.png', selector: null }) + ); + expect(result.success).toBe(true); + }); }); describe('cookies', () => { diff --git a/src/protocol.ts b/src/protocol.ts index 4e13e2c..8f899eb 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -693,7 +693,7 @@ const screenshotSchema = baseCommandSchema.extend({ action: z.literal('screenshot'), path: z.string().nullable().optional(), fullPage: z.boolean().optional(), - selector: z.string().min(1).optional(), + selector: z.string().min(1).nullish(), format: z.enum(['png', 'jpeg']).optional(), quality: z.number().min(0).max(100).optional(), });