title: Puppeteer - How to connect WSEndpoint using local IP address?
body: <p>I have two Node.js scripts for puppeteer automation. </p>
  
  <p>1) launcher.js</p>
  
  <p>This Puppeteer script launches a chrome browser and disconnects the chrome so that it can be connected by using WSEndpoint.</p>
  
  <pre><code>const puppeteer = require('puppeteer');
  
  module.exports = async () =&gt; {
      try {
          const options = {
              headless: false,
              devtools: false,
              ignoreHTTPSErrors: true,
              args: [
                  `--no-sandbox`,
                  `--disable-setuid-sandbox`,
                  `--ignore-certificate-errors`
              ]
          };
          const browser = await puppeteer.launch(options);
          let pagesCount = await browser.pages();
          const browserWSEndpoint = await browser.wsEndpoint();
          // console  WSEndPoint say : "ws://127.0.0.1:42207/devtools/browser/dbb2525b-ce44-43c2-a335-ff15d0306f36"
          console.log("browserWSEndpoint----- :&gt; ", browserWSEndpoint);
          await browser.disconnect();
          return browserWSEndpoint;
      } catch (err) {
          console.error(err);
          process.exit(1);
          return false;
      }
  };
  </code></pre>
  
  <p>2) connector.js</p>
  
  <p>Launches headless chrome and tries to connect chrome by WSEndPoint by various hostnames. If I ran this script with run command as  <code>node connector.js localhost</code>, it tries to connect WSEndpint with localhost as the hostname.</p>
  
  <pre><code>const puppeteer = require('puppeteer');
  const launcher = require('./launcher');
  
  (async (host) =&gt; {
      try {
          let WSEndPoint = await launcher();
          WSEndPoint = WSEndPoint.replace('127.0.0.1', host);
          console.log("WSENDPOINT :", WSEndPoint);
          const browser = await puppeteer.connect({
              browserWSEndpoint: WSEndPoint,
              ignoreHTTPSErrors: true
          });
          let pagesCount = await browser.pages();
          console.log("Pages available :&gt; ", pagesCount.length);
          // const browserWSEndpoint = await browser.wsEndpoint();
          await browser.disconnect();
          process.exit(1);
          return true;
      } catch (err) {
          console.error(err);
          process.exit(1);
          return false;
      }
  })(process.argv[2]);
  </code></pre>
  
  <p>But I can't connect the WSEndpint of the chrome using my local IP address ( say 192.168.1.36). Why? </p>
  
  <p>The error message is </p>
  
  <pre><code>{ Error: connect ECONNREFUSED 192.168.1.33:36693
      at Object._errnoException (util.js:992:11)
      at _exceptionWithHostPort (util.js:1014:20)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect',
    address: '192.168.1.33',
    port: 36693 }
  </code></pre>