title: Puppeteer Hangs In Headless Mode
body: <p>My Puppeteer script is running in headless mode and it's timing out.</p>
  
  <p>I'm not sure exactly what's going wrong. The script runs fine locally, but when I'm running in headless mode it always times out. </p>
  
  <p>I've read online that could be due to the script failing to load an external javascript source? Has anyone else run into this problem, and able to help out?</p>
  
  <p>Here's my setup function for my Puppeteer instance:</p>
  
  <pre><code> setUpPuppeteer: async () =&gt; {
      const headless = process.env.NODE_ENV === "production";
      const browser = await pupeteer.launch({
        headless,
        devtools: true,
        args: ['--no-sandbox' ]
      });
      const context = await browser.createIncognitoBrowserContext();
      const page = await context.newPage(); // Create new instance of puppet
  
      page.on('error', err =&gt; {
        logger.error('Puppeteer error.', err);
      });
  
      page.setDefaultNavigationTimeout(10000);
  
      if (process.env.NODE_ENV === 'production') {
        await page.setRequestInterception(true); // Optimize (no stylesheets, images)...
        page.on('request', request =&gt; {
          if (['image', 'stylesheet'].includes(request.resourceType())) {
            request.abort();
          } else {
            request.continue();
          }
        });
      }
  
      return {browser: context, page};
    },
  </code></pre>