Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

chore(bidi): fix support for downloads (#40659)

Holger Benl5790370e1b56
diff --git a/packages/playwright-core/src/server/bidi/bidiPage.ts b/packages/playwright-core/src/server/bidi/bidiPage.ts
index eb6fe320bd..6637b0d46e 100644
--- a/packages/playwright-core/src/server/bidi/bidiPage.ts
+++ b/packages/playwright-core/src/server/bidi/bidiPage.ts
@@ -255,7 +255,7 @@ export class BidiPage implements PageDelegate {
if (!originPage)
return;
- this._browserContext._browser.downloadCreated(originPage, event.navigation, event.url, event.suggestedFilename);
+ this._browserContext._browser.downloadCreated(originPage, event.navigation, event.url, event.suggestedFilename, event.suggestedFilename);
}
private _onDownloadEnded(event: bidi.BrowsingContext.DownloadEndParams) {
diff --git a/packages/playwright-core/src/server/download.ts b/packages/playwright-core/src/server/download.ts
index 6d88db191c..0c8725c35b 100644
--- a/packages/playwright-core/src/server/download.ts
+++ b/packages/playwright-core/src/server/download.ts
@@ -14,9 +14,8 @@
* limitations under the License.
*/
-import path from 'path';
-
import { assert } from '@isomorphic/assert';
+import { resolveWithinRoot } from '@utils/fileUtils';
import { Page } from './page';
import { Artifact } from './artifact';
@@ -29,7 +28,9 @@ export class Download {
constructor(page: Page, downloadsPath: string, uuid: string, url: string, suggestedFilename?: string, downloadFilename?: string) {
const unaccessibleErrorMessage = page.browserContext._options.acceptDownloads === 'deny' ? 'Pass { acceptDownloads: true } when you are creating your browser context.' : undefined;
- const downloadPath = path.join(downloadsPath, downloadFilename ?? uuid);
+ const downloadPath = resolveWithinRoot(downloadsPath, downloadFilename ?? uuid);
+ if (!downloadPath)
+ throw new Error(`Download filename '${downloadFilename}' escapes download directory`);
this.artifact = new Artifact(page, downloadPath, unaccessibleErrorMessage, () => this.cancel());
this._page = page;
this.url = url;