mirror of
https://kevinblog.sytes.net/Code/Jibo-Revival-Group/JiboViteDocs.git
synced 2026-06-15 22:16:19 +00:00
30 lines
640 B
TypeScript
30 lines
640 B
TypeScript
import {
|
|
supportsNativeFetch,
|
|
supportsSendBeacon,
|
|
supportsXMLHttpRequest
|
|
} from "./featureDetection";
|
|
import type { RequestFnType } from "./request";
|
|
import {
|
|
requestWithNativeFetch,
|
|
requestWithSendBeacon,
|
|
requestWithXMLHttpRequest
|
|
} from "./request";
|
|
|
|
export function getRequesterForBrowser(): RequestFnType {
|
|
if (supportsSendBeacon()) {
|
|
return requestWithSendBeacon;
|
|
}
|
|
|
|
if (supportsXMLHttpRequest()) {
|
|
return requestWithXMLHttpRequest;
|
|
}
|
|
|
|
if (supportsNativeFetch()) {
|
|
return requestWithNativeFetch;
|
|
}
|
|
|
|
throw new Error(
|
|
"Could not find a supported HTTP request client in this environment."
|
|
);
|
|
}
|