title: Requesting webSocketDebuggerUrl from Chrome-Headless in Docker Container
body: <h3>Setup</h3>
  
  <p>Trying to run chrome headless as a container (Image: <a href="https://hub.docker.com/r/alpeware/chrome-headless-trunk" rel="nofollow noreferrer">https://hub.docker.com/r/alpeware/chrome-headless-trunk</a>) in my docker-compose and connecting to it from another container.</p>
  
  <h3>Problem</h3>
  
  <p>To actually connect to chrome inside the container, I first need to retrieve the webSocketDebuggerUrl, which is available at <a href="http://0.0.0.0:9222/json/version" rel="nofollow noreferrer">http://0.0.0.0:9222/json/version</a> of the chrome-headless.</p>
  
  <p>The Problem is: my request to this path always fails with </p>
  
  <blockquote>
    <p>RequestError: Error: connect ECONNREFUSED 0.0.0.0:9222</p>
  </blockquote>
  
  <p>and cant get the webSocketDebuggerUrl to connect to chrome.</p>
  
  <h3>Some more Info</h3>
  
  <p>Also if I visit <a href="http://0.0.0.0:9222/json/version" rel="nofollow noreferrer">http://0.0.0.0:9222/json/version</a> in my browser myself, copy the url and hardcode it into my puppeteer.connect(), it ONLY works as expected, if I replace the address of '0.0.0.0' to my (linked) container-name (specified in docker-compose): <a href="http://chrome:9222/json/version" rel="nofollow noreferrer">http://chrome:9222/json/version</a></p>
  
  <p>If I try to request the webSocketDebuggerUrl from /json/version while using container-name address (<a href="http://chrome:9222/json/version" rel="nofollow noreferrer">http://chrome:9222/json/version</a>) i get the error</p>
  
  <blockquote>
    <p>StatusCodeError: 500 - "Host header is specified and is not an IP address or localhost."</p>
  </blockquote>
  
  <h3>My Code (abstraction)</h3>
  
  <pre><code>const rp = require('request-promise')
  const puppeteer = require('puppeteer-core')
  
  let url = await rp({uri:'http://0.0.0.0:9222/json/version', json: true }).then(res =&gt; res.webSocketDebuggerUrl)
  let browser = await puppeteer.connect({ browserWSEndpoint: url })
  </code></pre>