fix: resolve localhost to 127.0.0.1 in browserUrl and wsEndpoint#1821
Closed
yiidtw wants to merge 1 commit intoChromeDevTools:mainfrom
Closed
fix: resolve localhost to 127.0.0.1 in browserUrl and wsEndpoint#1821yiidtw wants to merge 1 commit intoChromeDevTools:mainfrom
yiidtw wants to merge 1 commit intoChromeDevTools:mainfrom
Conversation
On macOS, Node.js dns.lookup('localhost') non-deterministically resolves
to ::1 (IPv6) or 127.0.0.1 (IPv4) depending on network state. Chrome's
debug port typically binds only one address family, causing intermittent
connection failures when users pass --browserUrl http://localhost:9222.
This adds a resolveLocalhostToIPv4() helper that normalizes localhost to
127.0.0.1 in both --browserUrl and --wsEndpoint coerce functions, while
preserving explicit 127.0.0.1 and [::1] addresses.
Contributor
|
Hi @yiidtw! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On macOS,
dns.lookup('localhost')non-deterministically resolves to::1(IPv6) or127.0.0.1(IPv4) depending on network state. Chrome's debug port typically binds only one address family, causing intermittent connection failures when users pass--browserUrl http://localhost:9222or--wsEndpoint ws://localhost:9222/....This PR adds a
resolveLocalhostToIPv4()helper that replaceslocalhostwith127.0.0.1in both thebrowserUrlandwsEndpointcoerce functions, matching Chrome's default IPv4 binding.Changes
resolveLocalhostToIPv4(url)— regex replace of//localhost:and//localhost/with//127.0.0.1browserUrlcoerce (after URL validation)wsEndpointcoerce (after URL/protocol validation)browserUrltest to expect127.0.0.1127.0.0.1, preserve explicit[::1]Test plan
[::1], wsEndpoint localhost