# electron-fetch-via-main

> Fetch via main process in Electron

Latest version **1.2.0** (published 2023-10-25) · 0 weekly downloads

## Install

```sh
npm install electron-fetch-via-main
pnpm add electron-fetch-via-main
yarn add electron-fetch-via-main
bun add electron-fetch-via-main
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2023-10-25 |
| First published | 2023-10-24 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 9.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | wong2 |
| Maintainers | wong2 |

## Links

- npm: https://www.npmjs.com/package/electron-fetch-via-main
- Repository: https://github.com/wong2/electron-fetch-via-main
- Homepage: https://github.com/wong2/electron-fetch-via-main#readme
- Issues: https://github.com/wong2/electron-fetch-via-main/issues
- npm.io page: https://npm.io/package/electron-fetch-via-main

## Recent versions

- 1.2.0 (latest) — 2023-10-25
- 1.1.1 — 2023-10-24
- 1.1.0 — 2023-10-24
- 1.0.5 — 2023-10-24
- 1.0.4 — 2023-10-24
- 1.0.3 — 2023-10-24
- 1.0.2 — 2023-10-24
- 1.0.1 — 2023-10-24
- 1.0.0 — 2023-10-24

## README

# 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) {
  ...
}
```

---
_Source: https://npm.io/package/electron-fetch-via-main · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
