Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/playwright-core/src/server/chromium/crBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,9 @@ export class CRBrowserContext extends BrowserContext<CREventsMap> {
return;
}

// Ongoing downloads cause crashes in Edge, so cancel them first.
await Promise.all([...this._downloads].map(download => download.cancel().catch(() => {})));

await this._browser._session.send('Target.disposeBrowserContext', { browserContextId: this._browserContextId });
this._browser._contexts.delete(this._browserContextId);
for (const [targetId, serviceWorker] of this._browser._serviceWorkers) {
Expand Down
11 changes: 8 additions & 3 deletions packages/playwright-core/src/server/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,28 @@ import { Artifact } from './artifact';
export class Download {
readonly artifact: Artifact;
readonly url: string;
private _uuid: string;
private _page: Page;
private _suggestedFilename: string | undefined;

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);
this.artifact = new Artifact(page, downloadPath, unaccessibleErrorMessage, () => {
return this._page.browserContext.cancelDownload(uuid);
});
this.artifact = new Artifact(page, downloadPath, unaccessibleErrorMessage, () => this.cancel());
this._page = page;
this.url = url;
this._uuid = uuid;
this._suggestedFilename = suggestedFilename;
// Note: downloads are never removed from the context, so that we can delete them upon context closure.
page.browserContext._downloads.add(this);
if (suggestedFilename !== undefined)
this._fireDownloadEvent();
}

cancel() {
return this._page.browserContext.cancelDownload(this._uuid);
}

filenameSuggested(suggestedFilename: string) {
assert(this._suggestedFilename === undefined);
this._suggestedFilename = suggestedFilename;
Expand Down
Loading