https://github.com/agregoreweb/fetch-to-electron-protocol-handler
Generate electron protocol handlers from lazy-loaded fetch API handlers
https://github.com/agregoreweb/fetch-to-electron-protocol-handler
Last synced: 9 months ago
JSON representation
Generate electron protocol handlers from lazy-loaded fetch API handlers
- Host: GitHub
- URL: https://github.com/agregoreweb/fetch-to-electron-protocol-handler
- Owner: AgregoreWeb
- License: agpl-3.0
- Created: 2022-09-23T02:05:57.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-23T02:21:32.000Z (over 3 years ago)
- Last Synced: 2025-02-20T04:46:20.425Z (over 1 year ago)
- Language: JavaScript
- Size: 16.6 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fetch-to-electron-protocol-handler
Generate electron protocol handlers from lazy-loaded fetch API handlers
Refactored from the [Agregore Browser](https://github.com/AgregoreWeb/agregore-browser)
## Usage
```javascript
const fetchToHandler = require('fetch-to-electron-protocol-handler')
const {protocols, session} = require('electron')
const {handler} = fetchToHandler(getFetch, session.defaultSession)
protcols.registerStreamProtocol('example', handler)
async function getFetch() {
// Asynchronously initialize your `fetch()` function
// This is where you can set up your p2p nodes
// Note that the initializing will happen on the initial invocation
return async function fetch({url, ...opts}) => {
const convertedURL = new URL(url)
url.protocol = 'https:'
return globalThis.fetch(convertedURL.href, opts)
}
}
```