@causalfoundry/js-sdk
Version:
Causal Foundry WEB SDK (JS/TS)
25 lines (23 loc) • 599 B
text/typescript
import isBrowser from "is-in-browser";
/**
* Checks if the environment is online.
* In browser: uses navigator.onLine only (no fetch, avoids CORS issues).
* In Node.js: always returns true.
* Optionally, pass a testUrl for advanced use (may cause CORS errors).
*/
export const isOnline = (): boolean => {
if (!isBrowser) {
// Node.js or non-browser environment
return true;
}
// Browser environment
if (
typeof window !== "undefined" &&
typeof window.navigator !== "undefined" &&
!window.navigator.onLine
) {
return false;
}
// Fallback
return true;
};