-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix: allow screenshot capture when filename is an empty string #37678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Adds test case to verify that browser_take_screenshot handles empty filename argument by generating a default timestamped filename. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Adds z.preprocess to convert empty string to null in filename validation, allowing empty filename to fall back to default timestamp-based naming. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is it called with an empty string instead of omitting the parameter?
const screenshotSchema = z.object({ | ||
type: z.enum(['png', 'jpeg']).default('png').describe('Image format for the screenshot. Default is png.'), | ||
filename: z.string().optional().describe('File name to save the screenshot to. Defaults to `page-{timestamp}.{png|jpeg}` if not specified.'), | ||
filename: z.preprocess(v => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just change ??
to ||
at line 54:
const fileName = await tab.context.outputFile(params.filename || dateAsFileName(fileType), { origin: 'llm', reason: 'Saving screenshot' });
@yury-s Thanks for reviewing! I'm using this MCP server with the GPT-5 model via Mastra. When the filename is omitted in the prompt, the model sometimes calls the function with filename: "", which appears to be a model hallucination. While switching models is a possible workaround, I suggest that this edge case be handled within the library for improved robustness. |
Problem
file path for is outside
returning an error response instead of an image.Root Cause
Fix
page-YYYY-MM-DDTHH-mm-ss-SSSZ.png
) in the output directory.Behavior Changes