Skip to content

fix(cli): preserve downloads with duplicate suggested filenames - #43930

Closed
microsoft-playwright-automation[bot] wants to merge 1 commit into
mainfrom
triage/playwright-cli-514/42092337080-1
Closed

microsoft-playwright-automation[bot] wants to merge 1 commit into
mainfrom
triage/playwright-cli-514/42092337080-1

Conversation

@microsoft-playwright-automation

Copy link
Copy Markdown
Contributor

Download events use the site's suggested filename, so Download.saveAs() silently replaces an earlier download when the site reuses a name.

Reserve the destination with an exclusive write before saving, retrying collisions as name-1.ext, name-2.ext, etc. This preserves existing files and prevents concurrent downloads from claiming the same name. The existing completion event reports the selected destination. Explicit user-supplied output filenames are unchanged.

A new CLI regression test checks the reported paths and both files' contents. The existing screenshot and PDF tests in cli-save-as.spec.ts do not trigger downloads; the existing MCP download test uses a different client fixture.

Verified the regression fails without the fix on Chrome and passes with it on Chrome, Chromium, Firefox and WebKit on Linux. The CLI save-as and shared file suites have 81 passes and 7 existing skips. Build and npm run flint pass.

Fixes microsoft/playwright-cli#514

Triaged on Linux by the Playwright bot - agent run

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Test results for "MCP"

5201 passed, 616 skipped


Merge workflow run.

private async _downloadStarted(download: playwright.Download) {
// Do not trust web names.
const outputFile = await this.context.outputFile({ suggestedFilename: sanitizeForFilePath(download.suggestedFilename()), prefix: 'download', ext: 'bin' }, { origin: 'code' });
const suggestedFile = await this.context.outputFile({ suggestedFilename: sanitizeForFilePath(download.suggestedFilename()), prefix: 'download', ext: 'bin' }, { origin: 'code' });

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, make outputFile suggest a name w/ next ordinal. I.e. next to prefix and ext options, get an ordinal: boolean and when it is true it'll pick a new name every time.

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.

Downloads with the same suggested filename silently overwrite each other in the output dir

1 participant