Skip to content

Commit 36ea8ec

Browse files
authored
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.
1 parent d10fd2d commit 36ea8ec

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/protocol.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ describe('parseCommand', () => {
122122
const result = parseCommand(cmd({ id: '1', action: 'screenshot', fullPage: true }));
123123
expect(result.success).toBe(true);
124124
});
125+
126+
it('should parse screenshot with null selector', () => {
127+
const result = parseCommand(
128+
cmd({ id: '1', action: 'screenshot', path: 'test.png', selector: null })
129+
);
130+
expect(result.success).toBe(true);
131+
});
125132
});
126133

127134
describe('cookies', () => {

src/protocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ const screenshotSchema = baseCommandSchema.extend({
693693
action: z.literal('screenshot'),
694694
path: z.string().nullable().optional(),
695695
fullPage: z.boolean().optional(),
696-
selector: z.string().min(1).optional(),
696+
selector: z.string().min(1).nullish(),
697697
format: z.enum(['png', 'jpeg']).optional(),
698698
quality: z.number().min(0).max(100).optional(),
699699
});

0 commit comments

Comments
 (0)