there is a download button, after pressing the button a new tab opens and the download starts. After the download is completed, new tab closes. In the chrome browser I see that the file has been downloaded, but const path = await download.path (); shows nothing. VS Code does not show any error.
const [download] = await Promise.all([
page.waitForEvent("download"), // wait for download to start
page.click("span.icon-am-download"),
]);
const path = await download.path();
I think the problem is: A new tab opens, page.waitForEvent ("download") cannot catch the Download event because the event download is started in new tab.
How can a file be downloaded if the download starts in a new tab?
Depending on how this download is implemented (via script, redirect or something else), you could try waiting for the popup first via waitForEvent("popup") and then waiting for the download on that new popup...
Depending on how this download is implemented (via script, redirect or something else), you could try waiting for the popup first via waitForEvent("popup") and then waiting for the download on that new popup...
Thanks a lot for your answer!
I found one example page with popup and download exe file.
can you please show me how to download file inside popup.
Hi Team,
there is a download button, after pressing the button a new tab opens and the download starts. After the download is completed, new tab closes. In the chrome browser I see that the file has been downloaded, but
const path = await download.path ();
shows nothing. VS Code does not show any error.I think the problem is: A new tab opens, page.waitForEvent ("download") cannot catch the Download event because the event download is started in new tab.
How can a file be downloaded if the download starts in a new tab?
This is HTML Code: `
Thank you very much
Depending on how this download is implemented (via script, redirect or something else), you could try waiting for the popup first via
waitForEvent("popup")
and then waiting for the download on that new popup...Thanks a lot for your answer!
I found one example page with popup and download exe file. can you please show me how to download file inside popup.
Hier is code:
i tried this, does not work, because page close after download finished - Error: page.waitForEvent: Page closed
@osmenia your code works in Chromium headless.
There is a TODO in code for Chromium headful: https://github.com/microsoft/playwright/blob/8df1fe47bcc34f0d398f17a37f7a98eabd35b2f5/test/download.spec.ts#L280-L284
@ingvar-nikiforov thanks a lot for your info. wow, i did not try in headless mode,