setDownloadBehavior issue
See original GitHub issueSteps to reproduce
Tell us about your environment:
- Puppeteer version: ^1.18.1
- Platform / OS version: Win 10
- Node.js version: v8.12.0
What steps will reproduce the problem?
Please include code that reproduces the issue.
- Run script
- It fails
Code:
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({
executablePath: 'C:/Program Files (x86)/Google/Chrome/Application/chrome.exe',
defaultViewport: {
width: 1920,
height: 1080
},
headless: false,
userDataDir: "./user_data"
});
const page = await browser.newPage();
await page.goto(
'https://example.com/page-with-the-file-link',
{ waitUntil: 'domcontentloaded' },
);
await page._client.send('Page.setDownloadBehavior', {
behavior: 'allow',
downloadPath: 'C:/Users/Me/Downloads/custom/folder/'
});
console.log('Start downloading');
await page.click('a.download-btn');
await page.waitFor(5000);
console.log('Complete');
await browser.close();
})();
What is the expected result?
Catch “download complete” event and to make it work correctly. Also I want to handle downloading status and monitor downloading proccess.
What happens instead?
Start downloading
Complete
(node:51016) UnhandledPromiseRejectionWarning: Error: WebSocket is not open: readyState 3 (CLOSED)
at WebSocket.send (C:\Users\Me\Downloads\puppeteer\node_modules\ws\lib\websocket.js:329:19)
at WebSocketTransport.send (C:\Users\Me\Downloads\puppeteer\node_modules\puppeteer\lib\WebSocketTransport.js:60:14)
at Connection._rawSend (C:\Users\Me\Downloads\puppeteer\node_modules\puppeteer\lib\Connection.js:86:21)
at Connection.send (C:\Users\Me\Downloads\puppeteer\node_modules\puppeteer\lib\Connection.js:72:21)
at gracefullyCloseChrome (C:\Users\Me\Downloads\puppeteer\node_modules\puppeteer\lib\Launcher.js:194:20)
at Browser.close (C:\Users\Me\Downloads\puppeteer\node_modules\puppeteer\lib\Browser.js:255:31)
at Browser.<anonymous> (C:\Users\Me\Downloads\puppeteer\node_modules\puppeteer\lib\helper.js:112:23)
at C:\Users\Me\Downloads\puppeteer\test-download-file.js:97:18
at <anonymous>
(node:51016) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
(node:51016) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Script does not work properly during the execution. It exits right after clicking download link on the page w/o waiting for 5 seconds and chrome puts downloaded file into default 'Downloads'
folder instead of defined 'downloadPath'
in the script.
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (1 by maintainers)
Top Results From Across the Web
NodeJS Puppeteer setDownloadBehavior issue
I am trying to set custom path for downloading but chrome puts files into typical Downloads folder anyways. const puppeteer = require('puppeteer ...
Read more >Page.setDownloadBehavior - Google Groups
Greetings, I'm using this call to setup the download behavior and it generally works fine. I'm downloading PDF files and they do get...
Read more >How to download a file with Puppeteer? - ScrapingBee
However, there is one minor issue. ... setDownloadBehavior property of Puppeteer to tie up the path to Chrome browser.
Read more >Browser.setDownloadBehavior doesn't work for WebView2
setDownloadBehavior ", { behavior: "deny" });. Is this a known issue or I am doing something wrong? WebView2 version: 0.9.579. Edge Beta version:...
Read more >[cdp] download events do not emit on the browser domain
(follow the guides from here: https://chromedevtools.github.io/devtools-protocol/#monitor). 1. Issue the `Browser.setDownloadBehavior` command with `Main.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Page.setDownloadBehavior no longer works for me (07/21/2020). To work around, use createCDPSession to get a CDP Session, then do a Browser.setDownloadBehavior:
I believe that it may have to do with Page.setDownloadBehavior being deprecated.
I’m also getting download error, is there any way to download files by clicking?
I’ve tried both,
Broswer.set...
andPage.set...
none of them gets the job done.**EDIT: ** to save someone’s hour, the problem is that on windows you have to use path like this “D:\my\folder” instead of “./savepath”