Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localhost connection refused when accessing headless chrome instance from docker container using puppeteer (run locally)

I am running headless chrome in a docker container and accessing it through puppeteer by running it locally using browerWSEndpoint. This part works fine. Once I get the connection established I try to use the instance to go to a localhost:port which fails and I get the following error:

Error: net::ERR_CONNECTION_REFUSED at http://localhost:port/
at navigate (path_to/node_app/puppet/node_modules/puppeteer/lib/Page.js:521:37)
at anonymous
at process._tickCallback (internal/process/next_tick.js:188:7)

Puppeteer version:^1.2

Platform / OS version: My puppeteer is running on my local machine which is MacOS 10.13.4 and the docker container is linux.

Node.js version: v8.11.2

I used the https://github.com/skalfyfan/dockerized-puppeteer for setting up headless chrome in my container. (Note: Did not use the app folder but only chrome) Used puppeteer to connect to this chrome instance. Tried to open a localhost using: await page.goto("http://localhost:port", {waitUntil: 'networkidle0'});

Expected: Connection established and docker container stopping.

Actual:

Error: net::ERR_CONNECTION_REFUSED at http://localhost:port/
at navigate (/node_app/puppet/node_modules/puppeteer/lib/Page.js:521:37)
at 
at process._tickCallback (internal/process/next_tick.js:188:7)

Thank you.

like image 586
user3674212 Avatar asked Jun 25 '18 04:06

user3674212


1 Answers

Fixed it. I used hostname -f on terminal to find the hostname and used it instead of localhost. I think there is no localhost mapping when launching chrome instance from docker.

like image 127
user3674212 Avatar answered Sep 19 '22 14:09

user3674212