Files
makelore/electron/utils/proxy-fetch.ts

23 lines
521 B
TypeScript

/**
* Use Electron's network stack when available so requests honor
* session.defaultSession.setProxy(...). Fall back to the Node global fetch
* for non-Electron test environments.
*/
import { net } from 'electron';
export async function proxyAwareFetch(
input: string | URL,
init?: RequestInit
): Promise<Response> {
if (process.versions.electron) {
try {
return await net.fetch(input, init);
} catch {
// Fall through to the global fetch.
}
}
return await fetch(input, init);
}