5/5/2023 0 Comments Electron api request![]() There are different kinds of protocol handlers (file, string, buffer, etc.). You could use this mechanism to return any kind of response. Like vmd.openFile('yolo.txt').Īnd here's how we use a custom protocol to provide Emoji images via something like emoji://simple_smile. ClientRequest implements the Writable Stream interface and is therefore an EventEmitter. ![]() It is only available as a return value of other methods in the Electron API. new ClientRequest(options) options (Object string) - If options is a string, it is interpreted as the request. Process: Main This class is not exported from the 'electron' module. The code in the renderer process will just use the API provided by the preload script. Process: Main This class is not exported from the electron module. You could do something like myapp://internal/pokemon?q=fire and it would act like an API but actually read from the file system, for example. ![]() The code in the preload script has access to node modules while the renderer itself doesn't.īut if you don't load a remote URL in your window then enabling node integration shouldn't be a problem.Īnother possibility to communicate between the main process and the renderer is through custom protocols. Preload scripts allow you to provide an API to the renderer (and other stuff). If you want to turn off nodeIntegration you could use a preload script ( webPreferences.preload). options (Object String) - If options is a String, it is interpreted as the request URL. There are two things that might be relevant to know when sending requests: We need to know that our channel may accept some parameters We need to know which channel to use for the response Both of them are optional but we can now create an interface for sending requests. It's actually recommended to do as much as possible in the renderer process. Requests are sent from our renderer process. This class is not exported from the electron module. You can use all packages that work with Node.js in the main process as well as in the renderer process if you have webPreferences.nodeIntegration set to true in the BrowserWindow options.
0 Comments
Leave a Reply. |