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 package (net/http: neither of Fetch nor XMLHttpRequest APIs is available) #839

Open
pjebs opened this Issue Jul 6, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@pjebs
Contributor

pjebs commented Jul 6, 2018

I am making an electron app. http.Client works for render process (inside chromium JavaScript) but doesn't work from main process (node js)

It says an error about it not being supported.

How can I make requests from the main process? The compatibility table says I need a polyfill? Why does node js need a polyfill when it works from within chromium. What's the difference?

Is it better to use node library directly or perhaps axios library?

@dmitshur dmitshur added the question label Jul 6, 2018

@dmitshur

This comment has been minimized.

Member

dmitshur commented Jul 6, 2018

http.Client in GopherJS has 2 implementations: one based on Fetch API, another based on XMLHttpRequest API. It picks whichever is available in that order. Both of those tend to be available in browsers.

Node doesn't seem to provide either one by default, that's why you need a polyfill (either for Fetch or for XHR) for http.Client to work under node. The problem seems to be that there wasn't a good one, last time people looked. See previous discussion in #586.

@pjebs

This comment has been minimized.

Contributor

pjebs commented Jul 6, 2018

Thanks. Worked it out using assistance from #586

Step 1:
Add dependency to npm:
npm install xhr2

Step 2:
Create a imports.inc.js file in the same level as your Go files.

Step 3:
Add global.XMLHttpRequest = require('xhr2'); to the imports.inc.js file.

@pjebs pjebs closed this Jul 6, 2018

@pjebs pjebs changed the title from Net/http package to Net/http package (net/http: neither of Fetch nor XMLHttpRequest APIs is available) Jul 6, 2018

@pjebs pjebs changed the title from Net/http package (net/http: neither of Fetch nor XMLHttpRequest APIs is available) to net/http package (net/http: neither of Fetch nor XMLHttpRequest APIs is available) Jul 6, 2018

@pjebs

This comment has been minimized.

Contributor

pjebs commented Jul 8, 2018

@shurcooL
It looks like xhr2 does not respect context cancellation despite the documentation stating that it supports abort()

Do you know how I can make cancelling the specific request work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment