GoogleChrome/lighthouse

ECONNREFUSED error, I don't understand...

Closed this issue ยท 19 comments

Hi, I am on CentOS 7 with google-chrome installed (version 59) and node version 8.2.1

I run this code

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
  startingUrl: 'https://google.com',
  chromeFlags: ['--headless', '--disable-gpu']
}).then(chrome => {
  console.log(`Chrome debugging port running on ${chrome.port}`);
});

and it will return error like this.

(node:31716) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: connect ECONNREFUSED 127.0.0.1:33416
(node:31716) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I don't undestand that error, why it can't connect to that port? Is there any special settings needed on network side?

Thanks in advance.

specify a port like 8001 to try?

@sonyarianto, I was experimenting the same issue on Chrome 60 and adding --no-sandbox flag solved the problem.

const chromeLauncher = require('chrome-launcher');

chromeLauncher.launch({
  startingUrl: 'https://google.com',
  chromeFlags: ['--headless', '--disable-gpu', '--no-sandbox']
}).then(chrome => {
  console.log(`Chrome debugging port running on ${chrome.port}`);
});

Can you confirm you OS also @carloslfu? I believe that --no-sandbox will be required on *nix with --headless at the moment.

Is CentOS 7

@carloslfu Yes, it solve my problem by adding --no-sandbox

@carloslfu How do you even figure that out??? I mean, thank you, but like how

Hello @zwhitchcox . I found the solution by using command line e.g. lighthouse https://google.com. Then this error is shown: No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.

Ok, haha, I've never actually used the command lighthouse before..just using headless chrome...so i guess you know a lot more than I do haha

I didn't had luck with the command lighthouse - same error as carloslfu. I did had luck using lightouse programmatically and passing --no-sandbox to chromeLauncher.launch() - if possible I would recommend to add this flag to documentation since this blocks new users :( thanks

Thanks for reporting. I'm tracking this issue as GoogleChrome/chrome-launcher#6 so I'll dupe this to there.

@cancerberoSgx You can do so via the command line, just pass the flags to --chrome-flags, like so:
lighthouse <url> --chrome-flags="--no-sandbox --headless --disable-gpu"

So, I am trying this...
$ lighthouse https://google.com --chrome-flags="--no-sandbox --headless --disable-gpu"
...and getting this error...
ChromeLauncher:error connect ECONNREFUSED 127.0.0.1:36200 +2ms
ChromeLauncher:error Logging contents of /tmp/lighthouse.5Epzmdr/chrome-err.log +0ms
ChromeLauncher:error [20412:20412:0619/112922:ERROR:browser_main_loop.cc(219)] Running without the SUID sandbox! See https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md for more information on developing with the sandbox on.
ChromeLauncher:error [20412:20412:0619/112922:ERROR:browser_main_loop.cc(271)] Gtk: cannot open display:
ChromeLauncher:error +0ms
Unable to connect to Chrome
...Is this the same issue or something different?

It's the same class of error @mhenniger, ECONNREFUSED means Chrome didn't start properly and/or crashed.

The log messages you have indicate --headless isn't being respected. What version of Chrome are you running?

OMG... So you you asked a great question. Using npm to install lighthouse gave me chrome-launcher, but not chrome itself!!!! I am doing this work in Ubuntu. I just tried "sudo npm install chrome -g" but it seems to think I am on a mac, so I removed that. Do you have any recommendations for installing everything needed for lighthouse CLI? Thanks in advance for any tips you can provide. This is all new to me.

How to install Chrome is a bit beyond the scope and purpose of GitHub issues :) but you can take a look at the download script we use for an up-to-date Chrome version in CI and try Stack Overflow if you're still having trouble getting the basic environment setup.

@braincomb I tried adding lighthouse <url> --chrome-flags="--no-sandbox --headless --disable-gpu" however the same issue persists with me. I'm on Windows 10 and the Lighthouse CLI worked fine just days ago (well it refused to close the tab so I was left with hundreds of blank chrome tabs but otherwise fine ๐Ÿ˜† ) and now suddenly doesn't work. I get the same ECONNREFUSED error and Unable to connect to Chrome after waiting for upwards of ten seconds. It logs dozens of waiting for browser messages every 500ms or so. This is a very high priority for me because without this tool we cannot log data, we cannot update graphs and we cannot track progress and won't have accurate data to present. Thank you.

UPDATE: reverted node 17 to node 16 and it worked (plus a lot of debugging other solutions already mentioned)

it could that be dued to upgrade of Node version.
On my project, I start getting the issue since I have upgraded from Node 12 to 16
(and using a new docker image cimg/node:16.16.0-browsers that needs to install Chromium on my own...
- run: sudo apt-get -y update && sudo apt-get -y install xvfb chromium-browser

As per other replies, I get Error: connect ECONNREFUSED ::1:61099 using Node 17 or above (on Mac 13.2).

Works fine with Node v16.17.1.