Skip to content

Commit aface52

Browse files
committed
Mention that Electron net module is not supported
Fixes sindresorhus#1473
1 parent 1a97dc0 commit aface52

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

documentation/migration-guides.md

+13-6
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,16 @@ Readability is very important to us, so we have different names for these option
7070

7171
- The [`agent` option](2-options.md#agent) is now an object with `http`, `https` and `http2` properties.
7272
- The [`timeout` option](6-timeout.md) is now an object. You can set timeouts on particular events!
73-
- The [`searchParams` option](https://github.com/sindresorhus/got#searchParams) is always serialized using [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) unless it's a `string`.
74-
- To use streams, call `got.stream(url, options)` or `got(url, {…, isStream: true}`).
73+
- The [`searchParams` option](https://github.com/sindresorhus/got#searchParams) is always serialized using [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams).
74+
- In order to pass a custom query string, provide it with the `url` option.\
75+
`got('https://example.com', {searchParams: {test: ''}})``https://example.com/?test=`\
76+
`got('https://example.com/?test')``https://example.com/?test`
77+
- To use streams, call `got.stream(url, options)` or `got(url, {…, isStream: true})`.
7578

7679
#### Breaking changes
7780

7881
- The `json` option is not a `boolean`, it's an `object`. It will be stringified and used as a body.
79-
- The `form` option is an `object` and will be used as `application/x-www-form-urlencoded` body
82+
- The `form` option is an `object` and will be used as `application/x-www-form-urlencoded` body.
8083
- All headers are converted to lowercase.\
8184
According to [the spec](https://datatracker.ietf.org/doc/html/rfc7230#section-3.2), the headers are case-insensitive.
8285
- No `oauth` / `hawk` / `aws` / `httpSignature` option.\
@@ -86,9 +89,9 @@ Readability is very important to us, so we have different names for these option
8689
You need to pass an agent with `keepAlive` option set to `true`.
8790
- No `proxy` option. You need to [pass a custom agent](tips.md#proxy).
8891
- No `auth` option.\
89-
You need to use `username` / `password` instead or set the `authorization` header manually.
92+
You need to use [`username`](2-options.md#username) / [`password`](2-options.md#password) instead or set the `authorization` header manually.
9093
- No `baseUrl` option.\
91-
Instead, there is `prefixUrl` which appends a trailing slash if not present.
94+
Instead, there is [`prefixUrl`](2-options.md#prefixurl) which appends a trailing slash if not present.
9295
- No `removeRefererHeader` option.\
9396
You can remove the `referer` header in a [`beforeRequest` hook](hooks.md#beforerequest).
9497
- No `followAllRedirects` option.
@@ -138,4 +141,8 @@ In terms of streams nothing has really changed.
138141

139142
#### You're good to go!
140143

141-
Well, you have already come this far :tada: Take a look at the [documentation](../readme.md#documentation). It's worth the time to read it. There are [some great tips](tips.md). If something is unclear or doesn't work as it should, don't hesitate to [open an issue](https://github.com/sindresorhus/got/issues/new/choose).
144+
Well, you have already come this far :tada:\
145+
Take a look at the [documentation](../readme.md#documentation). It's worth the time to read it.\
146+
There are [some great tips](tips.md).
147+
148+
If something is unclear or doesn't work as it should, don't hesitate to [open an issue](https://github.com/sindresorhus/got/issues/new/choose).

readme.md

+26
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,32 @@ For advanced JSON usage, check out the [`parseJson`](2-options.md#parsejson) and
157157
- [travis-got](https://github.com/samverschueren/travis-got) - Got convenience wrapper to interact with the Travis API
158158
- [graphql-got](https://github.com/kevva/graphql-got) - Got convenience wrapper to interact with GraphQL
159159

160+
## Electron `net` module is not supported
161+
162+
Got doesn't support the `electron.net` module. It's missing crucial APIs that are available in Node.js. While Got used to support `electron.net`, it got very unstable and caused many errors.
163+
164+
However, you can use [IPC communication](https://www.electronjs.org/docs/api/ipc-main#ipcmainhandlechannel-listener) to get the Response object:
165+
166+
```js
167+
// Main process
168+
const got = require('got');
169+
170+
const instance = got.extend({
171+
// ...
172+
});
173+
174+
ipcMain.handle('got', async (event, ...args) => {
175+
const {statusCode, headers, body} = await instance(...args);
176+
return {statusCode, headers, body};
177+
});
178+
179+
// Renderer process
180+
async () => {
181+
const {statusCode, headers, body} = await ipcRenderer.invoke('got', 'https://httpbin.org/anything');
182+
// ...
183+
}
184+
```
185+
160186
## Comparison
161187

162188
| | `got` | [`request`][r0] | [`node-fetch`][n0] | [`ky`][k0] | [`axios`][a0] | [`superagent`][s0] |

0 commit comments

Comments
 (0)