title: How to stop NodeJS script from crashing when timeout exceeded
body: <p>Below you can find the error that occurs.</p>
  
  <p>I'm trying to scrape contents of a website using NodeJS and puppeteer. Sometimes the code stops with the error Timeout Exceeded. Is there a way so that if the timeout of the page load is exceeded I can run a function that would either reload the page or have the script wait for a few seconds and then reload the page until it gets the data correctly, without crashing?
  If so, how would I go forward with implementing it?</p>
  
  <p>Thank you.</p>
  
  <pre><code>(node:8300) UnhandledPromiseRejectionWarning: TimeoutError: Navigation Timeout Exceeded: 30000ms exceeded
      at Promise.then (C:\Users\danie\node_modules\puppeteer\lib\LifecycleWatcher.js:143:21)
    -- ASYNC --
      at Frame.&lt;anonymous&gt; (C:\Users\danie\node_modules\puppeteer\lib\helper.js:108:27)
      at Page.goto (C:\Users\danie\node_modules\puppeteer\lib\Page.js:656:49)
      at Page.&lt;anonymous&gt; (C:\Users\danie\node_modules\puppeteer\lib\helper.js:109:23)
      at scrape (C:\Users\danie\Documents\Node Projects\p-download.js:23:14)
      at process._tickCallback (internal/process/next_tick.js:68:7)
  (node:8300) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
  (node:8300) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
  </code></pre>
  
  <p>My Code:</p>
  
  <pre><code>const puppeteer = require('puppeteer');
  
  let scrape = async () =&gt; {
      const browser = await puppeteer.launch({headless: false});
      const page = await browser.newPage();
  
      await page.setRequestInterception(true);    
      page.on('request', (req) =&gt; {
          if(req.resourceType() == 'stylesheet' || req.resourceType() == 'script' || req.resourceType() == 'font' || req.resourceType() == 'media' || req.resourceType() == 'image'){
              req.abort();
          }
          else {
              req.continue();
          }
      }); //Disables loading CSS, images and scripts
  
      for(i=0; i&lt;5000; i++){
          await page.goto('https://website.com/' + i);
          let result = await page.evaluate(() =&gt; {
              var result = '';
              for (i=1; i&lt;=10; i++){
                  result += document.getElementsByTagName('td')[i].innerText;
                  result += ',';
              }
              result += '\n';
              return result;
          });
      }
  }
  scrape();
  </code></pre>