@grafana/faro-web-sdk 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle/faro-web-sdk.iife.js +1 -1
- package/dist/bundle/types/instrumentations/console/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/csp/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/errors/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/navigation/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/performance/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/session/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/userActions/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/view/instrumentation.d.ts +1 -1
- package/dist/bundle/types/instrumentations/webVitals/instrumentation.d.ts +1 -1
- package/dist/bundle/types/transports/console/transport.d.ts +1 -1
- package/dist/bundle/types/transports/fetch/transport.d.ts +1 -1
- package/dist/cjs/config/getWebInstrumentations.js +3 -4
- package/dist/cjs/config/getWebInstrumentations.js.map +1 -1
- package/dist/cjs/config/makeCoreConfig.js +48 -60
- package/dist/cjs/config/makeCoreConfig.js.map +1 -1
- package/dist/cjs/initialize.js +3 -3
- package/dist/cjs/initialize.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/activityWindowTracker.js +44 -65
- package/dist/cjs/instrumentations/_internal/activityWindowTracker.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/monitors/consoleMonitor.js +11 -16
- package/dist/cjs/instrumentations/_internal/monitors/consoleMonitor.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/monitors/domMutationMonitor.js +5 -5
- package/dist/cjs/instrumentations/_internal/monitors/domMutationMonitor.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/monitors/httpRequestMonitor.js +28 -30
- package/dist/cjs/instrumentations/_internal/monitors/httpRequestMonitor.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/monitors/interactionMonitor.js +7 -7
- package/dist/cjs/instrumentations/_internal/monitors/interactionMonitor.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/monitors/performanceEntriesMonitor.js +8 -8
- package/dist/cjs/instrumentations/_internal/monitors/performanceEntriesMonitor.js.map +1 -1
- package/dist/cjs/instrumentations/_internal/monitors/urlChangeMonitor.js +24 -32
- package/dist/cjs/instrumentations/_internal/monitors/urlChangeMonitor.js.map +1 -1
- package/dist/cjs/instrumentations/console/instrumentation.js +29 -49
- package/dist/cjs/instrumentations/console/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/csp/instrumentation.js +14 -32
- package/dist/cjs/instrumentations/csp/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/errors/getErrorDetails.js +23 -23
- package/dist/cjs/instrumentations/errors/getErrorDetails.js.map +1 -1
- package/dist/cjs/instrumentations/errors/getValueAndTypeFromMessage.js +5 -5
- package/dist/cjs/instrumentations/errors/getValueAndTypeFromMessage.js.map +1 -1
- package/dist/cjs/instrumentations/errors/instrumentation.js +11 -29
- package/dist/cjs/instrumentations/errors/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/errors/registerOnerror.js +6 -10
- package/dist/cjs/instrumentations/errors/registerOnerror.js.map +1 -1
- package/dist/cjs/instrumentations/errors/registerOnunhandledrejection.js +16 -17
- package/dist/cjs/instrumentations/errors/registerOnunhandledrejection.js.map +1 -1
- package/dist/cjs/instrumentations/errors/stackFrames/buildStackFrame.js +2 -2
- package/dist/cjs/instrumentations/errors/stackFrames/buildStackFrame.js.map +1 -1
- package/dist/cjs/instrumentations/errors/stackFrames/getDataFromSafariExtensions.js +4 -4
- package/dist/cjs/instrumentations/errors/stackFrames/getDataFromSafariExtensions.js.map +1 -1
- package/dist/cjs/instrumentations/errors/stackFrames/getStackFramesFromError.js +16 -17
- package/dist/cjs/instrumentations/errors/stackFrames/getStackFramesFromError.js.map +1 -1
- package/dist/cjs/instrumentations/errors/stackFrames/parseStacktrace.js +1 -1
- package/dist/cjs/instrumentations/errors/stackFrames/parseStacktrace.js.map +1 -1
- package/dist/cjs/instrumentations/navigation/instrumentation.js +27 -45
- package/dist/cjs/instrumentations/navigation/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/performance/instrumentation.js +19 -74
- package/dist/cjs/instrumentations/performance/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/performance/navigation.js +15 -26
- package/dist/cjs/instrumentations/performance/navigation.js.map +1 -1
- package/dist/cjs/instrumentations/performance/performanceUtils.js +18 -33
- package/dist/cjs/instrumentations/performance/performanceUtils.js.map +1 -1
- package/dist/cjs/instrumentations/performance/resource.js +13 -25
- package/dist/cjs/instrumentations/performance/resource.js.map +1 -1
- package/dist/cjs/instrumentations/session/instrumentation.js +45 -74
- package/dist/cjs/instrumentations/session/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/PersistentSessionsManager.js +21 -24
- package/dist/cjs/instrumentations/session/sessionManager/PersistentSessionsManager.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/VolatileSessionManager.js +21 -24
- package/dist/cjs/instrumentations/session/sessionManager/VolatileSessionManager.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/getSessionManagerByConfig.js +2 -2
- package/dist/cjs/instrumentations/session/sessionManager/getSessionManagerByConfig.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/sampling.js +5 -5
- package/dist/cjs/instrumentations/session/sessionManager/sampling.js.map +1 -1
- package/dist/cjs/instrumentations/session/sessionManager/sessionManagerUtils.js +47 -65
- package/dist/cjs/instrumentations/session/sessionManager/sessionManagerUtils.js.map +1 -1
- package/dist/cjs/instrumentations/userActions/instrumentation.js +15 -34
- package/dist/cjs/instrumentations/userActions/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/userActions/processUserActionEventHandler.js +11 -11
- package/dist/cjs/instrumentations/userActions/processUserActionEventHandler.js.map +1 -1
- package/dist/cjs/instrumentations/userActions/userActionController.js +49 -53
- package/dist/cjs/instrumentations/userActions/userActionController.js.map +1 -1
- package/dist/cjs/instrumentations/userActions/util.js +4 -4
- package/dist/cjs/instrumentations/userActions/util.js.map +1 -1
- package/dist/cjs/instrumentations/view/instrumentation.js +12 -30
- package/dist/cjs/instrumentations/view/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/webVitals/instrumentation.js +11 -29
- package/dist/cjs/instrumentations/webVitals/instrumentation.js.map +1 -1
- package/dist/cjs/instrumentations/webVitals/webVitalsWithAttribution.js +87 -94
- package/dist/cjs/instrumentations/webVitals/webVitalsWithAttribution.js.map +1 -1
- package/dist/cjs/metas/browser/meta.js +14 -14
- package/dist/cjs/metas/browser/meta.js.map +1 -1
- package/dist/cjs/metas/k6/meta.js +3 -14
- package/dist/cjs/metas/k6/meta.js.map +1 -1
- package/dist/cjs/metas/page/meta.js +7 -19
- package/dist/cjs/metas/page/meta.js.map +1 -1
- package/dist/cjs/metas/sdk/meta.js +3 -3
- package/dist/cjs/metas/sdk/meta.js.map +1 -1
- package/dist/cjs/metas/session/createSession.js +2 -2
- package/dist/cjs/metas/session/createSession.js.map +1 -1
- package/dist/cjs/transports/console/transport.js +10 -29
- package/dist/cjs/transports/console/transport.js.map +1 -1
- package/dist/cjs/transports/fetch/transport.js +82 -176
- package/dist/cjs/transports/fetch/transport.js.map +1 -1
- package/dist/cjs/utils/throttle.js +6 -10
- package/dist/cjs/utils/throttle.js.map +1 -1
- package/dist/cjs/utils/url.js +4 -5
- package/dist/cjs/utils/url.js.map +1 -1
- package/dist/cjs/utils/webStorage.js +4 -4
- package/dist/cjs/utils/webStorage.js.map +1 -1
- package/dist/esm/instrumentations/errors/getErrorDetails.js +1 -0
- package/dist/esm/instrumentations/errors/getErrorDetails.js.map +1 -1
- package/dist/esm/transports/fetch/transport.js +1 -1
- package/dist/esm/transports/fetch/transport.js.map +1 -1
- package/dist/types/instrumentations/console/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/csp/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/errors/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/navigation/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/performance/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/session/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/userActions/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/view/instrumentation.d.ts +1 -1
- package/dist/types/instrumentations/webVitals/instrumentation.d.ts +1 -1
- package/dist/types/transports/console/transport.d.ts +1 -1
- package/dist/types/transports/fetch/transport.d.ts +1 -1
- package/package.json +5 -5
|
@@ -2,18 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.monitorHttpRequests = monitorHttpRequests;
|
|
4
4
|
exports.__resetHttpRequestMonitorForTests = __resetHttpRequestMonitorForTests;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
6
|
+
const url_1 = require("../../../utils/url");
|
|
7
|
+
const const_1 = require("./const");
|
|
8
|
+
const apiTypeFetch = 'fetch';
|
|
9
|
+
const apiTypeXhr = 'xhr';
|
|
10
10
|
/**
|
|
11
11
|
* Monitors if any http requests are in progress.
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
let httpRequestObservable;
|
|
14
|
+
let isInstrumented = false;
|
|
15
|
+
let originalXhrOpen;
|
|
16
|
+
let originalFetchFn;
|
|
17
17
|
function monitorHttpRequests() {
|
|
18
18
|
if (httpRequestObservable) {
|
|
19
19
|
return httpRequestObservable;
|
|
@@ -44,66 +44,64 @@ function monitorHttpRequests() {
|
|
|
44
44
|
}
|
|
45
45
|
return httpRequestObservable;
|
|
46
46
|
}
|
|
47
|
-
function monitorXhr(
|
|
48
|
-
var onRequestStart = _a.onRequestStart, onRequestEnd = _a.onRequestEnd;
|
|
47
|
+
function monitorXhr({ onRequestStart, onRequestEnd, }) {
|
|
49
48
|
if (!originalXhrOpen) {
|
|
50
49
|
originalXhrOpen = XMLHttpRequest.prototype.open;
|
|
51
50
|
}
|
|
52
51
|
XMLHttpRequest.prototype.open = function () {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
const url = arguments[1];
|
|
53
|
+
const isIgnoredUrl = (0, url_1.isUrlIgnored)(url);
|
|
54
|
+
const method = arguments[0];
|
|
55
|
+
const requestId = (0, faro_core_1.genShortID)();
|
|
57
56
|
// request has started to load data.
|
|
58
57
|
this.addEventListener('loadstart', function () {
|
|
59
58
|
if (!isIgnoredUrl) {
|
|
60
|
-
onRequestStart({ url
|
|
59
|
+
onRequestStart({ url, method, requestId, apiType: apiTypeXhr });
|
|
61
60
|
}
|
|
62
61
|
});
|
|
63
62
|
// transaction completes successfully.
|
|
64
63
|
this.addEventListener('load', function () {
|
|
65
64
|
if (!isIgnoredUrl) {
|
|
66
|
-
onRequestEnd({ url
|
|
65
|
+
onRequestEnd({ url, method, requestId, apiType: apiTypeXhr });
|
|
67
66
|
}
|
|
68
67
|
});
|
|
69
68
|
this.addEventListener('error', function () {
|
|
70
69
|
if (!isIgnoredUrl) {
|
|
71
|
-
onRequestEnd({ url
|
|
70
|
+
onRequestEnd({ url, method, requestId, apiType: apiTypeXhr });
|
|
72
71
|
}
|
|
73
72
|
});
|
|
74
73
|
this.addEventListener('abort', function () {
|
|
75
74
|
if (!isIgnoredUrl) {
|
|
76
|
-
onRequestEnd({ url
|
|
75
|
+
onRequestEnd({ url, method, requestId, apiType: apiTypeXhr });
|
|
77
76
|
}
|
|
78
77
|
});
|
|
79
78
|
originalXhrOpen.apply(this, arguments);
|
|
80
79
|
};
|
|
81
80
|
}
|
|
82
|
-
function monitorFetch(
|
|
83
|
-
var onRequestEnd = _a.onRequestEnd, onRequestStart = _a.onRequestStart;
|
|
81
|
+
function monitorFetch({ onRequestEnd, onRequestStart, }) {
|
|
84
82
|
if (!originalFetchFn) {
|
|
85
83
|
originalFetchFn = window.fetch;
|
|
86
84
|
}
|
|
87
85
|
window.fetch = function () {
|
|
88
86
|
var _a, _b;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
87
|
+
const url = (_a = (0, url_1.getUrlFromResource)(arguments[0])) !== null && _a !== void 0 ? _a : '';
|
|
88
|
+
const isIgnoredUrl = (0, url_1.isUrlIgnored)(url);
|
|
89
|
+
const method = ((_b = arguments[1]) !== null && _b !== void 0 ? _b : {}).method;
|
|
90
|
+
const requestId = (0, faro_core_1.genShortID)();
|
|
93
91
|
if (!isIgnoredUrl) {
|
|
94
|
-
onRequestStart({ url
|
|
92
|
+
onRequestStart({ url, method, requestId, apiType: apiTypeFetch });
|
|
95
93
|
}
|
|
96
94
|
return originalFetchFn
|
|
97
95
|
.apply(this, arguments)
|
|
98
|
-
.then(
|
|
96
|
+
.then((response) => {
|
|
99
97
|
if (!isIgnoredUrl) {
|
|
100
|
-
onRequestEnd({ url
|
|
98
|
+
onRequestEnd({ url, method, requestId, apiType: apiTypeFetch });
|
|
101
99
|
}
|
|
102
100
|
return response;
|
|
103
101
|
})
|
|
104
|
-
.catch(
|
|
102
|
+
.catch((error) => {
|
|
105
103
|
if (!isIgnoredUrl) {
|
|
106
|
-
onRequestEnd({ url
|
|
104
|
+
onRequestEnd({ url, method, requestId, apiType: apiTypeFetch });
|
|
107
105
|
}
|
|
108
106
|
throw error;
|
|
109
107
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"httpRequestMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/httpRequestMonitor.ts"],"names":[],"mappings":";;AAoBA,kDAoCC;AAyFD,8EAWC;AA5JD,
|
|
1
|
+
{"version":3,"file":"httpRequestMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/httpRequestMonitor.ts"],"names":[],"mappings":";;AAoBA,kDAoCC;AAyFD,8EAW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E,CAAC;QACnB,MAAc,CAAC,KAAK,GAAG,eAAe,CAAC;IAC1C,CAAC;IACD,qBAAqB,GAAG,SAAS,CAAC;IAClC,cAAc,GAAG,KAAK,CAAC;IACvB,eAAe,GAAG,SAAS,CAAC;IAC5B,eAAe,GAAG,SAAS,CAAC;AAC9B,CAAC","sourcesContent":["import { genShortID, Observable } from '@grafana/faro-core';\n\nimport { getUrlFromResource, isUrlIgnored } from '../../../utils/url';\n\nimport { MESSAGE_TYPE_HTTP_REQUEST_END, MESSAGE_TYPE_HTTP_REQUEST_START } from './const';\nimport type { HttpRequestEndMessage, HttpRequestMessagePayload, HttpRequestStartMessage } from './types';\n\ntype RequestProps = HttpRequestMessagePayload;\n\nconst apiTypeFetch = 'fetch';\nconst apiTypeXhr = 'xhr';\n\n/**\n * Monitors if any http requests are in progress.\n */\nlet httpRequestObservable: Observable<HttpRequestStartMessage | HttpRequestEndMessage> | undefined;\nlet isInstrumented = false;\nlet originalXhrOpen: typeof XMLHttpRequest.prototype.open | undefined;\nlet originalFetchFn: typeof window.fetch | undefined;\n\nexport function monitorHttpRequests(): Observable<HttpRequestStartMessage | HttpRequestEndMessage> {\n if (httpRequestObservable) {\n return httpRequestObservable;\n }\n\n httpRequestObservable = new Observable<HttpRequestStartMessage | HttpRequestEndMessage>();\n\n function emitStartMessage(requestProps: RequestProps) {\n httpRequestObservable!.notify({\n type: MESSAGE_TYPE_HTTP_REQUEST_START,\n request: requestProps,\n });\n }\n\n function emitEndMessage(requestProps: RequestProps) {\n httpRequestObservable!.notify({\n type: MESSAGE_TYPE_HTTP_REQUEST_END,\n request: requestProps,\n });\n }\n\n if (!isInstrumented) {\n monitorFetch({\n onRequestStart: emitStartMessage,\n onRequestEnd: emitEndMessage,\n });\n\n monitorXhr({\n onRequestStart: emitStartMessage,\n onRequestEnd: emitEndMessage,\n });\n\n isInstrumented = true;\n }\n\n return httpRequestObservable;\n}\n\nfunction monitorXhr({\n onRequestStart,\n onRequestEnd,\n}: {\n onRequestStart: (props: RequestProps) => void;\n onRequestEnd: (props: RequestProps) => void;\n}) {\n if (!originalXhrOpen) {\n originalXhrOpen = XMLHttpRequest.prototype.open;\n }\n\n XMLHttpRequest.prototype.open = function () {\n const url = arguments[1];\n const isIgnoredUrl = isUrlIgnored(url);\n const method = arguments[0];\n\n const requestId = genShortID();\n\n // request has started to load data.\n this.addEventListener('loadstart', function () {\n if (!isIgnoredUrl) {\n onRequestStart({ url, method, requestId, apiType: apiTypeXhr });\n }\n });\n\n // transaction completes successfully.\n this.addEventListener('load', function () {\n if (!isIgnoredUrl) {\n onRequestEnd({ url, method, requestId, apiType: apiTypeXhr });\n }\n });\n\n this.addEventListener('error', function () {\n if (!isIgnoredUrl) {\n onRequestEnd({ url, method, requestId, apiType: apiTypeXhr });\n }\n });\n\n this.addEventListener('abort', function () {\n if (!isIgnoredUrl) {\n onRequestEnd({ url, method, requestId, apiType: apiTypeXhr });\n }\n });\n originalXhrOpen!.apply(this, arguments as any);\n };\n}\n\nfunction monitorFetch({\n onRequestEnd,\n onRequestStart,\n}: {\n onRequestStart: (props: RequestProps) => void;\n onRequestEnd: (props: RequestProps) => void;\n}) {\n if (!originalFetchFn) {\n originalFetchFn = window.fetch;\n }\n\n window.fetch = function () {\n const url = getUrlFromResource(arguments[0]) ?? '';\n const isIgnoredUrl = isUrlIgnored(url);\n const method = (arguments[1] ?? {}).method;\n\n const requestId = genShortID();\n\n if (!isIgnoredUrl) {\n onRequestStart({ url, method, requestId, apiType: apiTypeFetch });\n }\n\n return originalFetchFn!\n .apply(this, arguments as any)\n .then((response) => {\n if (!isIgnoredUrl) {\n onRequestEnd({ url, method, requestId, apiType: apiTypeFetch });\n }\n return response;\n })\n .catch((error) => {\n if (!isIgnoredUrl) {\n onRequestEnd({ url, method, requestId, apiType: apiTypeFetch });\n }\n throw error;\n });\n };\n}\n\n// Test-only utility to reset instrumentation and singleton between tests\nexport function __resetHttpRequestMonitorForTests() {\n if (originalXhrOpen) {\n XMLHttpRequest.prototype.open = originalXhrOpen;\n }\n if (originalFetchFn) {\n (window as any).fetch = originalFetchFn;\n }\n httpRequestObservable = undefined;\n isInstrumented = false;\n originalXhrOpen = undefined;\n originalFetchFn = undefined;\n}\n"]}
|
|
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MESSAGE_TYPE_INTERACTION = void 0;
|
|
4
4
|
exports.monitorInteractions = monitorInteractions;
|
|
5
5
|
exports.__resetInteractionMonitorForTests = __resetInteractionMonitorForTests;
|
|
6
|
-
|
|
6
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
7
7
|
exports.MESSAGE_TYPE_INTERACTION = 'interaction';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
let interactionObservable;
|
|
9
|
+
const registeredEventNames = new Set();
|
|
10
|
+
const eventNameToHandler = new Map();
|
|
11
11
|
function monitorInteractions(eventNames) {
|
|
12
12
|
if (!interactionObservable) {
|
|
13
13
|
interactionObservable = new faro_core_1.Observable();
|
|
14
14
|
}
|
|
15
|
-
eventNames.forEach(
|
|
15
|
+
eventNames.forEach((eventName) => {
|
|
16
16
|
if (!registeredEventNames.has(eventName)) {
|
|
17
|
-
|
|
17
|
+
const handler = () => {
|
|
18
18
|
interactionObservable.notify({ type: exports.MESSAGE_TYPE_INTERACTION, name: eventName });
|
|
19
19
|
};
|
|
20
20
|
window.addEventListener(eventName, handler);
|
|
@@ -26,7 +26,7 @@ function monitorInteractions(eventNames) {
|
|
|
26
26
|
}
|
|
27
27
|
// Test-only utility to reset state between tests
|
|
28
28
|
function __resetInteractionMonitorForTests() {
|
|
29
|
-
eventNameToHandler.forEach(
|
|
29
|
+
eventNameToHandler.forEach((handler, eventName) => {
|
|
30
30
|
window.removeEventListener(eventName, handler);
|
|
31
31
|
});
|
|
32
32
|
eventNameToHandler.clear();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interactionMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/interactionMonitor.ts"],"names":[],"mappings":";;;AAaA,kDAiBC;AAGD,8EAOC;AAxCD,
|
|
1
|
+
{"version":3,"file":"interactionMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/interactionMonitor.ts"],"names":[],"mappings":";;;AAaA,kDAiBC;AAGD,8EAOC;AAxCD,kDAAgD;AAEnC,QAAA,wBAAwB,GAAG,aAAa,CAAC;AAOtD,IAAI,qBAAiE,CAAC;AACtE,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC/C,MAAM,kBAAkB,GAAG,IAAI,GAAG,EAA8B,CAAC;AAEjE,SAAgB,mBAAmB,CAAC,UAAoB;IACtD,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,qBAAqB,GAAG,IAAI,sBAAU,EAAsB,CAAC;IAC/D,CAAC;IAED,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE;QAC/B,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACzC,MAAM,OAAO,GAAG,GAAG,EAAE;gBACnB,qBAAsB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,gCAAwB,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;YACrF,CAAC,CAAC;YACF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;YAC5C,oBAAoB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;YACpC,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAC7C,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,iDAAiD;AACjD,SAAgB,iCAAiC;IAC/C,kBAAkB,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE;QAChD,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IACH,kBAAkB,CAAC,KAAK,EAAE,CAAC;IAC3B,oBAAoB,CAAC,KAAK,EAAE,CAAC;IAC7B,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC","sourcesContent":["import { Observable } from '@grafana/faro-core';\n\nexport const MESSAGE_TYPE_INTERACTION = 'interaction';\n\nexport type InteractionMessage = {\n type: typeof MESSAGE_TYPE_INTERACTION;\n name: string;\n};\n\nlet interactionObservable: Observable<InteractionMessage> | undefined;\nconst registeredEventNames = new Set<string>();\nconst eventNameToHandler = new Map<string, (e: Event) => void>();\n\nexport function monitorInteractions(eventNames: string[]): Observable<InteractionMessage> {\n if (!interactionObservable) {\n interactionObservable = new Observable<InteractionMessage>();\n }\n\n eventNames.forEach((eventName) => {\n if (!registeredEventNames.has(eventName)) {\n const handler = () => {\n interactionObservable!.notify({ type: MESSAGE_TYPE_INTERACTION, name: eventName });\n };\n window.addEventListener(eventName, handler);\n registeredEventNames.add(eventName);\n eventNameToHandler.set(eventName, handler);\n }\n });\n\n return interactionObservable;\n}\n\n// Test-only utility to reset state between tests\nexport function __resetInteractionMonitorForTests() {\n eventNameToHandler.forEach((handler, eventName) => {\n window.removeEventListener(eventName, handler);\n });\n eventNameToHandler.clear();\n registeredEventNames.clear();\n interactionObservable = undefined;\n}\n"]}
|
|
@@ -2,19 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.monitorPerformanceEntries = monitorPerformanceEntries;
|
|
4
4
|
exports.__resetPerformanceEntriesMonitorForTests = __resetPerformanceEntriesMonitorForTests;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
6
|
+
const instrumentation_1 = require("../../performance/instrumentation");
|
|
7
|
+
const performanceConstants_1 = require("../../performance/performanceConstants");
|
|
8
|
+
const const_1 = require("./const");
|
|
9
|
+
let performanceObservable;
|
|
10
|
+
let isSubscribed = false;
|
|
11
|
+
let subscription;
|
|
12
12
|
function monitorPerformanceEntries() {
|
|
13
13
|
if (!performanceObservable) {
|
|
14
14
|
performanceObservable = new faro_core_1.Observable();
|
|
15
15
|
}
|
|
16
16
|
if (!isSubscribed) {
|
|
17
|
-
subscription = instrumentation_1.performanceEntriesSubscription.subscribe(
|
|
17
|
+
subscription = instrumentation_1.performanceEntriesSubscription.subscribe((data) => {
|
|
18
18
|
if (data.type === performanceConstants_1.RESOURCE_ENTRY) {
|
|
19
19
|
performanceObservable.notify({ type: const_1.MESSAGE_TYPE_RESOURCE_ENTRY });
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"performanceEntriesMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/performanceEntriesMonitor.ts"],"names":[],"mappings":";;AAYA,8DAeC;AAGD,4FAOC;AArCD,
|
|
1
|
+
{"version":3,"file":"performanceEntriesMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/performanceEntriesMonitor.ts"],"names":[],"mappings":";;AAYA,8DAeC;AAGD,4FAOC;AArCD,kDAAgD;AAGhD,uEAAmF;AACnF,iFAAwE;AAExE,mCAAsD;AAEtD,IAAI,qBAA6C,CAAC;AAClD,IAAI,YAAY,GAAG,KAAK,CAAC;AACzB,IAAI,YAAsC,CAAC;AAE3C,SAAgB,yBAAyB;IACvC,IAAI,CAAC,qBAAqB,EAAE,CAAC;QAC3B,qBAAqB,GAAG,IAAI,sBAAU,EAAE,CAAC;IAC3C,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,gDAA8B,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,EAAE;YAC/D,IAAI,IAAI,CAAC,IAAI,KAAK,qCAAc,EAAE,CAAC;gBACjC,qBAAsB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,mCAA2B,EAAE,CAAC,CAAC;YACvE,CAAC;QACH,CAAC,CAAC,CAAC;QACH,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;IAED,OAAO,qBAAqB,CAAC;AAC/B,CAAC;AAED,iDAAiD;AACjD,SAAgB,wCAAwC;IACtD,IAAI,YAAY,EAAE,CAAC;QACjB,YAAY,CAAC,WAAW,EAAE,CAAC;IAC7B,CAAC;IACD,YAAY,GAAG,SAAS,CAAC;IACzB,YAAY,GAAG,KAAK,CAAC;IACrB,qBAAqB,GAAG,SAAS,CAAC;AACpC,CAAC","sourcesContent":["import { Observable } from '@grafana/faro-core';\nimport type { Subscription } from '@grafana/faro-core';\n\nimport { performanceEntriesSubscription } from '../../performance/instrumentation';\nimport { RESOURCE_ENTRY } from '../../performance/performanceConstants';\n\nimport { MESSAGE_TYPE_RESOURCE_ENTRY } from './const';\n\nlet performanceObservable: Observable | undefined;\nlet isSubscribed = false;\nlet subscription: Subscription | undefined;\n\nexport function monitorPerformanceEntries(): Observable {\n if (!performanceObservable) {\n performanceObservable = new Observable();\n }\n\n if (!isSubscribed) {\n subscription = performanceEntriesSubscription.subscribe((data) => {\n if (data.type === RESOURCE_ENTRY) {\n performanceObservable!.notify({ type: MESSAGE_TYPE_RESOURCE_ENTRY });\n }\n });\n isSubscribed = true;\n }\n\n return performanceObservable;\n}\n\n// Test-only utility to reset state between tests\nexport function __resetPerformanceEntriesMonitorForTests() {\n if (subscription) {\n subscription.unsubscribe();\n }\n subscription = undefined;\n isSubscribed = false;\n performanceObservable = undefined;\n}\n"]}
|
|
@@ -3,36 +3,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.MESSAGE_TYPE_URL_CHANGE = void 0;
|
|
4
4
|
exports.monitorUrlChanges = monitorUrlChanges;
|
|
5
5
|
exports.__resetUrlChangeMonitorForTests = __resetUrlChangeMonitorForTests;
|
|
6
|
-
|
|
6
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
7
7
|
exports.MESSAGE_TYPE_URL_CHANGE = 'url-change';
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
8
|
+
let urlChangeObservable;
|
|
9
|
+
let isInstrumented = false;
|
|
10
|
+
let lastHref;
|
|
11
|
+
let originalPushState;
|
|
12
|
+
let originalReplaceState;
|
|
13
|
+
let onPopStateHandler;
|
|
14
|
+
let onHashChangeHandler;
|
|
15
|
+
let onNavigateHandler;
|
|
16
|
+
let originalNavigateEventIntercept;
|
|
17
17
|
function monitorUrlChanges() {
|
|
18
18
|
if (!urlChangeObservable) {
|
|
19
19
|
urlChangeObservable = new faro_core_1.Observable();
|
|
20
20
|
lastHref = location.href;
|
|
21
21
|
}
|
|
22
22
|
function emit(trigger, toOverride) {
|
|
23
|
-
|
|
23
|
+
const next = toOverride !== null && toOverride !== void 0 ? toOverride : location.href;
|
|
24
24
|
if (next !== lastHref) {
|
|
25
|
-
urlChangeObservable.notify({ type: exports.MESSAGE_TYPE_URL_CHANGE, from: lastHref, to: next, trigger
|
|
25
|
+
urlChangeObservable.notify({ type: exports.MESSAGE_TYPE_URL_CHANGE, from: lastHref, to: next, trigger });
|
|
26
26
|
lastHref = next;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
if (!isInstrumented) {
|
|
30
|
-
|
|
30
|
+
const hasNavigation = 'navigation' in window && 'NavigateEvent' in window;
|
|
31
31
|
if (hasNavigation) {
|
|
32
32
|
// Prefer Navigation API when supported: do not patch history or add popstate/hashchange listeners
|
|
33
|
-
onNavigateHandler =
|
|
33
|
+
onNavigateHandler = (e) => {
|
|
34
34
|
try {
|
|
35
|
-
|
|
35
|
+
const destination = e === null || e === void 0 ? void 0 : e.destination;
|
|
36
36
|
if ((destination === null || destination === void 0 ? void 0 : destination.sameDocument) && typeof destination.url === 'string') {
|
|
37
37
|
emit('navigate', destination.url);
|
|
38
38
|
}
|
|
@@ -42,7 +42,7 @@ function monitorUrlChanges() {
|
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
44
|
window.navigation.addEventListener('navigate', onNavigateHandler);
|
|
45
|
-
|
|
45
|
+
const NavigateEventConstructor = window.NavigateEvent;
|
|
46
46
|
if (NavigateEventConstructor &&
|
|
47
47
|
NavigateEventConstructor.prototype &&
|
|
48
48
|
typeof NavigateEventConstructor.prototype.intercept === 'function') {
|
|
@@ -52,8 +52,8 @@ function monitorUrlChanges() {
|
|
|
52
52
|
// Wrap intercept to detect soft navigations (cross-document turned same-document)
|
|
53
53
|
NavigateEventConstructor.prototype.intercept = function (options) {
|
|
54
54
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const canIntercept = !!(this === null || this === void 0 ? void 0 : this.canIntercept);
|
|
56
|
+
const destination = this === null || this === void 0 ? void 0 : this.destination;
|
|
57
57
|
if (canIntercept &&
|
|
58
58
|
destination &&
|
|
59
59
|
destination.sameDocument === false &&
|
|
@@ -74,29 +74,21 @@ function monitorUrlChanges() {
|
|
|
74
74
|
if (!originalPushState) {
|
|
75
75
|
originalPushState = window.history.pushState;
|
|
76
76
|
}
|
|
77
|
-
window.history.pushState = function () {
|
|
78
|
-
|
|
79
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
80
|
-
args[_i] = arguments[_i];
|
|
81
|
-
}
|
|
82
|
-
var result = originalPushState.apply(window.history, args);
|
|
77
|
+
window.history.pushState = function (...args) {
|
|
78
|
+
const result = originalPushState.apply(window.history, args);
|
|
83
79
|
emit('pushState');
|
|
84
80
|
return result;
|
|
85
81
|
};
|
|
86
82
|
if (!originalReplaceState) {
|
|
87
83
|
originalReplaceState = window.history.replaceState;
|
|
88
84
|
}
|
|
89
|
-
window.history.replaceState = function () {
|
|
90
|
-
|
|
91
|
-
for (var _i = 0; _i < arguments.length; _i++) {
|
|
92
|
-
args[_i] = arguments[_i];
|
|
93
|
-
}
|
|
94
|
-
var result = originalReplaceState.apply(window.history, args);
|
|
85
|
+
window.history.replaceState = function (...args) {
|
|
86
|
+
const result = originalReplaceState.apply(window.history, args);
|
|
95
87
|
emit('replaceState');
|
|
96
88
|
return result;
|
|
97
89
|
};
|
|
98
|
-
onPopStateHandler =
|
|
99
|
-
onHashChangeHandler =
|
|
90
|
+
onPopStateHandler = () => emit('popstate');
|
|
91
|
+
onHashChangeHandler = () => emit('hashchange');
|
|
100
92
|
window.addEventListener('popstate', onPopStateHandler);
|
|
101
93
|
window.addEventListener('hashchange', onHashChangeHandler);
|
|
102
94
|
isInstrumented = true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urlChangeMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/urlChangeMonitor.ts"],"names":[],"mappings":";;;AAqBA,8CA4FC;AAGD,0EA4BC;AAhJD,gDAAgD;AAEnC,QAAA,uBAAuB,GAAG,YAAY,CAAC;AASpD,IAAI,mBAA6D,CAAC;AAClE,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,QAA4B,CAAC;AACjC,IAAI,iBAA8D,CAAC;AACnE,IAAI,oBAAoE,CAAC;AACzE,IAAI,iBAAyE,CAAC;AAC9E,IAAI,mBAA6E,CAAC;AAClF,IAAI,iBAA4D,CAAC;AACjE,IAAI,8BAA8G,CAAC;AAEnH,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,mBAAmB,GAAG,IAAI,sBAAU,EAAoB,CAAC;QACzD,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,SAAS,IAAI,CAAC,OAAoC,EAAE,UAAmB;QACrE,IAAM,IAAI,GAAG,UAAU,aAAV,UAAU,cAAV,UAAU,GAAI,QAAQ,CAAC,IAAI,CAAC;QACzC,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,mBAAoB,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,+BAAuB,EAAE,IAAI,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S,GAAG,8BAA8B,CAAC;IACrF,CAAC;IACD,mBAAmB,GAAG,SAAS,CAAC;IAChC,cAAc,GAAG,KAAK,CAAC;IACvB,QAAQ,GAAG,SAAS,CAAC;IACrB,iBAAiB,GAAG,SAAS,CAAC;IAC9B,mBAAmB,GAAG,SAAS,CAAC;IAChC,iBAAiB,GAAG,SAAS,CAAC;IAC9B,iBAAiB,GAAG,SAAS,CAAC;IAC9B,oBAAoB,GAAG,SAAS,CAAC;IACjC,8BAA8B,GAAG,SAAS,CAAC;AAC7C,CAAC","sourcesContent":["import { Observable } from '@grafana/faro-core';\n\nexport const MESSAGE_TYPE_URL_CHANGE = 'url-change';\n\nexport type UrlChangeMessage = {\n type: typeof MESSAGE_TYPE_URL_CHANGE;\n from: string;\n to: string;\n trigger: 'pushState' | 'replaceState' | 'popstate' | 'hashchange' | 'navigate' | 'navigate-intercept';\n};\n\nlet urlChangeObservable: Observable<UrlChangeMessage> | undefined;\nlet isInstrumented = false;\nlet lastHref: string | undefined;\nlet originalPushState: typeof window.history.pushState | undefined;\nlet originalReplaceState: typeof window.history.replaceState | undefined;\nlet onPopStateHandler: ((this: Window, ev: PopStateEvent) => any) | undefined;\nlet onHashChangeHandler: ((this: Window, ev: HashChangeEvent) => any) | undefined;\nlet onNavigateHandler: ((this: any, ev: any) => any) | undefined;\nlet originalNavigateEventIntercept: (((this: any, options?: any) => any) & { _faroWrapped?: boolean }) | undefined;\n\nexport function monitorUrlChanges(): Observable<UrlChangeMessage> {\n if (!urlChangeObservable) {\n urlChangeObservable = new Observable<UrlChangeMessage>();\n lastHref = location.href;\n }\n\n function emit(trigger: UrlChangeMessage['trigger'], toOverride?: string) {\n const next = toOverride ?? location.href;\n if (next !== lastHref) {\n urlChangeObservable!.notify({ type: MESSAGE_TYPE_URL_CHANGE, from: lastHref!, to: next, trigger });\n lastHref = next;\n }\n }\n\n if (!isInstrumented) {\n const hasNavigation = 'navigation' in window && 'NavigateEvent' in (window as any);\n\n if (hasNavigation) {\n // Prefer Navigation API when supported: do not patch history or add popstate/hashchange listeners\n onNavigateHandler = (e: any) => {\n try {\n const destination = e?.destination as { url?: string; sameDocument?: boolean } | undefined;\n if (destination?.sameDocument && typeof destination.url === 'string') {\n emit('navigate', destination.url);\n }\n } catch (_err) {\n // Swallow to avoid impacting host app\n }\n };\n (window as any).navigation.addEventListener('navigate', onNavigateHandler as any);\n\n const NavigateEventConstructor = (window as any).NavigateEvent;\n if (\n NavigateEventConstructor &&\n NavigateEventConstructor.prototype &&\n typeof NavigateEventConstructor.prototype.intercept === 'function'\n ) {\n if (!originalNavigateEventIntercept) {\n originalNavigateEventIntercept = NavigateEventConstructor.prototype.intercept;\n }\n\n // Wrap intercept to detect soft navigations (cross-document turned same-document)\n NavigateEventConstructor.prototype.intercept = function (this: any, options?: any) {\n try {\n const canIntercept = !!this?.canIntercept;\n const destination = this?.destination as { url?: string; sameDocument?: boolean } | undefined;\n if (\n canIntercept &&\n destination &&\n destination.sameDocument === false &&\n typeof destination.url === 'string'\n ) {\n emit('navigate-intercept', destination.url);\n }\n } catch (_err) {\n // ignore\n }\n return originalNavigateEventIntercept!.call(this, options);\n } as typeof originalNavigateEventIntercept;\n }\n\n isInstrumented = true;\n } else {\n // Fallback: history API patching + popstate/hashchange\n if (!originalPushState) {\n originalPushState = window.history.pushState;\n }\n window.history.pushState = function (...args: Parameters<typeof window.history.pushState>) {\n const result = originalPushState!.apply(window.history, args as any);\n emit('pushState');\n return result;\n } as typeof window.history.pushState;\n\n if (!originalReplaceState) {\n originalReplaceState = window.history.replaceState;\n }\n window.history.replaceState = function (...args: Parameters<typeof window.history.replaceState>) {\n const result = originalReplaceState!.apply(window.history, args as any);\n emit('replaceState');\n return result;\n } as typeof window.history.replaceState;\n\n onPopStateHandler = () => emit('popstate');\n onHashChangeHandler = () => emit('hashchange');\n window.addEventListener('popstate', onPopStateHandler);\n window.addEventListener('hashchange', onHashChangeHandler);\n\n isInstrumented = true;\n }\n }\n\n return urlChangeObservable;\n}\n\n// Test-only utility to reset state between tests\nexport function __resetUrlChangeMonitorForTests() {\n if (onPopStateHandler) {\n window.removeEventListener('popstate', onPopStateHandler);\n }\n if (onHashChangeHandler) {\n window.removeEventListener('hashchange', onHashChangeHandler);\n }\n if (onNavigateHandler && (window as any).navigation?.removeEventListener) {\n (window as any).navigation.removeEventListener('navigate', onNavigateHandler as any);\n }\n if (originalPushState) {\n window.history.pushState = originalPushState;\n }\n if (originalReplaceState) {\n window.history.replaceState = originalReplaceState;\n }\n if (originalNavigateEventIntercept && (window as any).NavigateEvent?.prototype) {\n (window as any).NavigateEvent.prototype.intercept = originalNavigateEventIntercept;\n }\n urlChangeObservable = undefined;\n isInstrumented = false;\n lastHref = undefined;\n onPopStateHandler = undefined;\n onHashChangeHandler = undefined;\n onNavigateHandler = undefined;\n originalPushState = undefined;\n originalReplaceState = undefined;\n originalNavigateEventIntercept = undefined;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"urlChangeMonitor.js","sourceRoot":"","sources":["../../../../../src/instrumentations/_internal/monitors/urlChangeMonitor.ts"],"names":[],"mappings":";;;AAqBA,8CA4FC;AAGD,0EA4BC;AAhJD,kDAAgD;AAEnC,QAAA,uBAAuB,GAAG,YAAY,CAAC;AASpD,IAAI,mBAA6D,CAAC;AAClE,IAAI,cAAc,GAAG,KAAK,CAAC;AAC3B,IAAI,QAA4B,CAAC;AACjC,IAAI,iBAA8D,CAAC;AACnE,IAAI,oBAAoE,CAAC;AACzE,IAAI,iBAAyE,CAAC;AAC9E,IAAI,mBAA6E,CAAC;AAClF,IAAI,iBAA4D,CAAC;AACjE,IAAI,8BAA8G,CAAC;AAEnH,SAAgB,iBAAiB;IAC/B,IAAI,CAAC,mBAAmB,EAAE,CAAC;QACzB,mBAAmB,GAAG,IAAI,sBAAU,EAAoB,CAAC;QACzD,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3B,CAAC;IAED,SAAS,IAAI,CAAC,OAAoC,EAAE,UAAmB;QACrE,MAAM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,CAAA,EAAE,CAAC;QAC9E,MAAc,CAAC,aAAa,CAAC,SAAS,CAAC,SAAS,GAAG,8BAA8B,CAAC;IACrF,CAAC;IACD,mBAAmB,GAAG,SAAS,CAAC;IAChC,cAAc,GAAG,KAAK,CAAC;IACvB,QAAQ,GAAG,SAAS,CAAC;IACrB,iBAAiB,GAAG,SAAS,CAAC;IAC9B,mBAAmB,GAAG,SAAS,CAAC;IAChC,iBAAiB,GAAG,SAAS,CAAC;IAC9B,iBAAiB,GAAG,SAAS,CAAC;IAC9B,oBAAoB,GAAG,SAAS,CAAC;IACjC,8BAA8B,GAAG,SAAS,CAAC;AAC7C,CAAC","sourcesContent":["import { Observable } from '@grafana/faro-core';\n\nexport const MESSAGE_TYPE_URL_CHANGE = 'url-change';\n\nexport type UrlChangeMessage = {\n type: typeof MESSAGE_TYPE_URL_CHANGE;\n from: string;\n to: string;\n trigger: 'pushState' | 'replaceState' | 'popstate' | 'hashchange' | 'navigate' | 'navigate-intercept';\n};\n\nlet urlChangeObservable: Observable<UrlChangeMessage> | undefined;\nlet isInstrumented = false;\nlet lastHref: string | undefined;\nlet originalPushState: typeof window.history.pushState | undefined;\nlet originalReplaceState: typeof window.history.replaceState | undefined;\nlet onPopStateHandler: ((this: Window, ev: PopStateEvent) => any) | undefined;\nlet onHashChangeHandler: ((this: Window, ev: HashChangeEvent) => any) | undefined;\nlet onNavigateHandler: ((this: any, ev: any) => any) | undefined;\nlet originalNavigateEventIntercept: (((this: any, options?: any) => any) & { _faroWrapped?: boolean }) | undefined;\n\nexport function monitorUrlChanges(): Observable<UrlChangeMessage> {\n if (!urlChangeObservable) {\n urlChangeObservable = new Observable<UrlChangeMessage>();\n lastHref = location.href;\n }\n\n function emit(trigger: UrlChangeMessage['trigger'], toOverride?: string) {\n const next = toOverride ?? location.href;\n if (next !== lastHref) {\n urlChangeObservable!.notify({ type: MESSAGE_TYPE_URL_CHANGE, from: lastHref!, to: next, trigger });\n lastHref = next;\n }\n }\n\n if (!isInstrumented) {\n const hasNavigation = 'navigation' in window && 'NavigateEvent' in (window as any);\n\n if (hasNavigation) {\n // Prefer Navigation API when supported: do not patch history or add popstate/hashchange listeners\n onNavigateHandler = (e: any) => {\n try {\n const destination = e?.destination as { url?: string; sameDocument?: boolean } | undefined;\n if (destination?.sameDocument && typeof destination.url === 'string') {\n emit('navigate', destination.url);\n }\n } catch (_err) {\n // Swallow to avoid impacting host app\n }\n };\n (window as any).navigation.addEventListener('navigate', onNavigateHandler as any);\n\n const NavigateEventConstructor = (window as any).NavigateEvent;\n if (\n NavigateEventConstructor &&\n NavigateEventConstructor.prototype &&\n typeof NavigateEventConstructor.prototype.intercept === 'function'\n ) {\n if (!originalNavigateEventIntercept) {\n originalNavigateEventIntercept = NavigateEventConstructor.prototype.intercept;\n }\n\n // Wrap intercept to detect soft navigations (cross-document turned same-document)\n NavigateEventConstructor.prototype.intercept = function (this: any, options?: any) {\n try {\n const canIntercept = !!this?.canIntercept;\n const destination = this?.destination as { url?: string; sameDocument?: boolean } | undefined;\n if (\n canIntercept &&\n destination &&\n destination.sameDocument === false &&\n typeof destination.url === 'string'\n ) {\n emit('navigate-intercept', destination.url);\n }\n } catch (_err) {\n // ignore\n }\n return originalNavigateEventIntercept!.call(this, options);\n } as typeof originalNavigateEventIntercept;\n }\n\n isInstrumented = true;\n } else {\n // Fallback: history API patching + popstate/hashchange\n if (!originalPushState) {\n originalPushState = window.history.pushState;\n }\n window.history.pushState = function (...args: Parameters<typeof window.history.pushState>) {\n const result = originalPushState!.apply(window.history, args as any);\n emit('pushState');\n return result;\n } as typeof window.history.pushState;\n\n if (!originalReplaceState) {\n originalReplaceState = window.history.replaceState;\n }\n window.history.replaceState = function (...args: Parameters<typeof window.history.replaceState>) {\n const result = originalReplaceState!.apply(window.history, args as any);\n emit('replaceState');\n return result;\n } as typeof window.history.replaceState;\n\n onPopStateHandler = () => emit('popstate');\n onHashChangeHandler = () => emit('hashchange');\n window.addEventListener('popstate', onPopStateHandler);\n window.addEventListener('hashchange', onHashChangeHandler);\n\n isInstrumented = true;\n }\n }\n\n return urlChangeObservable;\n}\n\n// Test-only utility to reset state between tests\nexport function __resetUrlChangeMonitorForTests() {\n if (onPopStateHandler) {\n window.removeEventListener('popstate', onPopStateHandler);\n }\n if (onHashChangeHandler) {\n window.removeEventListener('hashchange', onHashChangeHandler);\n }\n if (onNavigateHandler && (window as any).navigation?.removeEventListener) {\n (window as any).navigation.removeEventListener('navigate', onNavigateHandler as any);\n }\n if (originalPushState) {\n window.history.pushState = originalPushState;\n }\n if (originalReplaceState) {\n window.history.replaceState = originalReplaceState;\n }\n if (originalNavigateEventIntercept && (window as any).NavigateEvent?.prototype) {\n (window as any).NavigateEvent.prototype.intercept = originalNavigateEventIntercept;\n }\n urlChangeObservable = undefined;\n isInstrumented = false;\n lastHref = undefined;\n onPopStateHandler = undefined;\n onHashChangeHandler = undefined;\n onNavigateHandler = undefined;\n originalPushState = undefined;\n originalReplaceState = undefined;\n originalNavigateEventIntercept = undefined;\n}\n"]}
|
|
@@ -1,64 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.ConsoleInstrumentation = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_this.errorSerializer = faro_core_1.defaultLogArgsSerializer;
|
|
29
|
-
return _this;
|
|
4
|
+
const faro_core_1 = require("@grafana/faro-core");
|
|
5
|
+
const consoleMonitor_1 = require("../_internal/monitors/consoleMonitor");
|
|
6
|
+
const getErrorDetails_1 = require("../errors/getErrorDetails");
|
|
7
|
+
class ConsoleInstrumentation extends faro_core_1.BaseInstrumentation {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = '@grafana/faro-web-sdk:instrumentation-console';
|
|
11
|
+
this.version = faro_core_1.VERSION;
|
|
12
|
+
this.errorSerializer = faro_core_1.defaultLogArgsSerializer;
|
|
30
13
|
}
|
|
31
|
-
|
|
32
|
-
var _this = this;
|
|
14
|
+
initialize() {
|
|
33
15
|
var _a, _b;
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
const instrumentationOptions = this.config.consoleInstrumentation;
|
|
17
|
+
const serializeErrors = (instrumentationOptions === null || instrumentationOptions === void 0 ? void 0 : instrumentationOptions.serializeErrors) || !!(instrumentationOptions === null || instrumentationOptions === void 0 ? void 0 : instrumentationOptions.errorSerializer);
|
|
36
18
|
this.errorSerializer = serializeErrors
|
|
37
19
|
? ((_a = instrumentationOptions === null || instrumentationOptions === void 0 ? void 0 : instrumentationOptions.errorSerializer) !== null && _a !== void 0 ? _a : faro_core_1.defaultErrorArgsSerializer)
|
|
38
20
|
: faro_core_1.defaultLogArgsSerializer;
|
|
39
|
-
|
|
21
|
+
const disabledLevels = (_b = instrumentationOptions === null || instrumentationOptions === void 0 ? void 0 : instrumentationOptions.disabledLevels) !== null && _b !== void 0 ? _b : ConsoleInstrumentation.defaultDisabledLevels;
|
|
40
22
|
// Pass unpatchedConsole to the monitor (only first caller's value is used)
|
|
41
|
-
|
|
23
|
+
const consoleMonitor = (0, consoleMonitor_1.monitorConsole)(this.unpatchedConsole);
|
|
42
24
|
// Subscribe this Faro instance to console events
|
|
43
|
-
this.subscription = consoleMonitor.subscribe(
|
|
44
|
-
var level = _a.level, args = _a.args;
|
|
25
|
+
this.subscription = consoleMonitor.subscribe(({ level, args }) => {
|
|
45
26
|
// Skip if this level is disabled for this instance
|
|
46
27
|
if (disabledLevels.includes(level)) {
|
|
47
28
|
return;
|
|
48
29
|
}
|
|
49
30
|
try {
|
|
50
31
|
if (level === faro_core_1.LogLevel.ERROR && !(instrumentationOptions === null || instrumentationOptions === void 0 ? void 0 : instrumentationOptions.consoleErrorAsLog)) {
|
|
51
|
-
|
|
32
|
+
const { value, type, stackFrames } = (0, getErrorDetails_1.getDetailsFromConsoleErrorArgs)(args, this.errorSerializer);
|
|
52
33
|
if (value && !type && !stackFrames) {
|
|
53
|
-
|
|
34
|
+
this.api.pushError(new Error(ConsoleInstrumentation.consoleErrorPrefix + value));
|
|
54
35
|
return;
|
|
55
36
|
}
|
|
56
|
-
|
|
37
|
+
this.api.pushError(new Error(ConsoleInstrumentation.consoleErrorPrefix + value), { type, stackFrames });
|
|
57
38
|
}
|
|
58
39
|
else if (level === faro_core_1.LogLevel.ERROR && (instrumentationOptions === null || instrumentationOptions === void 0 ? void 0 : instrumentationOptions.consoleErrorAsLog)) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
level
|
|
40
|
+
const { value, type, stackFrames } = (0, getErrorDetails_1.getDetailsFromConsoleErrorArgs)(args, this.errorSerializer);
|
|
41
|
+
this.api.pushLog(value ? [ConsoleInstrumentation.consoleErrorPrefix + value] : args, {
|
|
42
|
+
level,
|
|
62
43
|
context: {
|
|
63
44
|
value: value !== null && value !== void 0 ? value : '',
|
|
64
45
|
type: type !== null && type !== void 0 ? type : '',
|
|
@@ -67,23 +48,22 @@ var ConsoleInstrumentation = /** @class */ (function (_super) {
|
|
|
67
48
|
});
|
|
68
49
|
}
|
|
69
50
|
else {
|
|
70
|
-
|
|
51
|
+
this.api.pushLog(args, { level });
|
|
71
52
|
}
|
|
72
53
|
}
|
|
73
54
|
catch (err) {
|
|
74
|
-
|
|
55
|
+
this.logError(err);
|
|
75
56
|
}
|
|
76
57
|
});
|
|
77
|
-
}
|
|
58
|
+
}
|
|
78
59
|
// Clean up subscription when instrumentation is destroyed
|
|
79
|
-
|
|
60
|
+
destroy() {
|
|
80
61
|
var _a;
|
|
81
62
|
(_a = this.subscription) === null || _a === void 0 ? void 0 : _a.unsubscribe();
|
|
82
63
|
this.subscription = undefined;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
ConsoleInstrumentation.consoleErrorPrefix = 'console.error: ';
|
|
86
|
-
return ConsoleInstrumentation;
|
|
87
|
-
}(faro_core_1.BaseInstrumentation));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
88
66
|
exports.ConsoleInstrumentation = ConsoleInstrumentation;
|
|
67
|
+
ConsoleInstrumentation.defaultDisabledLevels = [faro_core_1.LogLevel.DEBUG, faro_core_1.LogLevel.TRACE, faro_core_1.LogLevel.LOG];
|
|
68
|
+
ConsoleInstrumentation.consoleErrorPrefix = 'console.error: ';
|
|
89
69
|
//# sourceMappingURL=instrumentation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/console/instrumentation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../../src/instrumentations/console/instrumentation.ts"],"names":[],"mappings":";;;AAAA,kDAM4B;AAG5B,yEAAsE;AACtE,+DAA2E;AAE3E,MAAa,sBAAuB,SAAQ,+BAAmB;IAA/D;;QACW,SAAI,GAAG,+CAA+C,CAAC;QACvD,YAAO,GAAG,mBAAO,CAAC;QAKnB,oBAAe,GAAsB,oCAAwB,CAAC;IA0DxE,CAAC;IAvDC,UAAU;;QACR,M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AED,0DAA0D;IAC1D,OAAO;;QACL,MAAA,IAAI,CAAC,YAAY,0CAAE,WAAW,EAAE,CAAC;QACjC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;IAChC,CAAC;;AAhEH,wDAiEC;AA7DQ,4CAAqB,GAAe,CAAC,oBAAQ,CAAC,KAAK,EAAE,oBAAQ,CAAC,KAAK,EAAE,oBAAQ,CAAC,GAAG,CAAC,AAA7D,CAA8D;AACnF,yCAAkB,GAAG,iBAAiB,AAApB,CAAqB","sourcesContent":["import {\n BaseInstrumentation,\n defaultErrorArgsSerializer,\n defaultLogArgsSerializer,\n LogLevel,\n VERSION,\n} from '@grafana/faro-core';\nimport type { LogArgsSerializer, Subscription } from '@grafana/faro-core';\n\nimport { monitorConsole } from '../_internal/monitors/consoleMonitor';\nimport { getDetailsFromConsoleErrorArgs } from '../errors/getErrorDetails';\n\nexport class ConsoleInstrumentation extends BaseInstrumentation {\n readonly name = '@grafana/faro-web-sdk:instrumentation-console';\n readonly version = VERSION;\n\n static defaultDisabledLevels: LogLevel[] = [LogLevel.DEBUG, LogLevel.TRACE, LogLevel.LOG];\n static consoleErrorPrefix = 'console.error: ';\n\n private errorSerializer: LogArgsSerializer = defaultLogArgsSerializer;\n private subscription: Subscription | undefined;\n\n initialize() {\n const instrumentationOptions = this.config.consoleInstrumentation;\n\n const serializeErrors = instrumentationOptions?.serializeErrors || !!instrumentationOptions?.errorSerializer;\n this.errorSerializer = serializeErrors\n ? (instrumentationOptions?.errorSerializer ?? defaultErrorArgsSerializer)\n : defaultLogArgsSerializer;\n\n const disabledLevels = instrumentationOptions?.disabledLevels ?? ConsoleInstrumentation.defaultDisabledLevels;\n\n // Pass unpatchedConsole to the monitor (only first caller's value is used)\n const consoleMonitor = monitorConsole(this.unpatchedConsole);\n\n // Subscribe this Faro instance to console events\n this.subscription = consoleMonitor.subscribe(({ level, args }) => {\n // Skip if this level is disabled for this instance\n if (disabledLevels.includes(level)) {\n return;\n }\n\n try {\n if (level === LogLevel.ERROR && !instrumentationOptions?.consoleErrorAsLog) {\n const { value, type, stackFrames } = getDetailsFromConsoleErrorArgs(args, this.errorSerializer);\n\n if (value && !type && !stackFrames) {\n this.api.pushError(new Error(ConsoleInstrumentation.consoleErrorPrefix + value));\n return;\n }\n\n this.api.pushError(new Error(ConsoleInstrumentation.consoleErrorPrefix + value), { type, stackFrames });\n } else if (level === LogLevel.ERROR && instrumentationOptions?.consoleErrorAsLog) {\n const { value, type, stackFrames } = getDetailsFromConsoleErrorArgs(args, this.errorSerializer);\n\n this.api.pushLog(value ? [ConsoleInstrumentation.consoleErrorPrefix + value] : args, {\n level,\n context: {\n value: value ?? '',\n type: type ?? '',\n stackFrames: stackFrames?.length ? defaultErrorArgsSerializer(stackFrames) : '',\n },\n });\n } else {\n this.api.pushLog(args, { level });\n }\n } catch (err) {\n this.logError(err);\n }\n });\n }\n\n // Clean up subscription when instrumentation is destroyed\n destroy() {\n this.subscription?.unsubscribe();\n this.subscription = undefined;\n }\n}\n"]}
|