posthog-js 1.76.0 → 1.77.1
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/array.full.js +2 -2
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +2 -2
- package/dist/array.js.map +1 -1
- package/dist/es.js +2 -2
- package/dist/es.js.map +1 -1
- package/dist/module.d.ts +38 -6
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/lib/package.json +8 -6
- package/lib/src/autocapture-utils.d.ts +15 -0
- package/lib/src/autocapture-utils.js +303 -0
- package/lib/src/autocapture-utils.js.map +1 -0
- package/lib/src/autocapture.d.ts +27 -0
- package/lib/src/autocapture.js +290 -0
- package/lib/src/autocapture.js.map +1 -0
- package/lib/src/base-request-queue.d.ts +12 -0
- package/lib/src/base-request-queue.js +33 -0
- package/lib/src/base-request-queue.js.map +1 -0
- package/lib/src/compression.d.ts +3 -0
- package/lib/src/compression.js +35 -0
- package/lib/src/compression.js.map +1 -0
- package/lib/src/config.d.ts +5 -0
- package/lib/src/config.js +9 -0
- package/lib/src/config.js.map +1 -0
- package/lib/src/constants.d.ts +19 -0
- package/lib/src/constants.js +41 -0
- package/lib/src/constants.js.map +1 -0
- package/lib/src/decide.d.ts +8 -0
- package/lib/src/decide.js +118 -0
- package/lib/src/decide.js.map +1 -0
- package/lib/src/extensions/cloud.d.ts +1 -0
- package/lib/src/extensions/cloud.js +2 -0
- package/lib/src/extensions/cloud.js.map +1 -0
- package/lib/src/extensions/exceptions/error-conversion.d.ts +26 -0
- package/lib/src/extensions/exceptions/error-conversion.js +204 -0
- package/lib/src/extensions/exceptions/error-conversion.js.map +1 -0
- package/lib/src/extensions/exceptions/exception-autocapture.d.ts +24 -0
- package/lib/src/extensions/exceptions/exception-autocapture.js +164 -0
- package/lib/src/extensions/exceptions/exception-autocapture.js.map +1 -0
- package/lib/src/extensions/exceptions/stack-trace.d.ts +31 -0
- package/lib/src/extensions/exceptions/stack-trace.js +259 -0
- package/lib/src/extensions/exceptions/stack-trace.js.map +1 -0
- package/lib/src/extensions/exceptions/type-checking.d.ts +10 -0
- package/lib/src/extensions/exceptions/type-checking.js +43 -0
- package/lib/src/extensions/exceptions/type-checking.js.map +1 -0
- package/lib/src/extensions/rageclick.d.ts +10 -0
- package/lib/src/extensions/rageclick.js +33 -0
- package/lib/src/extensions/rageclick.js.map +1 -0
- package/lib/src/extensions/segment-integration.d.ts +44 -0
- package/lib/src/extensions/segment-integration.js +34 -0
- package/lib/src/extensions/segment-integration.js.map +1 -0
- package/lib/src/extensions/sentry-integration.d.ts +30 -0
- package/lib/src/extensions/sentry-integration.js +63 -0
- package/lib/src/extensions/sentry-integration.js.map +1 -0
- package/lib/src/extensions/sessionrecording-utils.d.ts +67 -0
- package/lib/src/extensions/sessionrecording-utils.js +192 -0
- package/lib/src/extensions/sessionrecording-utils.js.map +1 -0
- package/lib/src/extensions/sessionrecording.d.ts +45 -0
- package/lib/src/extensions/sessionrecording.js +430 -0
- package/lib/src/extensions/sessionrecording.js.map +1 -0
- package/lib/src/extensions/toolbar.d.ts +18 -0
- package/lib/src/extensions/toolbar.js +151 -0
- package/lib/src/extensions/toolbar.js.map +1 -0
- package/lib/src/extensions/web-performance.d.ts +20 -0
- package/lib/src/extensions/web-performance.js +245 -0
- package/lib/src/extensions/web-performance.js.map +1 -0
- package/lib/src/gdpr-utils.d.ts +80 -0
- package/lib/src/gdpr-utils.js +236 -0
- package/lib/src/gdpr-utils.js.map +1 -0
- package/lib/src/loader-globals-full.d.ts +1 -0
- package/lib/src/loader-globals-full.js +5 -0
- package/lib/src/loader-globals-full.js.map +1 -0
- package/lib/src/loader-globals.d.ts +1 -0
- package/lib/src/loader-globals.js +3 -0
- package/lib/src/loader-globals.js.map +1 -0
- package/lib/src/loader-module.d.ts +4 -0
- package/lib/src/loader-module.js +6 -0
- package/lib/src/loader-module.js.map +1 -0
- package/lib/src/loader-recorder-v2.d.ts +2 -0
- package/lib/src/loader-recorder-v2.js +15 -0
- package/lib/src/loader-recorder-v2.js.map +1 -0
- package/lib/src/loader-recorder.d.ts +2 -0
- package/lib/src/loader-recorder.js +15 -0
- package/lib/src/loader-recorder.js.map +1 -0
- package/lib/src/page-view.d.ts +38 -0
- package/lib/src/page-view.js +127 -0
- package/lib/src/page-view.js.map +1 -0
- package/lib/src/posthog-core.d.ts +701 -0
- package/lib/src/posthog-core.js +1916 -0
- package/lib/src/posthog-core.js.map +1 -0
- package/lib/src/posthog-featureflags.d.ts +70 -0
- package/lib/src/posthog-featureflags.js +438 -0
- package/lib/src/posthog-featureflags.js.map +1 -0
- package/lib/src/posthog-persistence.d.ts +57 -0
- package/lib/src/posthog-persistence.js +256 -0
- package/lib/src/posthog-persistence.js.map +1 -0
- package/lib/src/posthog-surveys.d.ts +57 -0
- package/lib/src/posthog-surveys.js +76 -0
- package/lib/src/posthog-surveys.js.map +1 -0
- package/lib/src/rate-limiter.d.ts +5 -0
- package/lib/src/rate-limiter.js +66 -0
- package/lib/src/rate-limiter.js.map +1 -0
- package/lib/src/request-queue.d.ts +10 -0
- package/lib/src/request-queue.js +146 -0
- package/lib/src/request-queue.js.map +1 -0
- package/lib/src/retry-queue.d.ts +28 -0
- package/lib/src/retry-queue.js +198 -0
- package/lib/src/retry-queue.js.map +1 -0
- package/lib/src/send-request.d.ts +6 -0
- package/lib/src/send-request.js +125 -0
- package/lib/src/send-request.js.map +1 -0
- package/lib/src/sessionid.d.ts +28 -0
- package/lib/src/sessionid.js +205 -0
- package/lib/src/sessionid.js.map +1 -0
- package/lib/src/storage.d.ts +7 -0
- package/lib/src/storage.js +291 -0
- package/lib/src/storage.js.map +1 -0
- package/lib/src/types.d.ts +294 -0
- package/lib/src/types.js +6 -0
- package/lib/src/types.js.map +1 -0
- package/lib/src/utils.d.ts +89 -0
- package/lib/src/utils.js +868 -0
- package/lib/src/utils.js.map +1 -0
- package/lib/src/uuidv7.d.ts +42 -0
- package/lib/src/uuidv7.js +228 -0
- package/lib/src/uuidv7.js.map +1 -0
- package/package.json +8 -6
- package/CHANGELOG.md +0 -1145
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
var __values = (this && this.__values) || function(o) {
|
|
2
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
3
|
+
if (m) return m.call(o);
|
|
4
|
+
if (o && typeof o.length === "number") return {
|
|
5
|
+
next: function () {
|
|
6
|
+
if (o && i >= o.length) o = void 0;
|
|
7
|
+
return { value: o && o[i++], done: !o };
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
11
|
+
};
|
|
12
|
+
import { autocapture } from './autocapture';
|
|
13
|
+
import { _base64Encode, loadScript } from './utils';
|
|
14
|
+
import { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants';
|
|
15
|
+
var Decide = /** @class */ (function () {
|
|
16
|
+
function Decide(instance) {
|
|
17
|
+
this.instance = instance;
|
|
18
|
+
// don't need to wait for `decide` to return if flags were provided on initialisation
|
|
19
|
+
this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags();
|
|
20
|
+
}
|
|
21
|
+
Decide.prototype.call = function () {
|
|
22
|
+
var _this = this;
|
|
23
|
+
/*
|
|
24
|
+
Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.
|
|
25
|
+
*/
|
|
26
|
+
var json_data = JSON.stringify({
|
|
27
|
+
token: this.instance.get_config('token'),
|
|
28
|
+
distinct_id: this.instance.get_distinct_id(),
|
|
29
|
+
groups: this.instance.getGroups(),
|
|
30
|
+
person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),
|
|
31
|
+
group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),
|
|
32
|
+
disable_flags: this.instance.get_config('advanced_disable_feature_flags') ||
|
|
33
|
+
this.instance.get_config('advanced_disable_feature_flags_on_first_load') ||
|
|
34
|
+
undefined,
|
|
35
|
+
});
|
|
36
|
+
var encoded_data = _base64Encode(json_data);
|
|
37
|
+
this.instance._send_request("".concat(this.instance.get_config('api_host'), "/decide/?v=3"), { data: encoded_data, verbose: true }, { method: 'POST' }, function (response) { return _this.parseDecideResponse(response); });
|
|
38
|
+
};
|
|
39
|
+
Decide.prototype.parseDecideResponse = function (response) {
|
|
40
|
+
var e_1, _a, e_2, _b;
|
|
41
|
+
var _this = this;
|
|
42
|
+
var _c, _d, _e;
|
|
43
|
+
if ((response === null || response === void 0 ? void 0 : response.status) === 0) {
|
|
44
|
+
console.error('Failed to fetch feature flags from PostHog.');
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!(document && document.body)) {
|
|
48
|
+
console.log('document not ready yet, trying again in 500 milliseconds...');
|
|
49
|
+
setTimeout(function () {
|
|
50
|
+
_this.parseDecideResponse(response);
|
|
51
|
+
}, 500);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
this.instance.toolbar.afterDecideResponse(response);
|
|
55
|
+
(_c = this.instance.sessionRecording) === null || _c === void 0 ? void 0 : _c.afterDecideResponse(response);
|
|
56
|
+
autocapture.afterDecideResponse(response, this.instance);
|
|
57
|
+
(_d = this.instance.webPerformance) === null || _d === void 0 ? void 0 : _d.afterDecideResponse(response);
|
|
58
|
+
(_e = this.instance.exceptionAutocapture) === null || _e === void 0 ? void 0 : _e.afterDecideResponse(response);
|
|
59
|
+
if (!this.instance.get_config('advanced_disable_feature_flags_on_first_load')) {
|
|
60
|
+
this.instance.featureFlags.receivedFeatureFlags(response);
|
|
61
|
+
}
|
|
62
|
+
this.instance['compression'] = {};
|
|
63
|
+
if (response['supportedCompression'] && !this.instance.get_config('disable_compression')) {
|
|
64
|
+
var compression = {};
|
|
65
|
+
try {
|
|
66
|
+
for (var _f = __values(response['supportedCompression']), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
67
|
+
var method = _g.value;
|
|
68
|
+
compression[method] = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
72
|
+
finally {
|
|
73
|
+
try {
|
|
74
|
+
if (_g && !_g.done && (_a = _f.return)) _a.call(_f);
|
|
75
|
+
}
|
|
76
|
+
finally { if (e_1) throw e_1.error; }
|
|
77
|
+
}
|
|
78
|
+
this.instance['compression'] = compression;
|
|
79
|
+
}
|
|
80
|
+
if (response['siteApps']) {
|
|
81
|
+
if (this.instance.get_config('opt_in_site_apps')) {
|
|
82
|
+
var apiHost = this.instance.get_config('api_host');
|
|
83
|
+
var _loop_1 = function (id, url) {
|
|
84
|
+
var scriptUrl = [
|
|
85
|
+
apiHost,
|
|
86
|
+
apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,
|
|
87
|
+
].join('');
|
|
88
|
+
window["__$$ph_site_app_".concat(id)] = this_1.instance;
|
|
89
|
+
loadScript(scriptUrl, function (err) {
|
|
90
|
+
if (err) {
|
|
91
|
+
console.error("Error while initializing PostHog app with config id ".concat(id), err);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
};
|
|
95
|
+
var this_1 = this;
|
|
96
|
+
try {
|
|
97
|
+
for (var _h = __values(response['siteApps']), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
98
|
+
var _k = _j.value, id = _k.id, url = _k.url;
|
|
99
|
+
_loop_1(id, url);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
103
|
+
finally {
|
|
104
|
+
try {
|
|
105
|
+
if (_j && !_j.done && (_b = _h.return)) _b.call(_h);
|
|
106
|
+
}
|
|
107
|
+
finally { if (e_2) throw e_2.error; }
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
else if (response['siteApps'].length > 0) {
|
|
111
|
+
console.error('PostHog site apps are disabled. Enable the "opt_in_site_apps" config to proceed.');
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115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AC,CAAA;;;;oBAZN,KAA0B,IAAA,KAAA,SAAA,QAAQ,CAAC,UAAU,CAAC,CAAA,gBAAA;wBAAnC,IAAA,aAAW,EAAT,EAAE,QAAA,EAAE,GAAG,SAAA;gCAAP,EAAE,EAAE,GAAG;qBAanB;;;;;;;;;aACJ;iBAAM,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;gBACxC,OAAO,CAAC,KAAK,CAAC,kFAAkF,CAAC,CAAA;aACpG;SACJ;IACL,CAAC;IACL,aAAC;AAAD,CAAC,AAxFD,IAwFC","sourcesContent":["import { autocapture } from './autocapture'\nimport { _base64Encode, loadScript } from './utils'\nimport { PostHog } from './posthog-core'\nimport { Compression, DecideResponse } from './types'\nimport { STORED_GROUP_PROPERTIES_KEY, STORED_PERSON_PROPERTIES_KEY } from './constants'\n\nexport class Decide {\n instance: PostHog\n\n constructor(instance: PostHog) {\n this.instance = instance\n // don't need to wait for `decide` to return if flags were provided on initialisation\n this.instance.decideEndpointWasHit = this.instance._hasBootstrappedFeatureFlags()\n }\n\n call(): void {\n /*\n Calls /decide endpoint to fetch options for autocapture, session recording, feature flags & compression.\n */\n const json_data = JSON.stringify({\n token: this.instance.get_config('token'),\n distinct_id: this.instance.get_distinct_id(),\n groups: this.instance.getGroups(),\n person_properties: this.instance.get_property(STORED_PERSON_PROPERTIES_KEY),\n group_properties: this.instance.get_property(STORED_GROUP_PROPERTIES_KEY),\n disable_flags:\n this.instance.get_config('advanced_disable_feature_flags') ||\n this.instance.get_config('advanced_disable_feature_flags_on_first_load') ||\n undefined,\n })\n\n const encoded_data = _base64Encode(json_data)\n this.instance._send_request(\n `${this.instance.get_config('api_host')}/decide/?v=3`,\n { data: encoded_data, verbose: true },\n { method: 'POST' },\n (response) => this.parseDecideResponse(response as DecideResponse)\n )\n }\n\n parseDecideResponse(response: DecideResponse): void {\n if (response?.status === 0) {\n console.error('Failed to fetch feature flags from PostHog.')\n return\n }\n if (!(document && document.body)) {\n console.log('document not ready yet, trying again in 500 milliseconds...')\n setTimeout(() => {\n this.parseDecideResponse(response)\n }, 500)\n return\n }\n\n this.instance.toolbar.afterDecideResponse(response)\n this.instance.sessionRecording?.afterDecideResponse(response)\n autocapture.afterDecideResponse(response, this.instance)\n this.instance.webPerformance?.afterDecideResponse(response)\n this.instance.exceptionAutocapture?.afterDecideResponse(response)\n\n if (!this.instance.get_config('advanced_disable_feature_flags_on_first_load')) {\n this.instance.featureFlags.receivedFeatureFlags(response)\n }\n\n this.instance['compression'] = {}\n if (response['supportedCompression'] && !this.instance.get_config('disable_compression')) {\n const compression: Partial<Record<Compression, boolean>> = {}\n for (const method of response['supportedCompression']) {\n compression[method] = true\n }\n this.instance['compression'] = compression\n }\n\n if (response['siteApps']) {\n if (this.instance.get_config('opt_in_site_apps')) {\n const apiHost = this.instance.get_config('api_host')\n for (const { id, url } of response['siteApps']) {\n const scriptUrl = [\n apiHost,\n apiHost[apiHost.length - 1] === '/' && url[0] === '/' ? url.substring(1) : url,\n ].join('')\n\n ;(window as any)[`__$$ph_site_app_${id}`] = this.instance\n\n loadScript(scriptUrl, (err) => {\n if (err) {\n console.error(`Error while initializing PostHog app with config id ${id}`, err)\n }\n })\n }\n } else if (response['siteApps'].length > 0) {\n console.error('PostHog site apps are disabled. Enable the \"opt_in_site_apps\" config to proceed.')\n }\n }\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const POSTHOG_MANAGED_HOSTS: string[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cloud.js","sourceRoot":"","sources":["../../../src/extensions/cloud.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,qBAAqB,GAAG,CAAC,yBAAyB,EAAE,wBAAwB,CAAC,CAAA","sourcesContent":["export const POSTHOG_MANAGED_HOSTS = ['https://app.posthog.com', 'https://eu.posthog.com']\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { StackFrame } from './stack-trace';
|
|
2
|
+
export declare type ErrorEventArgs = [
|
|
3
|
+
event: string | Event,
|
|
4
|
+
source?: string | undefined,
|
|
5
|
+
lineno?: number | undefined,
|
|
6
|
+
colno?: number | undefined,
|
|
7
|
+
error?: Error | undefined
|
|
8
|
+
];
|
|
9
|
+
export interface ErrorProperties {
|
|
10
|
+
$exception_type: string;
|
|
11
|
+
$exception_message: string;
|
|
12
|
+
$exception_source?: string;
|
|
13
|
+
$exception_lineno?: number;
|
|
14
|
+
$exception_colno?: number;
|
|
15
|
+
$exception_DOMException_code?: string;
|
|
16
|
+
$exception_is_synthetic?: boolean;
|
|
17
|
+
$exception_stack_trace_raw?: string;
|
|
18
|
+
$exception_handled?: boolean;
|
|
19
|
+
$exception_personURL?: string;
|
|
20
|
+
}
|
|
21
|
+
export declare function parseStackFrames(ex: Error & {
|
|
22
|
+
framesToPop?: number;
|
|
23
|
+
stacktrace?: string;
|
|
24
|
+
}): StackFrame[];
|
|
25
|
+
export declare function errorToProperties([event, source, lineno, colno, error]: ErrorEventArgs): ErrorProperties;
|
|
26
|
+
export declare function unhandledRejectionToProperties([ev]: [ev: PromiseRejectionEvent]): ErrorProperties;
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
import { isDOMError, isDOMException, isError, isErrorEvent, isErrorWithStack, isEvent, isPlainObject, isPrimitive, } from './type-checking';
|
|
29
|
+
import { defaultStackParser } from './stack-trace';
|
|
30
|
+
/**
|
|
31
|
+
* based on the very wonderful MIT licensed Sentry SDK
|
|
32
|
+
*/
|
|
33
|
+
var ERROR_TYPES_PATTERN = /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i;
|
|
34
|
+
var reactMinifiedRegexp = /Minified React error #\d+;/i;
|
|
35
|
+
function getPopSize(ex) {
|
|
36
|
+
if (ex) {
|
|
37
|
+
if (typeof ex.framesToPop === 'number') {
|
|
38
|
+
return ex.framesToPop;
|
|
39
|
+
}
|
|
40
|
+
if (reactMinifiedRegexp.test(ex.message)) {
|
|
41
|
+
return 1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
export function parseStackFrames(ex) {
|
|
47
|
+
// Access and store the stacktrace property before doing ANYTHING
|
|
48
|
+
// else to it because Opera is not very good at providing it
|
|
49
|
+
// reliably in other circumstances.
|
|
50
|
+
var stacktrace = ex.stacktrace || ex.stack || '';
|
|
51
|
+
var popSize = getPopSize(ex);
|
|
52
|
+
try {
|
|
53
|
+
return defaultStackParser(stacktrace, popSize);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
// no-empty
|
|
57
|
+
}
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
function errorPropertiesFromError(error) {
|
|
61
|
+
var frames = parseStackFrames(error);
|
|
62
|
+
return {
|
|
63
|
+
$exception_type: error.name,
|
|
64
|
+
$exception_message: error.message,
|
|
65
|
+
$exception_stack_trace_raw: JSON.stringify(frames),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function errorPropertiesFromString(candidate) {
|
|
69
|
+
return {
|
|
70
|
+
$exception_type: 'Error',
|
|
71
|
+
$exception_message: candidate,
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Given any captured exception, extract its keys and create a sorted
|
|
76
|
+
* and truncated list that will be used inside the event message.
|
|
77
|
+
* eg. `Non-error exception captured with keys: foo, bar, baz`
|
|
78
|
+
*/
|
|
79
|
+
function extractExceptionKeysForMessage(exception, maxLength) {
|
|
80
|
+
if (maxLength === void 0) { maxLength = 40; }
|
|
81
|
+
var keys = Object.keys(exception);
|
|
82
|
+
keys.sort();
|
|
83
|
+
if (!keys.length) {
|
|
84
|
+
return '[object has no keys]';
|
|
85
|
+
}
|
|
86
|
+
for (var i = keys.length; i > 0; i--) {
|
|
87
|
+
var serialized = keys.slice(0, i).join(', ');
|
|
88
|
+
if (serialized.length > maxLength) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
if (i === keys.length) {
|
|
92
|
+
return serialized;
|
|
93
|
+
}
|
|
94
|
+
return serialized.length <= maxLength ? serialized : "".concat(serialized.slice(0, maxLength), "...");
|
|
95
|
+
}
|
|
96
|
+
return '';
|
|
97
|
+
}
|
|
98
|
+
function errorPropertiesFromObject(candidate) {
|
|
99
|
+
return {
|
|
100
|
+
$exception_type: isEvent(candidate) ? candidate.constructor.name : 'Error',
|
|
101
|
+
$exception_message: "Non-Error ".concat('exception', " captured with keys: ").concat(extractExceptionKeysForMessage(candidate)),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
export function errorToProperties(_a) {
|
|
105
|
+
var _b = __read(_a, 5), event = _b[0], source = _b[1], lineno = _b[2], colno = _b[3], error = _b[4];
|
|
106
|
+
// exception type and message are not optional but, it's useful to start off without them enforced
|
|
107
|
+
var errorProperties = {};
|
|
108
|
+
if (error === undefined && typeof event === 'string') {
|
|
109
|
+
var name_1 = 'Error';
|
|
110
|
+
var message = event;
|
|
111
|
+
var groups = event.match(ERROR_TYPES_PATTERN);
|
|
112
|
+
if (groups) {
|
|
113
|
+
name_1 = groups[1];
|
|
114
|
+
message = groups[2];
|
|
115
|
+
}
|
|
116
|
+
errorProperties = {
|
|
117
|
+
$exception_type: name_1,
|
|
118
|
+
$exception_message: message,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
var candidate = error || event;
|
|
122
|
+
if (isDOMError(candidate) || isDOMException(candidate)) {
|
|
123
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/DOMError
|
|
124
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/DOMException
|
|
125
|
+
var domException = candidate;
|
|
126
|
+
if (isErrorWithStack(candidate)) {
|
|
127
|
+
errorProperties = errorPropertiesFromError(candidate);
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
var name_2 = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException');
|
|
131
|
+
var message = domException.message ? "".concat(name_2, ": ").concat(domException.message) : name_2;
|
|
132
|
+
errorProperties = errorPropertiesFromString(message);
|
|
133
|
+
errorProperties.$exception_type = isDOMError(domException) ? 'DOMError' : 'DOMException';
|
|
134
|
+
errorProperties.$exception_message = errorProperties.$exception_message || message;
|
|
135
|
+
}
|
|
136
|
+
if ('code' in domException) {
|
|
137
|
+
errorProperties['$exception_DOMException_code'] = "".concat(domException.code);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
else if (isErrorEvent(candidate) && candidate.error) {
|
|
141
|
+
errorProperties = errorPropertiesFromError(candidate.error);
|
|
142
|
+
}
|
|
143
|
+
else if (isError(candidate)) {
|
|
144
|
+
errorProperties = errorPropertiesFromError(candidate);
|
|
145
|
+
}
|
|
146
|
+
else if (isPlainObject(candidate) || isEvent(candidate)) {
|
|
147
|
+
// group these by using the keys available on the object
|
|
148
|
+
var objectException = candidate;
|
|
149
|
+
errorProperties = errorPropertiesFromObject(objectException);
|
|
150
|
+
errorProperties.$exception_is_synthetic = true;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// If none of previous checks were valid, then it must be a string
|
|
154
|
+
errorProperties.$exception_type = errorProperties.$exception_type || 'Error';
|
|
155
|
+
errorProperties.$exception_message = errorProperties.$exception_message || candidate;
|
|
156
|
+
errorProperties.$exception_is_synthetic = true;
|
|
157
|
+
}
|
|
158
|
+
return __assign(__assign(__assign(__assign(__assign({}, errorProperties), {
|
|
159
|
+
// now we make sure the mandatory fields that were made optional are present
|
|
160
|
+
$exception_type: errorProperties.$exception_type || 'UnknownErrorType', $exception_message: errorProperties.$exception_message || '' }), (source
|
|
161
|
+
? {
|
|
162
|
+
$exception_source: source, // TODO get this from URL if not present
|
|
163
|
+
}
|
|
164
|
+
: {})), (lineno ? { $exception_lineno: lineno } : {})), (colno ? { $exception_colno: colno } : {}));
|
|
165
|
+
}
|
|
166
|
+
export function unhandledRejectionToProperties(_a) {
|
|
167
|
+
var _b = __read(_a, 1), ev = _b[0];
|
|
168
|
+
// dig the object of the rejection out of known event types
|
|
169
|
+
var error = ev;
|
|
170
|
+
try {
|
|
171
|
+
// PromiseRejectionEvents store the object of the rejection under 'reason'
|
|
172
|
+
// see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
|
|
173
|
+
if ('reason' in ev) {
|
|
174
|
+
error = ev.reason;
|
|
175
|
+
}
|
|
176
|
+
// something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
|
|
177
|
+
// to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
|
|
178
|
+
// the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
|
|
179
|
+
// see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
|
|
180
|
+
// https://github.com/getsentry/sentry-javascript/issues/2380
|
|
181
|
+
else if ('detail' in ev && 'reason' in ev.detail) {
|
|
182
|
+
error = ev.detail.reason;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (_oO) {
|
|
186
|
+
// no-empty
|
|
187
|
+
}
|
|
188
|
+
// exception type and message are not optional but, it's useful to start off without them enforced
|
|
189
|
+
var errorProperties = {};
|
|
190
|
+
if (isPrimitive(error)) {
|
|
191
|
+
errorProperties = {
|
|
192
|
+
$exception_message: "Non-Error promise rejection captured with value: ".concat(String(error)),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
errorProperties = errorToProperties([error]);
|
|
197
|
+
}
|
|
198
|
+
errorProperties.$exception_handled = false;
|
|
199
|
+
return __assign(__assign({}, errorProperties), {
|
|
200
|
+
// now we make sure the mandatory fields that were made optional are present
|
|
201
|
+
$exception_type: (errorProperties.$exception_type = 'UnhandledRejection'), $exception_message: (errorProperties.$exception_message =
|
|
202
|
+
errorProperties.$exception_message || ev.reason || String(error)) });
|
|
203
|
+
}
|
|
204
|
+
//# sourceMappingURL=error-conversion.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-conversion.js","sourceRoot":"","sources":["../../../../src/extensions/exceptions/error-conversion.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EACH,UAAU,EACV,cAAc,EACd,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,aAAa,EACb,WAAW,GACd,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAc,MAAM,eAAe,CAAA;AAE9D;;GAEG;AAEH,IAAM,mBAAmB,GACrB,0GAA0G,CAAA;AAuB9G,IAAM,mBAAmB,GAAG,6BAA6B,CAAA;AAEzD,SAAS,UAAU,CAAC,EAAoC;IACpD,IAAI,EAAE,EAAE;QACJ,IAAI,OAAO,EAAE,CAAC,WAAW,KAAK,QAAQ,EAAE;Y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QAC9F,gFAAgF;QAChF,qFAAqF;QACrF,uEAAuE;QACvE,6DAA6D;aACxD,IAAI,QAAQ,IAAI,EAAE,IAAI,QAAQ,IAAK,EAAU,CAAC,MAAM,EAAE;YACvD,KAAK,GAAI,EAAU,CAAC,MAAM,CAAC,MAAM,CAAA;SACpC;KACJ;IAAC,OAAO,GAAG,EAAE;QACV,WAAW;KACd;IAED,kGAAkG;IAClG,IAAI,eAAe,GAGf,EAAE,CAAA;IACN,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;QACpB,eAAe,GAAG;YACd,kBAAkB,EAAE,2DAAoD,MAAM,CAAC,KAAK,CAAC,CAAE;SAC1F,CAAA;KACJ;SAAM;QACH,eAAe,GAAG,iBAAiB,CAAC,CAAC,KAAuB,CAAC,CAAC,CAAA;KACjE;IACD,eAAe,CAAC,kBAAkB,GAAG,KAAK,CAAA;IAE1C,6BACO,eAAe;QAClB,4EAA4E;QAC5E,eAAe,EAAE,CAAC,eAAe,CAAC,eAAe,GAAG,oBAAoB,CAAC,EACzE,kBAAkB,EAAE,CAAC,eAAe,CAAC,kBAAkB;YACnD,eAAe,CAAC,kBAAkB,IAAK,EAAU,CAAC,MAAM,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,IACjF;AACL,CAAC","sourcesContent":["import {\n isDOMError,\n isDOMException,\n isError,\n isErrorEvent,\n isErrorWithStack,\n isEvent,\n isPlainObject,\n isPrimitive,\n} from './type-checking'\nimport { defaultStackParser, StackFrame } from './stack-trace'\n\n/**\n * based on the very wonderful MIT licensed Sentry SDK\n */\n\nconst ERROR_TYPES_PATTERN =\n /^(?:[Uu]ncaught (?:exception: )?)?(?:((?:Eval|Internal|Range|Reference|Syntax|Type|URI|)Error): )?(.*)$/i\n\nexport type ErrorEventArgs = [\n event: string | Event,\n source?: string | undefined,\n lineno?: number | undefined,\n colno?: number | undefined,\n error?: Error | undefined\n]\n\nexport interface ErrorProperties {\n $exception_type: string\n $exception_message: string\n $exception_source?: string\n $exception_lineno?: number\n $exception_colno?: number\n $exception_DOMException_code?: string\n $exception_is_synthetic?: boolean\n $exception_stack_trace_raw?: string\n $exception_handled?: boolean\n $exception_personURL?: string\n}\n\nconst reactMinifiedRegexp = /Minified React error #\\d+;/i\n\nfunction getPopSize(ex: Error & { framesToPop?: number }): number {\n if (ex) {\n if (typeof ex.framesToPop === 'number') {\n return ex.framesToPop\n }\n\n if (reactMinifiedRegexp.test(ex.message)) {\n return 1\n }\n }\n\n return 0\n}\n\nexport function parseStackFrames(ex: Error & { framesToPop?: number; stacktrace?: string }): StackFrame[] {\n // Access and store the stacktrace property before doing ANYTHING\n // else to it because Opera is not very good at providing it\n // reliably in other circumstances.\n const stacktrace = ex.stacktrace || ex.stack || ''\n\n const popSize = getPopSize(ex)\n\n try {\n return defaultStackParser(stacktrace, popSize)\n } catch (e) {\n // no-empty\n }\n\n return []\n}\n\nfunction errorPropertiesFromError(error: Error): ErrorProperties {\n const frames = parseStackFrames(error)\n\n return {\n $exception_type: error.name,\n $exception_message: error.message,\n $exception_stack_trace_raw: JSON.stringify(frames),\n }\n}\n\nfunction errorPropertiesFromString(candidate: string): ErrorProperties {\n return {\n $exception_type: 'Error',\n $exception_message: candidate,\n }\n}\n\n/**\n * Given any captured exception, extract its keys and create a sorted\n * and truncated list that will be used inside the event message.\n * eg. `Non-error exception captured with keys: foo, bar, baz`\n */\nfunction extractExceptionKeysForMessage(exception: Record<string, unknown>, maxLength = 40): string {\n const keys = Object.keys(exception)\n keys.sort()\n\n if (!keys.length) {\n return '[object has no keys]'\n }\n\n for (let i = keys.length; i > 0; i--) {\n const serialized = keys.slice(0, i).join(', ')\n if (serialized.length > maxLength) {\n continue\n }\n if (i === keys.length) {\n return serialized\n }\n return serialized.length <= maxLength ? serialized : `${serialized.slice(0, maxLength)}...`\n }\n\n return ''\n}\n\nfunction errorPropertiesFromObject(candidate: Record<string, unknown>): ErrorProperties {\n return {\n $exception_type: isEvent(candidate) ? candidate.constructor.name : 'Error',\n $exception_message: `Non-Error ${'exception'} captured with keys: ${extractExceptionKeysForMessage(candidate)}`,\n }\n}\n\nexport function errorToProperties([event, source, lineno, colno, error]: ErrorEventArgs): ErrorProperties {\n // exception type and message are not optional but, it's useful to start off without them enforced\n let errorProperties: Omit<ErrorProperties, '$exception_type' | '$exception_message'> & {\n $exception_type?: string\n $exception_message?: string\n } = {}\n\n if (error === undefined && typeof event === 'string') {\n let name = 'Error'\n let message = event\n const groups = event.match(ERROR_TYPES_PATTERN)\n if (groups) {\n name = groups[1]\n message = groups[2]\n }\n errorProperties = {\n $exception_type: name,\n $exception_message: message,\n }\n }\n\n const candidate = error || event\n\n if (isDOMError(candidate) || isDOMException(candidate)) {\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMError\n // https://developer.mozilla.org/en-US/docs/Web/API/DOMException\n\n const domException = candidate as unknown as DOMException\n\n if (isErrorWithStack(candidate)) {\n errorProperties = errorPropertiesFromError(candidate as Error)\n } else {\n const name = domException.name || (isDOMError(domException) ? 'DOMError' : 'DOMException')\n const message = domException.message ? `${name}: ${domException.message}` : name\n errorProperties = errorPropertiesFromString(message)\n errorProperties.$exception_type = isDOMError(domException) ? 'DOMError' : 'DOMException'\n errorProperties.$exception_message = errorProperties.$exception_message || message\n }\n if ('code' in domException) {\n errorProperties['$exception_DOMException_code'] = `${domException.code}`\n }\n } else if (isErrorEvent(candidate as ErrorEvent) && (candidate as ErrorEvent).error) {\n errorProperties = errorPropertiesFromError((candidate as ErrorEvent).error as Error)\n } else if (isError(candidate)) {\n errorProperties = errorPropertiesFromError(candidate)\n } else if (isPlainObject(candidate) || isEvent(candidate)) {\n // group these by using the keys available on the object\n const objectException = candidate as Record<string, unknown>\n errorProperties = errorPropertiesFromObject(objectException)\n errorProperties.$exception_is_synthetic = true\n } else {\n // If none of previous checks were valid, then it must be a string\n errorProperties.$exception_type = errorProperties.$exception_type || 'Error'\n errorProperties.$exception_message = errorProperties.$exception_message || candidate\n errorProperties.$exception_is_synthetic = true\n }\n\n return {\n ...errorProperties,\n // now we make sure the mandatory fields that were made optional are present\n $exception_type: errorProperties.$exception_type || 'UnknownErrorType',\n $exception_message: errorProperties.$exception_message || '',\n ...(source\n ? {\n $exception_source: source, // TODO get this from URL if not present\n }\n : {}),\n ...(lineno ? { $exception_lineno: lineno } : {}),\n ...(colno ? { $exception_colno: colno } : {}),\n }\n}\n\nexport function unhandledRejectionToProperties([ev]: [ev: PromiseRejectionEvent]): ErrorProperties {\n // dig the object of the rejection out of known event types\n let error: unknown = ev\n try {\n // PromiseRejectionEvents store the object of the rejection under 'reason'\n // see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent\n if ('reason' in ev) {\n error = ev.reason\n }\n // something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents\n // to CustomEvents, moving the `promise` and `reason` attributes of the PRE into\n // the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec\n // see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and\n // https://github.com/getsentry/sentry-javascript/issues/2380\n else if ('detail' in ev && 'reason' in (ev as any).detail) {\n error = (ev as any).detail.reason\n }\n } catch (_oO) {\n // no-empty\n }\n\n // exception type and message are not optional but, it's useful to start off without them enforced\n let errorProperties: Omit<ErrorProperties, '$exception_type' | '$exception_message'> & {\n $exception_type?: string\n $exception_message?: string\n } = {}\n if (isPrimitive(error)) {\n errorProperties = {\n $exception_message: `Non-Error promise rejection captured with value: ${String(error)}`,\n }\n } else {\n errorProperties = errorToProperties([error as string | Event])\n }\n errorProperties.$exception_handled = false\n\n return {\n ...errorProperties,\n // now we make sure the mandatory fields that were made optional are present\n $exception_type: (errorProperties.$exception_type = 'UnhandledRejection'),\n $exception_message: (errorProperties.$exception_message =\n errorProperties.$exception_message || (ev as any).reason || String(error)),\n }\n}\n"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { PostHog } from '../../posthog-core';
|
|
2
|
+
import { DecideResponse, Properties } from '../../types';
|
|
3
|
+
import { ErrorEventArgs } from './error-conversion';
|
|
4
|
+
export declare class ExceptionObserver {
|
|
5
|
+
instance: PostHog;
|
|
6
|
+
remoteEnabled: boolean | undefined;
|
|
7
|
+
private originalOnErrorHandler;
|
|
8
|
+
private originalOnUnhandledRejectionHandler;
|
|
9
|
+
private errorsToIgnore;
|
|
10
|
+
constructor(instance: PostHog);
|
|
11
|
+
private debugLog;
|
|
12
|
+
startCapturing(): void;
|
|
13
|
+
stopCapturing(): void;
|
|
14
|
+
isCapturing(): boolean;
|
|
15
|
+
isEnabled(): boolean;
|
|
16
|
+
afterDecideResponse(response: DecideResponse): void;
|
|
17
|
+
captureException(args: ErrorEventArgs, properties?: Properties): void;
|
|
18
|
+
/**
|
|
19
|
+
* :TRICKY: Make sure we batch these requests
|
|
20
|
+
*/
|
|
21
|
+
sendExceptionEvent(properties: {
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}): void;
|
|
24
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
13
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
14
|
+
if (!m) return o;
|
|
15
|
+
var i = m.call(o), r, ar = [], e;
|
|
16
|
+
try {
|
|
17
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
18
|
+
}
|
|
19
|
+
catch (error) { e = { error: error }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e) throw e.error; }
|
|
25
|
+
}
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
29
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
30
|
+
if (ar || !(i in from)) {
|
|
31
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
32
|
+
ar[i] = from[i];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
36
|
+
};
|
|
37
|
+
import { window } from '../../utils';
|
|
38
|
+
import { errorToProperties, unhandledRejectionToProperties } from './error-conversion';
|
|
39
|
+
import { isPrimitive } from './type-checking';
|
|
40
|
+
var EXCEPTION_INGESTION_ENDPOINT = '/e/';
|
|
41
|
+
var ExceptionObserver = /** @class */ (function () {
|
|
42
|
+
function ExceptionObserver(instance) {
|
|
43
|
+
this.originalOnErrorHandler = undefined;
|
|
44
|
+
this.originalOnUnhandledRejectionHandler = undefined;
|
|
45
|
+
this.errorsToIgnore = [];
|
|
46
|
+
this.instance = instance;
|
|
47
|
+
}
|
|
48
|
+
ExceptionObserver.prototype.debugLog = function () {
|
|
49
|
+
var args = [];
|
|
50
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
51
|
+
args[_i] = arguments[_i];
|
|
52
|
+
}
|
|
53
|
+
if (this.instance.get_config('debug')) {
|
|
54
|
+
console.log.apply(console, __spreadArray(['PostHog.js [PostHog.ExceptionObserver]'], __read(args), false));
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
ExceptionObserver.prototype.startCapturing = function () {
|
|
58
|
+
var _a;
|
|
59
|
+
if (!this.isEnabled() || ((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
try {
|
|
63
|
+
this.originalOnErrorHandler = window.onerror;
|
|
64
|
+
window.onerror = function () {
|
|
65
|
+
var args = [];
|
|
66
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
67
|
+
args[_i] = arguments[_i];
|
|
68
|
+
}
|
|
69
|
+
this.captureException(args);
|
|
70
|
+
if (this.originalOnErrorHandler) {
|
|
71
|
+
// eslint-disable-next-line prefer-rest-params
|
|
72
|
+
return this.originalOnErrorHandler.apply(this, args);
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
}.bind(this);
|
|
76
|
+
window.onerror.__POSTHOG_INSTRUMENTED__ = true;
|
|
77
|
+
this.originalOnUnhandledRejectionHandler = window.onunhandledrejection;
|
|
78
|
+
window.onunhandledrejection = function () {
|
|
79
|
+
var args = [];
|
|
80
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
81
|
+
args[_i] = arguments[_i];
|
|
82
|
+
}
|
|
83
|
+
var errorProperties = unhandledRejectionToProperties(args);
|
|
84
|
+
this.sendExceptionEvent(errorProperties);
|
|
85
|
+
if (this.originalOnUnhandledRejectionHandler) {
|
|
86
|
+
// eslint-disable-next-line prefer-rest-params
|
|
87
|
+
return this.originalOnUnhandledRejectionHandler.apply(window, args);
|
|
88
|
+
}
|
|
89
|
+
return true;
|
|
90
|
+
}.bind(this);
|
|
91
|
+
window.onunhandledrejection.__POSTHOG_INSTRUMENTED__ = true;
|
|
92
|
+
}
|
|
93
|
+
catch (e) {
|
|
94
|
+
console.error('PostHog failed to start exception autocapture', e);
|
|
95
|
+
this.stopCapturing();
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
ExceptionObserver.prototype.stopCapturing = function () {
|
|
99
|
+
var _a, _b;
|
|
100
|
+
if (this.originalOnErrorHandler !== undefined) {
|
|
101
|
+
window.onerror = this.originalOnErrorHandler;
|
|
102
|
+
this.originalOnErrorHandler = null;
|
|
103
|
+
}
|
|
104
|
+
(_a = window.onerror) === null || _a === void 0 ? true : delete _a.__POSTHOG_INSTRUMENTED__;
|
|
105
|
+
if (this.originalOnUnhandledRejectionHandler !== undefined) {
|
|
106
|
+
window.onunhandledrejection = this.originalOnUnhandledRejectionHandler;
|
|
107
|
+
this.originalOnUnhandledRejectionHandler = null;
|
|
108
|
+
}
|
|
109
|
+
(_b = window.onunhandledrejection) === null || _b === void 0 ? true : delete _b.__POSTHOG_INSTRUMENTED__;
|
|
110
|
+
};
|
|
111
|
+
ExceptionObserver.prototype.isCapturing = function () {
|
|
112
|
+
var _a;
|
|
113
|
+
return !!((_a = window.onerror) === null || _a === void 0 ? void 0 : _a.__POSTHOG_INSTRUMENTED__);
|
|
114
|
+
};
|
|
115
|
+
ExceptionObserver.prototype.isEnabled = function () {
|
|
116
|
+
var _a;
|
|
117
|
+
return (_a = this.remoteEnabled) !== null && _a !== void 0 ? _a : false;
|
|
118
|
+
};
|
|
119
|
+
ExceptionObserver.prototype.afterDecideResponse = function (response) {
|
|
120
|
+
var autocaptureExceptionsResponse = response.autocaptureExceptions;
|
|
121
|
+
this.remoteEnabled = !!autocaptureExceptionsResponse || false;
|
|
122
|
+
if (!isPrimitive(autocaptureExceptionsResponse) &&
|
|
123
|
+
'errors_to_ignore' in autocaptureExceptionsResponse &&
|
|
124
|
+
Array.isArray(autocaptureExceptionsResponse.errors_to_ignore)) {
|
|
125
|
+
var dropRules = autocaptureExceptionsResponse.errors_to_ignore;
|
|
126
|
+
this.errorsToIgnore = dropRules.map(function (rule) {
|
|
127
|
+
return new RegExp(rule);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (this.isEnabled()) {
|
|
131
|
+
this.startCapturing();
|
|
132
|
+
this.debugLog('Remote config for exception autocapture is enabled, starting', autocaptureExceptionsResponse);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
this.debugLog('Remote config for exception autocapture is disabled, not starting', autocaptureExceptionsResponse);
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
ExceptionObserver.prototype.captureException = function (args, properties) {
|
|
139
|
+
var errorProperties = errorToProperties(args);
|
|
140
|
+
if (this.errorsToIgnore.some(function (regex) { return regex.test(errorProperties.$exception_message || ''); })) {
|
|
141
|
+
this.debugLog('Ignoring exception based on remote config', errorProperties);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
var propertiesToSend = __assign(__assign({}, properties), errorProperties);
|
|
145
|
+
var posthogHost = this.instance.get_config('ui_host') || this.instance.get_config('api_host');
|
|
146
|
+
errorProperties.$exception_personURL = posthogHost + '/person/' + this.instance.get_distinct_id();
|
|
147
|
+
this.sendExceptionEvent(propertiesToSend);
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* :TRICKY: Make sure we batch these requests
|
|
151
|
+
*/
|
|
152
|
+
ExceptionObserver.prototype.sendExceptionEvent = function (properties) {
|
|
153
|
+
this.instance.capture('$exception', properties, {
|
|
154
|
+
transport: 'XHR',
|
|
155
|
+
method: 'POST',
|
|
156
|
+
endpoint: EXCEPTION_INGESTION_ENDPOINT,
|
|
157
|
+
_noTruncate: true,
|
|
158
|
+
_batchKey: 'exceptionEvent',
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
return ExceptionObserver;
|
|
162
|
+
}());
|
|
163
|
+
export { ExceptionObserver };
|
|
164
|
+
//# sourceMappingURL=exception-autocapture.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exception-autocapture.js","sourceRoot":"","sources":["../../../../src/extensions/exceptions/exception-autocapture.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAGpC,OAAO,EAAmC,iBAAiB,EAAE,8BAA8B,EAAE,MAAM,oBAAoB,CAAA;AACvH,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAE7C,IAAM,4BAA4B,GAAG,KAAK,CAAA;AAE1C;IAQI,2BAAY,QAAiB;QALrB,2BAAsB,GAAgD,SAAS,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AAG,IAAI,CAAC,QAAQ,CAAC,eAAe,EAAE,CAAA;QAEjG,IAAI,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,CAAA;IAC7C,CAAC;IAED;;OAEG;IACH,8CAAkB,GAAlB,UAAmB,UAAkC;QACjD,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,EAAE;YAC5C,SAAS,EAAE,KAAK;YAChB,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,4BAA4B;YACtC,WAAW,EAAE,IAAI;YACjB,SAAS,EAAE,gBAAgB;SAC9B,CAAC,CAAA;IACN,CAAC;IACL,wBAAC;AAAD,CAAC,AAzID,IAyIC","sourcesContent":["import { window } from '../../utils'\nimport { PostHog } from '../../posthog-core'\nimport { DecideResponse, Properties } from '../../types'\nimport { ErrorEventArgs, ErrorProperties, errorToProperties, unhandledRejectionToProperties } from './error-conversion'\nimport { isPrimitive } from './type-checking'\n\nconst EXCEPTION_INGESTION_ENDPOINT = '/e/'\n\nexport class ExceptionObserver {\n instance: PostHog\n remoteEnabled: boolean | undefined\n private originalOnErrorHandler: typeof window['onerror'] | null | undefined = undefined\n private originalOnUnhandledRejectionHandler: typeof window['onunhandledrejection'] | null | undefined = undefined\n\n private errorsToIgnore: RegExp[] = []\n\n constructor(instance: PostHog) {\n this.instance = instance\n }\n\n private debugLog(...args: any[]) {\n if (this.instance.get_config('debug')) {\n console.log('PostHog.js [PostHog.ExceptionObserver]', ...args)\n }\n }\n\n startCapturing() {\n if (!this.isEnabled() || (window.onerror as any)?.__POSTHOG_INSTRUMENTED__) {\n return\n }\n\n try {\n this.originalOnErrorHandler = window.onerror\n\n window.onerror = function (this: ExceptionObserver, ...args: ErrorEventArgs): boolean {\n this.captureException(args)\n\n if (this.originalOnErrorHandler) {\n // eslint-disable-next-line prefer-rest-params\n return this.originalOnErrorHandler.apply(this, args)\n }\n\n return false\n }.bind(this)\n ;(window.onerror as any).__POSTHOG_INSTRUMENTED__ = true\n\n this.originalOnUnhandledRejectionHandler = window.onunhandledrejection\n\n window.onunhandledrejection = function (\n this: ExceptionObserver,\n ...args: [ev: PromiseRejectionEvent]\n ): boolean {\n const errorProperties: ErrorProperties = unhandledRejectionToProperties(args)\n this.sendExceptionEvent(errorProperties)\n\n if (this.originalOnUnhandledRejectionHandler) {\n // eslint-disable-next-line prefer-rest-params\n return this.originalOnUnhandledRejectionHandler.apply(window, args)\n }\n\n return true\n }.bind(this)\n ;(window.onunhandledrejection as any).__POSTHOG_INSTRUMENTED__ = true\n } catch (e) {\n console.error('PostHog failed to start exception autocapture', e)\n this.stopCapturing()\n }\n }\n\n stopCapturing() {\n if (this.originalOnErrorHandler !== undefined) {\n window.onerror = this.originalOnErrorHandler\n this.originalOnErrorHandler = null\n }\n delete (window.onerror as any)?.__POSTHOG_INSTRUMENTED__\n\n if (this.originalOnUnhandledRejectionHandler !== undefined) {\n window.onunhandledrejection = this.originalOnUnhandledRejectionHandler\n this.originalOnUnhandledRejectionHandler = null\n }\n delete (window.onunhandledrejection as any)?.__POSTHOG_INSTRUMENTED__\n }\n\n isCapturing() {\n return !!(window.onerror as any)?.__POSTHOG_INSTRUMENTED__\n }\n\n isEnabled() {\n return this.remoteEnabled ?? false\n }\n\n afterDecideResponse(response: DecideResponse) {\n const autocaptureExceptionsResponse = response.autocaptureExceptions\n this.remoteEnabled = !!autocaptureExceptionsResponse || false\n if (\n !isPrimitive(autocaptureExceptionsResponse) &&\n 'errors_to_ignore' in autocaptureExceptionsResponse &&\n Array.isArray(autocaptureExceptionsResponse.errors_to_ignore)\n ) {\n const dropRules = autocaptureExceptionsResponse.errors_to_ignore\n\n this.errorsToIgnore = dropRules.map((rule) => {\n return new RegExp(rule)\n })\n }\n\n if (this.isEnabled()) {\n this.startCapturing()\n this.debugLog('Remote config for exception autocapture is enabled, starting', autocaptureExceptionsResponse)\n } else {\n this.debugLog(\n 'Remote config for exception autocapture is disabled, not starting',\n autocaptureExceptionsResponse\n )\n }\n }\n\n captureException(args: ErrorEventArgs, properties?: Properties) {\n const errorProperties = errorToProperties(args)\n\n if (this.errorsToIgnore.some((regex) => regex.test(errorProperties.$exception_message || ''))) {\n this.debugLog('Ignoring exception based on remote config', errorProperties)\n return\n }\n\n const propertiesToSend = { ...properties, ...errorProperties }\n\n const posthogHost = this.instance.get_config('ui_host') || this.instance.get_config('api_host')\n errorProperties.$exception_personURL = posthogHost + '/person/' + this.instance.get_distinct_id()\n\n this.sendExceptionEvent(propertiesToSend)\n }\n\n /**\n * :TRICKY: Make sure we batch these requests\n */\n sendExceptionEvent(properties: { [key: string]: any }) {\n this.instance.capture('$exception', properties, {\n transport: 'XHR',\n method: 'POST',\n endpoint: EXCEPTION_INGESTION_ENDPOINT,\n _noTruncate: true,\n _batchKey: 'exceptionEvent',\n })\n }\n}\n"]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface StackFrame {
|
|
2
|
+
filename?: string;
|
|
3
|
+
function?: string;
|
|
4
|
+
module?: string;
|
|
5
|
+
platform?: string;
|
|
6
|
+
lineno?: number;
|
|
7
|
+
colno?: number;
|
|
8
|
+
abs_path?: string;
|
|
9
|
+
context_line?: string;
|
|
10
|
+
pre_context?: string[];
|
|
11
|
+
post_context?: string[];
|
|
12
|
+
in_app?: boolean;
|
|
13
|
+
instruction_addr?: string;
|
|
14
|
+
addr_mode?: string;
|
|
15
|
+
vars?: {
|
|
16
|
+
[key: string]: any;
|
|
17
|
+
};
|
|
18
|
+
debug_id?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare type StackParser = (stack: string, skipFirst?: number) => StackFrame[];
|
|
21
|
+
export declare type StackLineParserFn = (line: string) => StackFrame | undefined;
|
|
22
|
+
export declare type StackLineParser = [number, StackLineParserFn];
|
|
23
|
+
export declare const chromeStackLineParser: StackLineParser;
|
|
24
|
+
export declare const geckoStackLineParser: StackLineParser;
|
|
25
|
+
export declare const winjsStackLineParser: StackLineParser;
|
|
26
|
+
export declare const opera10StackLineParser: StackLineParser;
|
|
27
|
+
export declare const opera11StackLineParser: StackLineParser;
|
|
28
|
+
export declare const defaultStackLineParsers: StackLineParser[];
|
|
29
|
+
export declare function reverse(stack: ReadonlyArray<StackFrame>): StackFrame[];
|
|
30
|
+
export declare function createStackParser(...parsers: StackLineParser[]): StackParser;
|
|
31
|
+
export declare const defaultStackParser: StackParser;
|