Puppeteer err_tunnel_connection_failed




Puppeteer – ERR_TUNNEL_CONNECTION_FAILED

The ERR_TUNNEL_CONNECTION_FAILED error in Puppeteer typically occurs when there is a problem establishing a secure connection to the target URL. This can happen due to various reasons, such as network connectivity issues, firewall restrictions, or proxy settings.

One common cause of this error is when Puppeteer’s default Chromium instance is unable to connect to the internet through a proxy server. In such cases, you can try configuring Puppeteer to use a different proxy or bypass the proxy altogether.

Here’s an example of how to bypass the proxy while launching Puppeteer:

        const puppeteer = require('puppeteer');

        (async () => {
          const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'], ignoreDefaultArgs: ['--disable-extensions'], ignoreHTTPSErrors: true });
          const page = await browser.newPage();

          await page.setRequestInterception(true);
          page.on('request', (request) => {
            if (request.resourceType() === 'Document')
              request.continue();
            else
              request.abort();
          });

          await page.goto('https://www.example.com');

          // Rest of your code...

          await browser.close();
        })();
      

In this example, we launch Puppeteer with the arguments ‘–no-sandbox’ and ‘–disable-setuid-sandbox’ to avoid certain sandbox-related issues. Setting ‘ignoreHTTPSErrors’ to true allows Puppeteer to ignore certificate errors if any.

The ‘setRequestInterception’ method is used to intercept and modify network requests. In this case, we only allow requests for Document resources to continue and abort all other requests. This effectively bypasses the proxy for the main page load.

Finally, we navigate to the target URL using ‘page.goto’, perform any necessary actions, and close the browser when finished.

This is just one example of how to handle the ERR_TUNNEL_CONNECTION_FAILED error in Puppeteer. The specific solution may vary depending on the underlying cause of the error.

Remember to check your network connection, firewall settings, and proxy configuration to ensure they are not causing the connection failure. Additionally, make sure you are using the latest version of Puppeteer and its dependencies.


Leave a comment