Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Puppeteer is not downloading into folder specified with "Page.setDownloadBehavior" in Windows?

I use the following piece of code to achieve the download of a file by making Puppeteer click the button that emits the event

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

It works pretty fine in a Mac OS machine, but it does nothing in a Windows one

The try/catch that wraps this block it doesn't catch anything, and when I use the headless: false setting, it's proven to "download the file", but there is no file in all the hard drive

like image 654
Benjamín Vázquez Avatar asked Dec 02 '25 14:12

Benjamín Vázquez


2 Answers

In case Windows API needs an absolute path, you can compose it with __dirname and relative path.

like image 183
vsemozhebuty Avatar answered Dec 05 '25 05:12

vsemozhebuty


For newer versions (tested in version 12.0.1 on Windows)

page._client is deprecated, instead, use page.client()

downloadPath needs to be absolute for Windows (see the accepted answer)

await page.client().send("Page.setDownloadBehavior", {
  behavior: "allow",
  downloadPath: __dirname + "./", // referenced from the accepted answer
});
like image 36
Rajkumar Gaur Avatar answered Dec 05 '25 04:12

Rajkumar Gaur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!