fix(mcp): route custom screenshot filenames through outputFile#39229
Open
LeeorNahum wants to merge 1 commit intomicrosoft:mainfrom
Open
fix(mcp): route custom screenshot filenames through outputFile#39229LeeorNahum wants to merge 1 commit intomicrosoft:mainfrom
LeeorNahum wants to merge 1 commit intomicrosoft:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Custom filenames passed to
browser_take_screenshot(andbrowser_pdf_save) are resolved viaworkspaceFile()instead ofoutputFile()inresolveClientFile(). 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
--output-dir /tmp/playwright-mcpbrowser_take_screenshot()without filename → saves to/tmp/playwright-mcp/page-{timestamp}.png✅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:context.outputFile()already handlessuggestedFilename— it uses it as the basename and resolves againstoutputDir. ThecheckFile()security validation still applies.References microsoft/playwright-mcp#1390, microsoft/playwright-mcp#1253, microsoft/playwright-mcp#1002