-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Limitless2023/playwright
#1Description
Description
When --output-dir is configured, browser_take_screenshot only respects it for auto-generated filenames. Custom filenames bypass --output-dir entirely and save to the workspace root.
| Scenario | Where file saves | Expected |
|---|---|---|
No filename (auto-generated page-{timestamp}.png) |
--output-dir ✅ |
Correct |
Custom filename (e.g. test.png) |
Workspace root ❌ | Should go to --output-dir |
Steps to Reproduce
- Start the MCP server with
--output-dir /tmp/playwright-mcp - Navigate to any page
- Call
browser_take_screenshotwithout a filename → file saves to/tmp/playwright-mcp/page-{timestamp}.png✅ - Call
browser_take_screenshotwithfilename: "test.png"→ file saves to{workspace}/test.png❌
Root Cause
In response.ts, the resolveClientFile method uses workspaceFile() when a suggestedFilename is provided, but outputFile() when no filename is given:
async resolveClientFile(template: FilenameTemplate, title: string): Promise<ResolvedFile> {
let fileName: string;
if (template.suggestedFilename)
fileName = await this._context.workspaceFile(template.suggestedFilename, this._clientWorkspace); // ← workspace root
else
fileName = await this._context.outputFile(template, { origin: 'llm' }); // ← --output-dirBoth paths should use outputFile(). The context.outputFile() method already handles suggestedFilename correctly — it uses it as the basename and resolves against outputDir. The checkFile() security check still validates the path is within allowed directories.
Proposed Fix
One-line change in packages/playwright/src/mcp/browser/response.ts:
if (template.suggestedFilename)
- fileName = await this._context.workspaceFile(template.suggestedFilename, this._clientWorkspace);
+ fileName = await this._context.outputFile(template, { origin: 'llm' });I have a PR ready with this fix targeting microsoft/playwright.
Related Issues
- browser_take_screenshot ignores --output-dir when filename contains path separators #1253 — reported the same symptom (closed, root cause not addressed)
- LLM confusion about file saving paths in browser_pdf_save and browser_take_screenshot tools #1002 — suggested clarifying filename as "name only, no directories"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels