title: Puppeteer how to retry url fetch with delay if it failed
body: <p>I try to write simple web-<strong>scraper</strong> using <a href="https://github.com/GoogleChrome/puppeteer" rel="nofollow noreferrer">puppeteer library</a>.</p>
  <p>When I get page by url via <code>page.goto</code>, I need to retry if it failed, i.e response code is &gt;= 400.</p>
  <p>My snippet:</p>
  <pre><code>'use strict';
  const puppeteer = require('puppeteer');
  
  (async () =&gt; {
      const browser = await puppeteer.launch({headless: false});
      const page = await browser.newPage();
      await page.setViewport({width: 1024, height: 768});
      await page.setDefaultNavigationTimeout(0);
  
      await page.goto('https://google.com');
  
      await browser.close();
      process.exit();
  })();
  </code></pre>
  <p>I need to implement fail strategy to retry url if <code>response.code</code> is &gt;= 400.<br />
  I need delay beetween attempts equal to <code>retryNumber</code> * 1000ms:</p>
  <ul>
  <li>1000 ms for first attempt;</li>
  <li>2000 ms for second attempt;</li>
  <li>3000 ms for third attempt and so on.</li>
  </ul>
  <p>Promise should be rejected if <code>retryNumber</code> exceeds <code>maxRetryNumber</code>.</p>
  <p>Who knows how to implement this via code? Are there any ready to use packets or snippets to achieve the goal?</p>