Skip to content
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

ECONNREFUSED after launching Chrome #2331

Closed
eight04 opened this issue Oct 24, 2021 · 6 comments
Closed

ECONNREFUSED after launching Chrome #2331

eight04 opened this issue Oct 24, 2021 · 6 comments

Comments

@eight04
Copy link
Contributor

eight04 commented Oct 24, 2021

Is this a feature request or a bug?

Bug.

What is the current behavior?

  1. Launch Chrome via web-ext run.
  2. Wait 15 seconds,
  3. web-ext gets an ECONNREFUSED error and exits.
C:\Users\eight04\dev\tabalanche-extension>npm run start-chrome

> tabalanche-extension@1.0.0 start-chrome
> web-ext run --target chromium

Applying config files: ~\.web-ext-config.js, .\package.json
Running web extension from C:\Users\eight04\dev\tabalanche-extension

Error: connect ECONNREFUSED ::1:3693
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16)

Error code: ECONNREFUSED

What is the expected or desired behavior?

No error.

Version information (for bug reports)

  • Firefox version: Chrome 95.0.4638.54
  • Your OS and version: Windows 10
  • Paste the output of these commands:
C:\Users\eight04\dev\tabalanche-extension\node_modules\.bin>node --version && npm --version && web-ext --version
v17.0.0
8.1.0
6.5.0

There is an error in the background page of web-ext reload manager:
image

@igorakkerman
Copy link

igorakkerman commented Oct 24, 2021

Funny enough, I've been fighting with the same issue for the past few days.

Short answer:

Using Node.js 17.0.1, I get the same issue.
Using Node.js 16.12.0, it works fine.
Delete node_modules and run npm i with Node 16 installed before running web_ext again. I use https://github.com/coreybutler/nvm-windows to switch between versions.

Longer answer:

web-ext uses a temporary local extension in %TEMP%, the reload manager. The extension is built on the fly when web-ext is run. The reload manager connects back to the web-ext application using Websockets. web-ext creates a Websocket server on localhost using a random port. Then, it retrieves the actual values for host and port dynamically. Next, it takes the reload manager code, which contains placeholders, and fills in the retrieved values for host and port for the placeholders. Finally, it copies the reload manager extension to the temporary location.

The error message you mention refers to an IPv6 host address used in a URL: ::1. This is the actual value for host retrieved dynamically by web-ext. While you may use an IPv6 address in a URL, you must enclose it in square brackets, in your case: ws://[::1]:3692. That's why ws://::1:3692 without the square backets is invalid.

Unfortunately, this seems to be only one part of the answer. I tried to fix the extension, hardcoding localhost or 127.0.0.1, but the connection between web-ext and reload manager would still not be established and eventually time out.

I tried to build web-ext myself but got an error using Node 17. I tried with Node 15 and Node 16, both worked fine. Then I tried to use Node 16 to run web-ext, this also worked.

Since using Node.js 16 works fine, I will not investigate this issue further but wanted to share my findings.

@eight04
Copy link
Contributor Author

eight04 commented Oct 25, 2021

So there are two problems here:

  1. The error in reload-manager ECONNREFUSED after launching Chrome #2331 (comment)
  2. ECONNREFUSED comes from chrome-launcher:
    https://github.com/GoogleChrome/chrome-launcher/blob/4cfe2456dd840fdb7486f5c3e1a83fa383b1e1ac/src/chrome-launcher.ts#L316
    This used to connect to 127.0.0.1 but node@17 prefers IPv6 ("localhost" favours IPv6 in node v17, used to favour IPv4 nodejs/node#40537). However, Chrome doesn't listen on IPv6 so it never connects. A simple fix:
-- const client = net.createConnection(this.port);
++ const client = net.createConnection(this.port, '127.0.0.1');

@eight04
Copy link
Contributor Author

eight04 commented Oct 25, 2021

Here is the build issue of Webpack:
webpack/webpack#14532 (comment)

@eight04
Copy link
Contributor Author

eight04 commented Oct 26, 2021

Seems that there is a similar issue for adb. I have to pass --adb-host 127.0.0.1 when targeting firefox-android.

@willdurand
Copy link
Member

See also: GoogleChrome/chrome-launcher#251

@eight04
Copy link
Contributor Author

eight04 commented Nov 26, 2021

Can't reproduce with web-ext@6.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants