node.jschromiumpuppeteer

puppeteer - how to set download location


I was able to successfully download a file with puppeteer, but it was just saving it to my /Downloads folder. I've been looking around and can't find anything in the api or forums to set this location.

My downloads are basically just go going to the link:

await page.goto(url);

Solution

  • Update for newer Puppeteer versions (~June 2022):

    As mentioned by @Daniel here, you have to create the CDP session yourself:

    const client = await page.target().createCDPSession()
    await client.send('Page.setDownloadBehavior', {
      behavior: 'allow',
      downloadPath: './myAwesomeDownloadFolder',
    })
    

    Original Answer

    This is how you can set the download path in latest puppeteer v0.13.

    await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './myAwesomeDownloadFolder'});
    

    The behaviour is experimental, it might be removed, modified, or changed later.

    Pst, you can try more tricks listed here, on your own risk :).