-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chrome remote debugging expects host header #2242
Comments
I was testing this bug with previous puppeteer version and had the same error. Maybe this bug is related to chrome because I used v67 chrome. With v66 chrome everything is OK. |
Got the same error with a Chromium 67.0.3383.0 while trying to get a docker-container to work with my laravel application, Will try to get version 66 by now |
@grantstephens thanks for reaching to us. This was recently introduced in https://chromium-review.googlesource.com/c/chromium/src/+/952522. The error is issued if the host header is set to non-localhost and non-IP address. What's your python library? It looks like it sets a non-trivial host header, so you have to override it with empty value. |
I'm using requests, which AFAIK does not send a host header by default, but I may be wrong. Either way- couldn't find any changelog for it suddenly happening (From the chrome side) so thought I'd just put it here in case anybody else was having a similar issue. |
and so what's the workaround of the issue? |
I started getting this when I upgraded from version 65 to 66. |
"The error is issued if the host header is set to non-localhost and non-IP address." Does this imply that the host header should use an IP address? Which header? Is this an error in a websites configuration or an error in puppeteer? |
@aslushnikov @pavelfeldman the problem of setting the $ curl -H host: localhost:9222/json/list
[ {
"description": "",
"devtoolsFrontendUrl": "/devtools/inspector.html?ws=/devtools/page/A4566872556EA7F94C344A8ABEA30A73",
"id": "A4566872556EA7F94C344A8ABEA30A73",
"title": "about:blank",
"type": "page",
"url": "about:blank",
"webSocketDebuggerUrl": "ws:///devtools/page/A4566872556EA7F94C344A8ABEA30A73"
} ] |
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. const endPoint = await changeUrlHostToUseIp(process.env.CHROME_WS_ENDPOINT);
browser = await puppeteer.connect({
browserWSEndpoint: endPoint,
// You may need the following if you use this browser to connect to a machine with self-signed certs
// ignoreHTTPSErrors: true,
});
const lookupAsync = require('util').promisify(require('dns').lookup);
// Fix for https://github.com/GoogleChrome/puppeteer/issues/2242
async function changeUrlHostToUseIp(urlString) {
const urlParsed = url.parse(urlString);
const { address: hostIp } = await lookupAsync(urlParsed.hostname);
delete urlParsed.host;
urlParsed.hostname = hostIp;
return url.format(urlParsed);
} For reference, my |
@itaylor thank you for your work-around. Before I go trying it, I figured I'd ask you: Does that work-around require set |
@bean5, it shouldn't require |
Wait, what is the fix? |
I read wondering the same thing. Please re-open unless this is intended
functionality.
|
@aslushnikov Can you clarify why this ticket has been closed? Is the behaviour in described in this ticket intentional? Please re-open or clarify |
While we're waint to hear back (3 months and counting), @itaylor 's workaround is good. |
Issue is on the Chrome side, at https://bugs.chromium.org/p/chromium/issues/detail?id=813540 |
@drzraf can you explain your solution? |
Since 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: Around v66 of Chromium this patch was introduced: 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 = 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 Obviously aliasing headless chrome in your |
This 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.
The text was updated successfully, but these errors were encountered: