How can I configure a custom download folder using Puppeteer?

I managed to retrieve a file with Puppeteer, but it automatically goes into the default Downloads folder. Despite combing through the API and community threads, I haven’t located any option that allows me to define a different save path. My current implementation simply navigates to the target URL and downloads the file.

await browserTab.redirectTo(targetLink);

I encountered this issue in one of my projects and eventually discovered that Puppeteer doesn’t offer a direct setting for a custom download folder. The solution I found most reliable was to launch Chromium with a predefined user profile where I’d customized the download behavior. This involves setting the appropriate download directory in the profile preferences before starting the browser using Puppeteer. Alternatively, using the Chrome DevTools Protocol to control file downloads worked in my case, although it required additional setup. Both approaches can be a bit cumbersome but offer a practical workaround for controlling file paths.

Based on my experience, while Puppeteer does not natively support setting a custom download directory, a practical workaround is to launch the browser with a modified user data profile. I configured a profile with customized download settings by passing specific command line arguments to Chromium, thus redirecting file downloads. Another approach I experimented with involved intercepting network responses to detect a download and then moving the file to a desired location programmatically. Although both methods add some complexity, they provide a viable solution when the default download folder is not suitable.

hey, i’ve tinkered with similar issues. i ended up using puppeteer’s cdp to catch download events and then shifted the file post-download. its a bit messy, but it worked for my use case. hope this helps a bit.

I encountered a similar situation while automating downloads for a project. Instead of relying solely on Puppeteer to handle the file download, I intercepted the request for the download link and used a Node.js module to manually download the file. This approach allowed me to specify the destination folder directly in my code. It required a bit more coding to manage the HTTP request and file stream, but it gave me complete control over where and how the file was saved, which was exactly what I needed.