chrome-remote-interface: Host header is specified and is not an IP address or localhost.

Component Version
Operating system Ubuntu 16.04
Node.js 8.11.1
Chrome/Chromium/… 66.0.3359.117
chrome-remote-interface 0.25.5

Is Chrome running in a container? YES

Getting the error in the latest version of stable chrome

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

In my case, I used k8s service name as the link URL, so I bypass the restriction by using DNS lookup to turn host name to IP address, then use it to connect the headless chrome instance.

const dns = require('dns').promises;

const { address } = await dns.lookup("chrome-service", {
  family: 4,
  hints: dns.ADDRCONFIG,
});

const browser = await puppeteer.connect({
  browserURL: `http://${address}:9222`,
});

It works.

how to override the default host header?

Like this:

--- a/lib/external-request.js
+++ b/lib/external-request.js
@@ -4,6 +4,7 @@ const REQUEST_TIMEOUT = 10000;

 // callback(err, data)
 function externalRequest(transport, options, callback) {
+    options.headers = {host: 'localhost'};
     const request = transport.get(options, function (response) {
         let data = '';
         response.on('data', function (chunk) {

if we can regenerated webSocketDebuggerUrl for temporary workaround, can be work?

It could be but since the webSocketDebuggerUrl issue appears to be a bug of Chrome I would wait a response from the Chromium team.


The simplest workaround is IMHO using the IP address directly.