: Monitor page.on('response') . If the URL or content type matches your target (e.g., .pdf ), capture the buffer using response.buffer() and save it using fs.writeFileSync.
: Map the GUID back to your desired filename and use fs.renameSync to finalize it. javascript puppeteer rename download file
: This method may fail for downloads triggered via complex JavaScript or POST requests that require specific session headers. Method 3: Post-Download Monitoring : Monitor page
const client = await page.target().createCDPSession(); await client.send('Browser.setDownloadBehavior', { behavior: 'allowAndName', downloadPath: './downloads', eventsEnabled: true, }); client.on('Browser.downloadProgress', (event) => { if (event.state === 'completed') { // guid is the temp filename, suggestName is what the site intended fs.renameSync(`./downloads/${event.guid}`, `./downloads/my-new-name.pdf`); } }); Use code with caution. Method 2: Response Interception (For Direct URLs) { behavior: 'allowAndName'