"Host header is specified and is not an IP address or localhost" message when using chromedp headless-shell

Viewed 474

I'm trying to deploy chromedp/headless-shell to Cloud Run.

Here is my Dockerfile:

FROM chromedp/headless-shell
ENTRYPOINT [ "/headless-shell/headless-shell", "--remote-debugging-address=0.0.0.0", "--remote-debugging-port=9222", "--disable-gpu", "--headless", "--no-sandbox" ]

The command I used to deploy to Cloud Run is

gcloud run deploy chromedp-headless-shell --source . --port 9222

Problem

When I go to this path /json/list, I expect to see something like this

    [{
       "description": "",
       "devtoolsFrontendUrl": "/devtools/inspector.html?ws=localhost:9222/devtools/page/B06F36A73E5F33A515E87C6AE4E2284E",
       "id": "B06F36A73E5F33A515E87C6AE4E2284E",
       "title": "about:blank",
       "type": "page",
       "url": "about:blank",
       "webSocketDebuggerUrl": "ws://localhost:9222/devtools/page/B06F36A73E5F33A515E87C6AE4E2284E"
    }]

but instead, I get this error:

Host header is specified and is not an IP address or localhost.

Is there something wrong with my configuration or is Cloud Run not the ideal choice for deploying this?

1 Answers

This specific issue is not unique to Cloud Run. It originates from an existing change in the Chrome DevTools Protocol which generates this error when accessing it remotely. It could be attributed to security measures against some types of attacks. You can see the related Chromium pull request here.

I deployed a chromedp/headless-shell container to Cloud Run using your configuration and also received the same error. Now, there is this useful comment in a GitHub issue showing a workaround for this problem, by passing a HOST:localhost header. While this does work when I tested it locally, it does not work on Cloud Run (returns a 404 error). This 404 error could be due to how Cloud Run also utilizes the HOST header to route requests to the correct service.

Unfortunately this answer is not a solution, but it sheds some light on what you are seeing and why. I would go for using a different service from GCP, such a GCE that are pure virtual machines and less managed.

Related