net Type
⚠ Process Availability: Main ✔ | Renderer ❌ | Utility ✔ | Exported ✔
Issue HTTP/HTTPS requests using Chromium's native networking libraryProcess: Main, UtilityThe net module is a client-side API for issuing HTTP(S) requests. It is similar to the HTTP and HTTPS modules of Node.js but uses Chromium's native networking library instead of the Node.js implementation, offering better support for web proxies. It also supports checking network status.The following is a non-exhaustive list of why you may consider using the net module instead of the native Node.js modules:* Automatic management of system proxy configuration, support of the wpad protocol and proxy pac configuration files.* Automatic tunneling of HTTPS requests.* Support for authenticating proxies using basic, digest, NTLM, Kerberos or negotiate authentication schemes.* Support for traffic monitoring proxies: Fiddler-like proxies used for access control and monitoring.The API components (including classes, methods, properties and event names) are similar to those used in Node.js.Example usage:const { app } = require('electron')app.whenReady().then(() => { const { net } = require('electron') const request = net.request('https://github.com') request.on('response', (response) => { console.log(STATUS: \({response.statusCode}) console.log(HEADERS:\){JSON.stringify(response.headers)}) response.on('data', (chunk) => { console.log(BODY: ${chunk}) }) response.on('end', () => { console.log('No more data in response.') }) }) request.end()})The net API can be used only after the application emits the ready event. Trying to use the module before the ready event will throw an error.
Static members
| Static member |
Description
|
Full Usage:
net.fetch (input, ?init)
Parameters:
U2<string, Request>
?init : RequestInit
Returns: Promise<Response>
Modifiers: inline |
see Response.Sends a request, similarly to how fetch() works in the renderer, using Chrome's network stack. This differs from Node's fetch(), which uses Node.js's HTTP stack.Example:This method will issue requests from the default session. To send a fetch request from another session, use ses.fetch().See the MDN documentation for fetch() for more details.Limitations:* net.fetch() does not support the data: or blob: schemes.* The value of the integrity option is ignored.* The .type and .url values of the returned Response object are incorrect.By default, requests made with net.fetch can be made to custom protocols as well as file:, and will trigger webRequest handlers if present. When the non-standard bypassCustomProtocolHandlers option is set in RequestInit, custom protocol handlers will not be called for this request. This allows forwarding an intercepted request to the built-in handler. webRequest handlers will still be triggered when bypassing custom protocols.> [!NOTE] In the utility process, custom protocols are not supported.
|
Full Usage:
net.isOnline ()
Returns: bool
Modifiers: inline |
Whether there is currently internet connection.A return value of false is a pretty strong indicator that the user won't be able to connect to remote sites. However, a return value of true is inconclusive; even if some link is up, it is uncertain whether a particular connection attempt to a particular remote site will be successful.
|
Full Usage:
net.online
Returns: bool
|
A boolean property. Whether there is currently internet connection.A return value of false is a pretty strong indicator that the user won't be able to connect to remote sites. However, a return value of true is inconclusive; even if some link is up, it is uncertain whether a particular connection attempt to a particular remote site will be successful.
|
|
Creates a ClientRequest instance using the provided options which are directly forwarded to the ClientRequest constructor. The net.request method would be used to issue both secure and insecure HTTP requests according to the specified protocol scheme in the options object.
|
Full Usage:
net.resolveHost (host, ?queryType, ?source, ?cacheUsage, ?secureDnsPolicy)
Parameters:
string
?queryType : QueryType
?source : Source
?cacheUsage : CacheUsage
?secureDnsPolicy : SecureDnsPolicy
Returns: Promise<ResolvedHost>
Modifiers: inline |
Resolves with the resolved IP addresses for the host.This method will resolve hosts from the default session. To resolve a host from another session, use ses.resolveHost().
|
fable-electron-docs-api