1

I am aware, that if I know the URL, then I can fetch a file to a variable like this:

await page.evaluate(() => {
    return fetch(URL, {
        method: "GET",
        credentials: "include"
    }).then(r => r.text());
});

My problem is, that there is no direct URL, just a button in the page which does some JS magic and then the download begins.

What code would trigger the download in this case via button click (no form)

UPDATE

This code works for download via button click:

await page._client.send('Page.setDownloadBehavior', {
    behavior: 'allow',
    downloadPath: '/home/domain.tld/tmp',
});
await page.click('#exportButton');
await page.waitFor(20000);
  1. Is there a way to set the filename?

  2. How can I do this without downloading the file, but fetch into a variable?

Thanks,

Zoltan
  • 533
  • 4
  • 18
  • So you're just trying to emulate a click? https://stackoverflow.com/questions/46342930/puppeteer-button-press – Antoine Jan 21 '20 at 22:29
  • And maybe use `Page.setDownloadBehavior` before (https://github.com/puppeteer/puppeteer/issues/1478) – Antoine Jan 21 '20 at 22:30
  • Thanks for the suggestions, I can download the file with `Page.setDownloadBehavior` is there a way to set the filename? – Zoltan Jan 21 '20 at 23:04
  • Not sure. Internet seems to say there is no way. Now that your answer is provided, could you care answering you own question with the updated code? For future people :) – Antoine Jan 21 '20 at 23:09
  • I edited my question. If you write your suggestion as an answer I am more than happy to accept it :) – Zoltan Jan 21 '20 at 23:20
  • Okay I won't post it because your request is actually "INTO a variable", and I don't have the answer for that ;) – Antoine Jan 21 '20 at 23:24
  • Thanks, then I wait for a bit more :) – Zoltan Jan 21 '20 at 23:26

0 Answers0