🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

electron-fetch-via-main

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

electron-fetch-via-main

Fetch via main process in Electron

latest
Source
npmnpm
Version
1.2.0
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

electron-fetch-via-main

Why

This module helps you bypass restrictions when making cross origin requests in renderer process, by delegate the requests to main process.

Install

npm install electron-fetch-via-main

Usage

Note that this module only work with contextIsolation: false

In main process

import { setupMainFetchlistener } from 'electron-fetch-via-main'

setupMainFetchlistener()

In preload scripts, expose fetchViaMain to renderer

import { fetchViaMain } from 'electron-fetch-via-main'

window.fetchViaMain = fetchViaMain

In renderer process, just replace fetch with fetchViaMain

const resp = await window.fetchViaMain('https://...', {
  method: 'POST',
  body: { ... },
})

// read json
await resp.json()

// streaming response
for await (const chunk of resp.body) {
  ...
}

FAQs

Package last updated on 25 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts