Warm tip: This article is reproduced from serverfault.com, please click

PDF doesn't download with puppeteer

发布于 2020-11-26 14:30:59

So I'm trying to download a pdf file that opens in a pop up, like this.

enter image description here

Using this code right here to get the pop up and download it to './'.

const popUp = await popUpPromise
        await popUp.waitFor(5000)
        // await popUp.waitForSelector('.content')
        const pdf = await popUp.$$eval('html', e => e)
        await console.log(pdf)
        await popUp._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: './'})

But not only it isn't downloading as I expected, but the html from the pop up is returning empty.

Questioner
LGimenez
Viewed
0
Brewha 2020-12-03 05:34:51

In order to download a pdf from a popup you will need to simulate pressing ctrl-s once the popup loads. It should download to your specified folder in your downloadbehavior settings. Try using await page.type() or await page.press()