简体   繁体   中英

How to set download behaviour in PuppeteerSharp?

I want to set download behaviour of browser for testing needs

I had tried solution from this topic: puppeteer - how to set download location

var browser = await StartNewChromeAsync(); //starting new chrome without extensions
var pages = await browser.PagesAsync();
var firstPage = pages[0];
var cdp = await firstPage.Target.CreateCDPSessionAsync();
await cdp.SendAsync("Page.setDownloadBehavior", new
                {
                    behavior = "allow",
                    downloadPath = Path.GetAbsolutePath("./testing_downloads")
                });
await cdp.DetachAsync();

I expecting, that files will be downloaded in ./testing_downloads , but it downloadings in default path. What am i doing wrong?

I found no way to do this in modern versions of Chrome because Page.setDownloadBehavior is removed from CDP v1.3 https://chromedevtools.github.io/devtools-protocol/1-3 .

UPD: this work https://gist.github.com/vabka/88a9b054ee756a53a44691366b16b474

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM