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

net/http: HTTP requests failing with 'Protocol not available' on wasm/js when running in browser #59605

Open
rayvbr opened this issue Apr 13, 2023 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@rayvbr
Copy link

rayvbr commented Apr 13, 2023

What version of Go are you using (go version)?

$ go version
1.20.3

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
wasm/js

Chrome version: Version 111.0.5563.146 (Official Build) (x86_64)

(also reproducible with various Chromium-based browsers)

What did you do?

When doing a simple HTTP GET in a Go library compiled for wasm/js, all versions Go 1.18 and later are failing when running inside Chrome with dial tcp: lookup <some_domain>: Protocol not available.

When running on Go 1.17, this works fine. But Go 1.18 and later give the error above

The issue seems to be introduced by 2666262 and possibly made worse by 4c5d979. These commits seem to try to "autodetect" a Node environment by checking the presence of certain browser settings. While that may have been valid at time of committing, it seems the assumptions on which they were based no longer hold for more recent browser versions.

Perhaps a more direct/explicit way of checking whether we're running in a Node or browser environment would be more suitable? The methods above look a bit hacky

@dr2chase
Copy link
Contributor

@golang/wasm, @neild

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 13, 2023
@rayvbr
Copy link
Author

rayvbr commented Apr 21, 2023

I can confirm that removing the following lines from src/net/http/roundtrip_js.go fixes the issue:

if t.Dial != nil || t.DialContext != nil || t.DialTLS != nil || t.DialTLSContext != nil || jsFetchMissing || jsFetchDisabled {
	return t.roundTrip(req)
}

Just removing jsFetchDisabled is not sufficient

@philippgille
Copy link

philippgille commented Aug 19, 2023

With Go 1.21 and a (GOOS=js GOARCH=wasm) program that makes a simple HTTP request it works for me without manual modifications in a browser, in Deno and in Bun. But not in Node, where I get the same "Protocol not available" error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants