0

I'd like to automate the download of some pdf bill in a specific directory but I didn't manage to do it.

Note i'm using puppeteer 3.0.2 on windows:

I tried to setup it multiple ways : Initializing the browser:

const browser = await puppeteer.launch({
    headless: navMode,
    userDataDir : "E:/projets/factures/",
    args: [
        '--start-maximized',
        // you can also use '--start-fullscreen'
    ]

});

I also tried:

await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: 'E:/projets/factures/'});

juste before the download

i tried also :

page.on('request', req => {
    if (req.url() === urlFile) {
        const file = fs.createWriteStream('./file.pdf');
        https.get(req.url(), response => response.pipe(file));
    }
});

all of this is before :

await page.goto(urlFile); //urlFile contains the pdf url

The PDF is only downloading in the Default Download Directory

Ferran Buireu
  • 28,630
  • 6
  • 39
  • 67
Patrick Valibus
  • 227
  • 4
  • 17

2 Answers2

0

here I can get solution for you.

puppeteer - how to set download location

In your code, 'E:/projets/factures/' this seems to be error.

Please try use this like './../../projects/fatures/'

Thanks

i-Guru
  • 164
  • 4
  • 25
0

you can use achieve this easily using puppeteer-extra & a puppeteer-extra-plugin-user-preferences plugin. please refer to this answer for details

Muhammad Uzair
  • 394
  • 5
  • 9