UNPKG

@dash0/sdk-web

Version:

Dash0's Web SDK to collect telemetry from end-users' web browsers

37 lines (36 loc) 1.38 kB
// aliasing globals for improved minification // Avoid blowing up in an ssr context. It is important to check via typeof here because window might not even be declared when imported in ssr. export const win = typeof window !== "undefined" ? window : undefined; export const doc = win?.document; export const nav = win?.navigator; export const loc = typeof location !== "undefined" ? location : undefined; export const perf = win?.performance || win?.webkitPerformance || win?.msPerformance || win?.mozPerformance; export const encodeURIComponent = win?.encodeURIComponent; export const fetch = win?.fetch; export const localStorage = (function () { try { return win?.localStorage ?? null; } catch { // localStorage access is not permitted in certain security modes, e.g. // when cookies are completely disabled in web browsers. return null; } })(); export const sessionStorage = (function () { try { return win?.sessionStorage ?? null; } catch { // sessionStorage access is not permitted in certain security modes, e.g. // when cookies are completely disabled in web browsers. return null; } })(); /** * Exposed via this module to enable testing. */ export function sendBeacon(url, data) { return nav?.sendBeacon(url, data) ?? false; } /* eslint-enable no-restricted-globals */