question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Puppeteer to download file with Page.setDownloadBehavior

See original GitHub issue

I am currently having issues downloading a file via URL. The download itself is working, but an incorrect extension of “.crdownload” is added to the end of the working extension.

Steps to reproduce

Environment:

  • Puppeteer version: ^0.12.0

Steps:

const reportLink = await page.$('table.icwTable > tbody#myReportResults > tr:nth-child(1) > td:nth-child(2) > a'); await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'}); await reportLink.click({ clickCount: 1, delay: 100 });

  1. Select the download URL
  2. Set download behavior with Chrome DevTools Protocol Viewer
  3. Click the link to download

Ideally the file would be downloaded and the extension would be “.xls”.

Currently the file is being downloaded, but with a file extension of “.xls.crdownload”. If I delete “.crdownload” manually the file downloads correctly - how do I stop the extra “.crdownload” extension from being added.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:34 (8 by maintainers)

github_iconTop GitHub Comments

18reactions
dunnkerscommented, Jan 6, 2018

I just set out to try if this bug occurred to me when trying to download .csv files. However, for me, it downloads just fine in headless and non-headless.

async function download(page) {
    await page._client.send('Page.setDownloadBehavior', {
        behavior: 'allow',
        downloadPath: './'
    });
    await page.goto(DOWNLOAD_URL);
    await page.click(DOWNLOAD_BUTTON_SELECTOR);
}

Using puppeteer ^0.13.0, working just fine. ✅

12reactions
t0johnsocommented, Mar 9, 2018

Hey guys, if it helps, what I noticed is that await page._client.send(‘Page.setDownloadBehavior’, {behavior: ‘allow’, downloadPath: ‘./’}); actually saved the file into the node_modules library where puppeteer/chromium was executing. So confirming what dallashuggins said: “…which downloads the file to a sibling folder on the same level as the file I am running (in the root directory).”

SO if you’re running puppeteer out of node_modules, then your path is relative to the puppeteer module directory:

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to download a file with Puppeteer? - ScrapingBee
In this article, we will discuss how to efficiently download files with Puppeteer. Automating file downloads can sometimes be complicated.
Read more >
Dealing with file downloads in puppeteer - browserless docs
Using our prior example we'll set this to generate a file for illustration purposes: await page._client.send('Page.setDownloadBehavior', { behavior: 'allow', ...
Read more >
NodeJS Puppeteer setDownloadBehavior issue
So, it ignores downloadPath option and puts the file to default C:/Users/Me/Downloads folder. Also it does not wait for 5 seconds, it only...
Read more >
How to download a file with Puppeteer? - ScrapFly
To download files with Puppteer we can either the browser's fetch feature - which will download the file into a javascript variable -...
Read more >
Handling file download with Puppeteer - Help · Apify
Basically, it extends Puppeteer's functionality. Then we can download the file by clicking on it. await page.click('.export-button');. Let's wait ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found