title: Fetch file to variable via button click in Puppeteer
body: <p>I am aware, that if I know the URL, then I can fetch a file to a variable like this:</p>
  
  <pre><code>await page.evaluate(() =&gt; {
      return fetch(URL, {
          method: "GET",
          credentials: "include"
      }).then(r =&gt; r.text());
  });
  </code></pre>
  
  <p>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.</p>
  
  <p>What code would trigger the download in this case via button click (no form)</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>This code works for download via button click:</p>
  
  <pre><code>await page._client.send('Page.setDownloadBehavior', {
      behavior: 'allow',
      downloadPath: '/home/domain.tld/tmp',
  });
  await page.click('#exportButton');
  await page.waitFor(20000);
  </code></pre>
  
  <ol>
  <li><p>Is there a way to set the filename?</p></li>
  <li><p>How can I do this without downloading the file, but fetch into a variable?</p></li>
  </ol>
  
  <p>Thanks,</p>