Repository navigation
Closed
Labels
Description
Describe the bug
- Node.js version: 12.13.0
- Electron version : 7.0.0
- OS & version: linux mint 19.2
When using got in electron, useElectronNet option is not working with electron 7 for POST requests, returns net::ERR_INVALID_ARGUMENT error.
Actual behavior
HTTP request returns the following error :
GotError [RequestError]: net::ERR_INVALID_ARGUMENT
at ClientRequest.<anonymous> (/home/vincent/lls/lls-desktop/node_modules/got/source/request-as-event-emitter.js:192:19)
at Object.onceWrapper (events.js:291:20)
at ClientRequest.emit (events.js:208:15)
at ClientRequest.origin.emit (/home/vincent/lls/lls-desktop/node_modules/@szmarczak/http-timer/source/index.js:37:11)
at URLRequest../lib/browser/api/net.js.URLRequest._emitRequestEvent (electron/js2c/browser_init.js:2284:24) {
name: 'RequestError',
host: 'jsonplaceholder.typicode.com',
hostname: 'jsonplaceholder.typicode.com',
method: 'POST',
path: '/posts',
socketPath: undefined,
protocol: 'https:',
url: 'https://jsonplaceholder.typicode.com/posts',
gotOptions: {
path: '/posts',
protocol: 'https:',
slashes: true,
auth: null,
host: 'jsonplaceholder.typicode.com',
port: null,
hostname: 'jsonplaceholder.typicode.com',
hash: null,
search: null,
query: null,
pathname: '/posts',
href: 'https://jsonplaceholder.typicode.com/posts',
retry: {
retries: [Function],
methods: [Set],
statusCodes: [Set],
errorCodes: [Set]
},
headers: {
'user-agent': 'got/9.6.0 (https://github.com/sindresorhus/got)',
accept: 'application/json',
'accept-encoding': 'gzip, deflate',
'content-type': 'application/json',
'content-length': 39
},
hooks: {
beforeRequest: [],
beforeRedirect: [],
beforeRetry: [],
afterResponse: [],
beforeError: [],
init: []
},
decompress: true,
throwHttpErrors: true,
followRedirect: true,
stream: false,
form: false,
json: true,
cache: false,
useElectronNet: true,
body: '{"title":"foo","body":"bar","userId":1}',
method: 'POST'
}
}
Expected behavior
Correct HTTP response
Code to reproduce
In electron main or renderer process :
got
.post('https://jsonplaceholder.typicode.com/posts', {
body: {
title: 'foo',
body: 'bar',
userId: 1
},
json: true,
useElectronNet: true
})
.then(console.log)
.catch(console.log)
Activity
vbourgeois commentedon Oct 23, 2019
For GET requests, I get the following error :
with
It is working if I remove
useElectronNetoption.[-]useElectronNet with electron 7/6[/-][+]Fix Electron usage[/+]arantes555 commentedon Nov 12, 2019
It is probably linked to a recent (undocumented) change in electron@7 where setting content-length explicitly fails : electron/electron#21091
arantes555 commentedon Nov 12, 2019
(I have the same issue on
electron-fetcharantes555/electron-fetch#17 )szmarczak commentedon Nov 12, 2019
@arantes555 thanks for the heads up :)
arantes555 commentedon Nov 15, 2019
@szmarczak it turns out, in this specific case, it is indeed a breaking change in electron's API but not a bug per-say. You just cannot set explicitly a
content-lengthin electron >= 7, it is computed automatically in electron.szmarczak commentedon Nov 17, 2019
Ok, so I have made progress on this:
Things that do not work:
Things that can be fixed:
TODO (applies only when using electron):
options.sessiontooptions.electronSessionoptions.redirectconstant (manualto supportbeforeRedirecthook)request.once('login', ...)options.path = options.url.pathname + options.url.searchavaronYou can see my work here.
sindresorhus commentedon Nov 18, 2019
@szmarczak Honestly, I would prefer us opening an Electron issue about these differences instead of littering the codebase with workarounds. Electron says it's Node.js compatible, so it's up to them to fix it.
arantes555 commentedon Nov 18, 2019
@sindresorhus @szmarczak I believe there are PRs in electron that will fix most of these issues :
I suggest waiting until these are merged, and [email protected] is released with these fixes.
sindresorhus commentedon Nov 18, 2019
And for anything not fixed by those PRs or doesn't have an existing issue, we should open new Electron issues for.
szmarczak commentedon Nov 18, 2019
Haven't
electronhad this already? :OOOOOOOOOOOOO (not enough Os here)arantes555 commentedon Nov 18, 2019
@szmarczak they had it, they broke it ^^ electron@7 broke a lot of things in
net...sindresorhus commentedon Nov 19, 2019
Every single Electron release breaks a lot of random things...
vbourgeois commentedon Dec 10, 2019
szmarczak commentedon Dec 10, 2019
@vbourgeois We are aware that electron support is broken as of now - it's because electron is not compatible with the Node.js
netAPI. We'll provide more info when we get it working.szmarczak commentedon Dec 14, 2019
I have made more progress:
✔️
response.redirectUrlsis not empty anymore✔️
options.sessionwas renamed tooptions.electronSession✔️
beforeRedirecthooks work as expected✔️
option.followRedirectworks as expected✔️
option.responseTypeworks as expected✖️
options.retrydoes not work (yet)✖️
options.timeouthas no effect (onlytimeout.requestworks)✖️
options.decompresshas no effect✖️
options.dnsCachehas no effect✖️
Agentis not supported✖️
timingsare broken (won't fix)will send a PR in 10 mins
sindresorhus commentedon Dec 14, 2019
@szmarczak At this point, is it really worth all the effort? Electron will continue to break things and be incompatible. I feel like this is a losing battle. Electron support was only added because the Electron team said the
netAPI was compatible. It's clearly not and it doesn't look like it ever will be. I honestly think it would be better to just mark the Electron support as broken and deprecated and remove it in the next major version.szmarczak commentedon Dec 14, 2019
@sindresorhus I agree. Sent a PR - it will also display a deprecation warning. I think we should drop Electron support in a minor release, as it's been broken since Got v9. Or we can just drop it now.
sindresorhus commentedon Dec 16, 2019
@szmarczak I don't think we should drop it completely as it might work for people in some scenarios, and dropping it would be a breaking change. However, what we can do is to remove the docs for the Electron option and mention of Electron support, except the FAQ thing. And then open an issue about removing it completely in Got v11.
MarshallOfSound commentedon Dec 19, 2019
Hey @sindresorhus
This got sent my way, just wanted to check in here RE in
netmodule in Electron. In particular this bit from your comment.I haven't checked the history of our docs but our current
netdocumentation doesn't claim API compatibility, the closest it gets is this.We made the API close so that the super simple "request a thing from URL(X)" work across
httpandnet, anything complicated will fall over pretty quickly.I think dropping support here is the right move as they are fundamentally not API compatible and trying to make it look to users like they are will just result in weird bugs / issues for all involved. There are also lots of options to
http.requestlikeagentanddnsCachethat Electron can just never support innetdue to the way Chromiums networking stack is structured.If there's a part of our docs that I've missed that does erroneously claim compatibility let me know and I will gladly scrub it or reword it 👍
sindresorhus commentedon Dec 19, 2019
@MarshallOfSound It was removed here: electron/electron@8ea33d6#diff-4193de697f9ec0a7a4b858cb1a6ea968L24-L25 by my request: electron/electron#8117 (comment)
sindresorhus commentedon Dec 23, 2019
Note: When the
electron.netsupport is removed, you'll still be able to use Got in the Electron main process and in the renderer process through theelectron.remotemodule or if you use Node.js shims.nathanlesage commentedon Jan 15, 2020
One question, as I just saw the thread, and Got is working fine for me — will only the
net-module-support be dropped, or won't Got work altogether without these workarounds you mentioned? I don't usenet, because Got does everything I need and works perfectly, so this would be the question …?sindresorhus commentedon Jan 15, 2020
Only the
netsupport will be dropped.nathanlesage commentedon Jan 15, 2020
Perfect, thank you very much for the clarification!