Skip to content

Commit 53c78a8

Browse files
authored
fix(downloads): fix acceptDownloads complaint (#1777) (#1923)
1 parent 00e8d88 commit 53c78a8

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/download.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ export class Download {
3939
this._url = url;
4040
this._finishedCallback = () => {};
4141
this._finishedPromise = new Promise(f => this._finishedCallback = f);
42-
this._page.emit(Events.Page.Download, this);
4342
page._browserContext._downloads.add(this);
4443
this._acceptDownloads = !!this._page._browserContext._options.acceptDownloads;
44+
this._page.emit(Events.Page.Download, this);
4545
}
4646

4747
url(): string {

test/download.spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ describe('Download', function() {
7070
expect(fs.readFileSync(path).toString()).toBe('Hello world');
7171
await page.close();
7272
});
73+
it(`should report download path within page.on('download', …) handler`, async({browser, server}) => {
74+
const page = await browser.newPage({ acceptDownloads: true });
75+
const onDownloadPathPath = new Promise((res) => {
76+
page.on('download', dl => {
77+
dl.path().then(res);
78+
});
79+
});
80+
await page.setContent(`<a href="${server.PREFIX}/download">download</a>`);
81+
await page.click('a');
82+
const path = await onDownloadPathPath;
83+
expect(fs.readFileSync(path).toString()).toBe('Hello world');
84+
await page.close();
85+
})
7386
it.skip(FFOX).fail(CHROMIUM || WEBKIT)('should report alt-click downloads', async({browser, server}) => {
7487
// Firefox does not download on alt-click by default.
7588
// Our WebKit embedder does not download on alt-click, although Safari does.

0 commit comments

Comments
 (0)