title: Chrome download error when downloading file with Puppeteer
body: <p>I have an application that shows a page, the user clicks on a button, and downloads a CSV file. I want to run this with Puppeteer.</p>
  <p>Problem is that the CSV is downloaded empty and with an error. This happens both with <code>headless</code> true and false. The page finished loading, and I increased the timeout, but it still fails. What could be the issue?</p>
  <p><a href="https://i.stack.imgur.com/NlvuB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NlvuB.png" alt="enter image description here" /></a></p>
  <pre><code>const puppeteer = require('puppeteer');
  
  (async () =&gt; {
      
      const browser = await puppeteer.launch({
         headless: false
      });
  
      const page = await browser.newPage();
      await page.goto('http://localhost:4400/login', { waitUntil: 'networkidle2' });    
      
      await page._client.send('Page.setDownloadBehavior', {
          behavior: 'allow',
          downloadPath: './',
      });
  
      await page.waitForSelector('#run-and-export');
      await page.click('#run-and-export');
    
      // file-downloaded is turned on when the file finished downloading (not to close the window)
      await page.waitForSelector('#file-downloaded', { timeout: 120000 }); 
  
      await browser.close();
      
  })();
  </code></pre>
  <p>The code in the application that generates the file to download is an Angular service:</p>
  <pre><code>@Injectable({ 
      providedIn: 'root' 
  })
  export class DownloadService {
  
      downloadFile(content:any, fileName: string, mimeType: string){
      
          var blob = new Blob([(content)], {type: mimeType});
          var a = document.createElement('a');
          a.href = window.URL.createObjectURL(blob);
          a.download = fileName;
          a.click();
  
      }
  }
  </code></pre>