Skip to content

fix(mcp): route custom screenshot filenames through outputFile#39229

Open
LeeorNahum wants to merge 1 commit intomicrosoft:mainfrom
LeeorNahum:fix/mcp-screenshot-output-dir
Open

fix(mcp): route custom screenshot filenames through outputFile#39229
LeeorNahum wants to merge 1 commit intomicrosoft:mainfrom
LeeorNahum:fix/mcp-screenshot-output-dir

Conversation

@LeeorNahum
Copy link

Custom filenames passed to browser_take_screenshot (and browser_pdf_save) are resolved via workspaceFile() instead of outputFile() in resolveClientFile(). This means they save to the workspace root, bypassing --output-dir.

Auto-generated filenames (when no filename is provided) already correctly route through outputFile(). This one-line fix makes custom filenames use the same path.

Reproduction

  1. Start MCP with --output-dir /tmp/playwright-mcp
  2. browser_take_screenshot() without filename → saves to /tmp/playwright-mcp/page-{timestamp}.png
  3. browser_take_screenshot(filename: "test.png") → saves to {workspace}/test.png ❌ (should go to /tmp/playwright-mcp/test.png)

Fix

In packages/playwright/src/mcp/browser/response.ts, resolveClientFile() line 72:

  if (template.suggestedFilename)
-   fileName = await this._context.workspaceFile(template.suggestedFilename, this._clientWorkspace);
+   fileName = await this._context.outputFile(template, { origin: 'llm' });

context.outputFile() already handles suggestedFilename — it uses it as the basename and resolves against outputDir. The checkFile() security validation still applies.

References microsoft/playwright-mcp#1390, microsoft/playwright-mcp#1253, microsoft/playwright-mcp#1002

Custom filenames passed to browser_take_screenshot were resolved
via workspaceFile() (workspace root) instead of outputFile()
(--output-dir). This meant custom filenames bypassed --output-dir
and saved to the workspace root, cluttering projects.

Auto-generated filenames (when no filename is provided) already
correctly routed through outputFile(). This fix makes custom
filenames use the same path.

References microsoft/playwright-mcp#1253, microsoft/playwright-mcp#1002

Signed-off-by: LeeorNahum <124272031+LeeorNahum@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant