Chrome remote debugging expects host header
See original GitHub issueThis is a slightly weird one and I don’t think it is strictly speaking a puppeteer bug but thought I’d raise it here anyway.
Since version 1.2, when trying to connect to chrome via the remote debugging interface a host header must be specified.
This is not a problem in puppeteer per se, but we use python to get the ws address and so the python requests line now has to include headers={'Host':''} otherwise chrome returns an error: Host header is specified and is not an IP address or localhost.
I assume that puppeteer is setting this header in the background somewhere or chrome doesn’t care anymore once the request comes in via the websocket. I also could not find anything documented about this change, but I’m assuming that is has something to do with the .dev domain changes to HTTPS.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:18 (2 by maintainers)
Top Related StackOverflow Question
I’ve been working around this issue by doing a dns lookup in the code that sets up puppeteer (running inside Docker for Mac) to call back to my host machine.
For reference, my
CHROME_WS_ENDPOINTenv var looks like:ws://host.docker.internal:9223/devtools/page/FF3312E555CDEADBC3759BF0DE46B72BSince this is on top of results when I google “Host header is specified and is not an IP address or localhost” + “puppeteer” let’s leave crumbs for others:
= WHY
A security bug was filed against Chromium Dev Tools: https://bugs.chromium.org/p/chromium/issues/detail?id=813540
Around v66 of Chromium this patch was introduced: https://chromium-review.googlesource.com/c/chromium/src/+/952522
That patch inspects all HTTP (not WS) requests hitting Dev Tools endpoint and before doing anything else, validates it against:
where
This means that any non-IP-address-looking hostname that is NOT
localhost,*.localhostorlocalhost.localdomainwill result in error “Host header is specified and is not an IP address or localhost” error.= WHAT TO DO ABOUT IT
== Most reliable way to fix it
DNS resolve the hostname and feed that IP address to puppeteer instead of hostname.
(what @itaylor mentioned above, but in simpler, promise-ified DNS)
== Accidental Fixes / Shortcuts
Standard address for “host machine” on Docker is
host.docker.internal, but on Docker for Mac and similar there is another, older alias -docker.for.mac.localhost.host.docker.internalwill NOT work, whiledocker.for.mac.localhostwill natively work.Obviously aliasing headless chrome in your
/etc/hostsunder some*.localhosthostname will also work.