Repository navigation
fix(cli): preserve downloads with duplicate suggested filenames - #43930
Closed
microsoft-playwright-automation[bot] wants to merge 1 commit into
Closed
microsoft-playwright-automation[bot] wants to merge 1 commit into
microsoft-playwright-automation[bot] wants to merge 1 commit into
Conversation
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' }); |
There was a problem hiding this comment.
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.
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.
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.tsdo 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 flintpass.Fixes microsoft/playwright-cli#514
Triaged on Linux by the Playwright bot - agent run