import { addHandler, maybeInstrument, triggerHandlers, supportsHistory, fill } from '@sentry/core'; import { WINDOW } from '../types.js'; let lastHref; function addHistoryInstrumentationHandler(handler) { const type = "history"; addHandler(type, handler); maybeInstrument(type, instrumentHistory); } function instrumentHistory() { WINDOW.addEventListener("popstate", () => { const to = WINDOW.location.href; const from = lastHref; lastHref = to; if (from === to) { return; } const handlerData = { from, to }; triggerHandlers("history", handlerData); }); if (!supportsHistory()) { return; } function historyReplacementFunction(originalHistoryFunction) { return function(...args) { const url = args.length > 2 ? args[2] : void 0; if (url) { const from = lastHref; const to = getAbsoluteUrl(String(url)); lastHref = to; if (from === to) { return originalHistoryFunction.apply(this, args); } const handlerData = { from, to }; triggerHandlers("history", handlerData); } return originalHistoryFunction.apply(this, args); }; } fill(WINDOW.history, "pushState", historyReplacementFunction); fill(WINDOW.history, "replaceState", historyReplacementFunction); } function getAbsoluteUrl(urlOrPath) { try { const url = new URL(urlOrPath, WINDOW.location.origin); return url.toString(); } catch { return urlOrPath; } } export { addHistoryInstrumentationHandler, instrumentHistory }; //# sourceMappingURL=history.js.map