Files
DeskClaw/electron/utils/proxy-fetch.ts
2026-03-02 17:33:06 +08:00

22 lines
536 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.
*/
export async function proxyAwareFetch(
input: string | URL,
init?: RequestInit
): Promise<Response> {
if (process.versions.electron) {
try {
const { net } = await import('electron');
return await net.fetch(input, init);
} catch {
// Fall through to the global fetch.
}
}
return await fetch(input, init);
}