UNPKG

@elhamdev/tracejs

Version:

A modern, privacy-conscious alternative to browser fingerprinting for unique user identification.

38 lines (37 loc) 1.18 kB
"use strict"; /** * Helpers for safely accessing browser-only globals. These are necessary because * TraceJS can be imported in non-browser contexts (SSR, Node) where globals like * window, document, or navigator do not exist. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.getLocalStorage = exports.getNavigator = exports.getDocument = exports.getGlobalWindow = void 0; const getGlobalWindow = () => { return typeof window !== "undefined" ? window : null; }; exports.getGlobalWindow = getGlobalWindow; const getDocument = () => { return typeof document !== "undefined" ? document : null; }; exports.getDocument = getDocument; const getNavigator = () => { if (typeof navigator !== "undefined") { return navigator; } const win = (0, exports.getGlobalWindow)(); return win?.navigator ?? null; }; exports.getNavigator = getNavigator; const getLocalStorage = () => { const win = (0, exports.getGlobalWindow)(); if (!win || !("localStorage" in win)) { return null; } try { return win.localStorage; } catch { return null; } }; exports.getLocalStorage = getLocalStorage;