@posthog/core 1.23.2 → 1.23.4
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/error-tracking/coercers/promise-rejection-event.d.ts +10 -3
- package/dist/error-tracking/coercers/promise-rejection-event.d.ts.map +1 -1
- package/dist/error-tracking/coercers/promise-rejection-event.js +11 -3
- package/dist/error-tracking/coercers/promise-rejection-event.mjs +12 -4
- package/dist/posthog-core-stateless.d.ts.map +1 -1
- package/dist/posthog-core-stateless.js +22 -17
- package/dist/posthog-core-stateless.mjs +22 -17
- package/dist/utils/user-agent-utils.d.ts +7 -1
- package/dist/utils/user-agent-utils.d.ts.map +1 -1
- package/dist/utils/user-agent-utils.js +6 -1
- package/dist/utils/user-agent-utils.mjs +6 -1
- package/package.json +1 -1
- package/src/error-tracking/coercers/promise-rejection-event.ts +26 -17
- package/src/error-tracking/error-properties-builder.coerce.spec.ts +28 -2
- package/src/posthog-core-stateless.ts +23 -18
- package/src/utils/user-agent-utils.ts +21 -3
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
import { CoercingContext, ErrorTrackingCoercer, ExceptionLike } from '../types';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
type EventWithDetailReason = Event & {
|
|
3
|
+
detail: {
|
|
4
|
+
reason: unknown;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
export declare class PromiseRejectionEventCoercer implements ErrorTrackingCoercer<PromiseRejectionEvent | EventWithDetailReason> {
|
|
8
|
+
match(err: unknown): err is PromiseRejectionEvent | EventWithDetailReason;
|
|
9
|
+
private isCustomEventWrappingRejection;
|
|
10
|
+
coerce(err: PromiseRejectionEvent | EventWithDetailReason, ctx: CoercingContext): ExceptionLike | undefined;
|
|
5
11
|
private getUnhandledRejectionReason;
|
|
6
12
|
}
|
|
13
|
+
export {};
|
|
7
14
|
//# sourceMappingURL=promise-rejection-event.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"promise-rejection-event.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/promise-rejection-event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"promise-rejection-event.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/coercers/promise-rejection-event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE/E,KAAK,qBAAqB,GAAG,KAAK,GAAG;IAAE,MAAM,EAAE;QAAE,MAAM,EAAE,OAAO,CAAA;KAAE,CAAA;CAAE,CAAA;AAGpE,qBAAa,4BAA6B,YAAW,oBAAoB,CACvE,qBAAqB,GAAG,qBAAqB,CAC9C;IACC,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,qBAAqB,GAAG,qBAAqB;IAIzE,OAAO,CAAC,8BAA8B;IAYtC,MAAM,CAAC,GAAG,EAAE,qBAAqB,GAAG,qBAAqB,EAAE,GAAG,EAAE,eAAe,GAAG,aAAa,GAAG,SAAS;IAc3G,OAAO,CAAC,2BAA2B;CAsBpC"}
|
|
@@ -29,7 +29,16 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
29
29
|
const index_js_namespaceObject = require("../../utils/index.js");
|
|
30
30
|
class PromiseRejectionEventCoercer {
|
|
31
31
|
match(err) {
|
|
32
|
-
return (0, index_js_namespaceObject.isBuiltin)(err, 'PromiseRejectionEvent');
|
|
32
|
+
return (0, index_js_namespaceObject.isBuiltin)(err, 'PromiseRejectionEvent') || this.isCustomEventWrappingRejection(err);
|
|
33
|
+
}
|
|
34
|
+
isCustomEventWrappingRejection(err) {
|
|
35
|
+
if (!(0, index_js_namespaceObject.isEvent)(err)) return false;
|
|
36
|
+
try {
|
|
37
|
+
const detail = err.detail;
|
|
38
|
+
return null != detail && 'object' == typeof detail && 'reason' in detail;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
43
|
coerce(err, ctx) {
|
|
35
44
|
const reason = this.getUnhandledRejectionReason(err);
|
|
@@ -42,10 +51,9 @@ class PromiseRejectionEventCoercer {
|
|
|
42
51
|
return ctx.apply(reason);
|
|
43
52
|
}
|
|
44
53
|
getUnhandledRejectionReason(error) {
|
|
45
|
-
if ((0, index_js_namespaceObject.isPrimitive)(error)) return error;
|
|
46
54
|
try {
|
|
47
55
|
if ('reason' in error) return error.reason;
|
|
48
|
-
if ('detail' in error && 'reason' in error.detail) return error.detail.reason;
|
|
56
|
+
if ('detail' in error && null != error.detail && 'object' == typeof error.detail && 'reason' in error.detail) return error.detail.reason;
|
|
49
57
|
} catch {}
|
|
50
58
|
return error;
|
|
51
59
|
}
|
|
@@ -1,7 +1,16 @@
|
|
|
1
|
-
import { isBuiltin, isPrimitive } from "../../utils/index.mjs";
|
|
1
|
+
import { isBuiltin, isEvent, isPrimitive } from "../../utils/index.mjs";
|
|
2
2
|
class PromiseRejectionEventCoercer {
|
|
3
3
|
match(err) {
|
|
4
|
-
return isBuiltin(err, 'PromiseRejectionEvent');
|
|
4
|
+
return isBuiltin(err, 'PromiseRejectionEvent') || this.isCustomEventWrappingRejection(err);
|
|
5
|
+
}
|
|
6
|
+
isCustomEventWrappingRejection(err) {
|
|
7
|
+
if (!isEvent(err)) return false;
|
|
8
|
+
try {
|
|
9
|
+
const detail = err.detail;
|
|
10
|
+
return null != detail && 'object' == typeof detail && 'reason' in detail;
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
5
14
|
}
|
|
6
15
|
coerce(err, ctx) {
|
|
7
16
|
const reason = this.getUnhandledRejectionReason(err);
|
|
@@ -14,10 +23,9 @@ class PromiseRejectionEventCoercer {
|
|
|
14
23
|
return ctx.apply(reason);
|
|
15
24
|
}
|
|
16
25
|
getUnhandledRejectionReason(error) {
|
|
17
|
-
if (isPrimitive(error)) return error;
|
|
18
26
|
try {
|
|
19
27
|
if ('reason' in error) return error.reason;
|
|
20
|
-
if ('detail' in error && 'reason' in error.detail) return error.detail.reason;
|
|
28
|
+
if ('detail' in error && null != error.detail && 'object' == typeof error.detail && 'reason' in error.detail) return error.detail.reason;
|
|
21
29
|
} catch {}
|
|
22
30
|
return error;
|
|
23
31
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"posthog-core-stateless.d.ts","sourceRoot":"","sources":["../src/posthog-core-stateless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAGnD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,sBAAsB,EACtB,qBAAqB,EACrB,QAAQ,EACR,mBAAmB,EACnB,gBAAgB,EAGhB,yBAAyB,EACzB,iBAAiB,EACjB,cAAc,EACd,oBAAoB,EACpB,mBAAmB,EACnB,wBAAwB,EAExB,MAAM,EACN,cAAc,EAEf,MAAM,SAAS,CAAA;AAChB,OAAO,EAOL,gBAAgB,EAIjB,MAAM,SAAS,CAAA;AAqChB,eAAO,MAAM,QAAQ,GAAI,KAAK,MAAM,EAAE,OAAO,QAAQ,GAAG,SAAS,KAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAC9C,CAAA;AAE7C,wBAAsB,aAAa,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3D;AAUD,oBAAY,mBAAmB;IAC7B,YAAY,kBAAkB;IAC9B,UAAU,eAAe;CAC1B;AAED,8BAAsB,oBAAoB;IAExC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,mBAAmB,EAAE,OAAO,CAAA;IACrC,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAA;IAChC,O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C,eAAe;IAMvB;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB5B,SAAS,CAAC,gBAAgB,IAAI;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE;YAazC,MAAM;YA4FN,cAAc;IAsDtB,SAAS,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDjE;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,QAAQ,CAAC,iBAAiB,GAAE,MAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAYjE"}
|
|
@@ -275,7 +275,7 @@ class PostHogCoreStateless {
|
|
|
275
275
|
this._events.emit('error', error);
|
|
276
276
|
});
|
|
277
277
|
}
|
|
278
|
-
async getFlags(distinctId, groups = {}, personProperties = {}, groupProperties = {}, extraPayload = {}, fetchConfig =
|
|
278
|
+
async getFlags(distinctId, groups = {}, personProperties = {}, groupProperties = {}, extraPayload = {}, fetchConfig = false) {
|
|
279
279
|
await this._initPromise;
|
|
280
280
|
const configParam = fetchConfig ? '&config=true' : '';
|
|
281
281
|
const url = `${this.host}/flags/?v=2${configParam}`;
|
|
@@ -633,11 +633,6 @@ class PostHogCoreStateless {
|
|
|
633
633
|
this._events.emit('flush', sentMessages);
|
|
634
634
|
}
|
|
635
635
|
async fetchWithRetry(url, options, retryOptions, requestTimeout) {
|
|
636
|
-
AbortSignal.timeout ??= function(ms) {
|
|
637
|
-
const ctrl = new AbortController();
|
|
638
|
-
setTimeout(()=>ctrl.abort(), ms);
|
|
639
|
-
return ctrl.signal;
|
|
640
|
-
};
|
|
641
636
|
const body = options.body ? options.body : '';
|
|
642
637
|
let reqByteLength = -1;
|
|
643
638
|
try {
|
|
@@ -650,14 +645,19 @@ class PostHogCoreStateless {
|
|
|
650
645
|
}
|
|
651
646
|
}
|
|
652
647
|
return await (0, index_js_namespaceObject.retriable)(async ()=>{
|
|
648
|
+
const ctrl = new AbortController();
|
|
649
|
+
const timeoutMs = requestTimeout ?? this.requestTimeout;
|
|
650
|
+
const timer = (0, index_js_namespaceObject.safeSetTimeout)(()=>ctrl.abort(), timeoutMs);
|
|
653
651
|
let res = null;
|
|
654
652
|
try {
|
|
655
653
|
res = await this.fetch(url, {
|
|
656
|
-
signal:
|
|
654
|
+
signal: ctrl.signal,
|
|
657
655
|
...options
|
|
658
656
|
});
|
|
659
657
|
} catch (e) {
|
|
660
658
|
throw new PostHogFetchNetworkError(e);
|
|
659
|
+
} finally{
|
|
660
|
+
clearTimeout(timer);
|
|
661
661
|
}
|
|
662
662
|
const isNoCors = 'no-cors' === options.mode;
|
|
663
663
|
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength);
|
|
@@ -685,16 +685,21 @@ class PostHogCoreStateless {
|
|
|
685
685
|
await logFlushError(e);
|
|
686
686
|
}
|
|
687
687
|
};
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
688
|
+
let timeoutHandle;
|
|
689
|
+
try {
|
|
690
|
+
return await Promise.race([
|
|
691
|
+
new Promise((_, reject)=>{
|
|
692
|
+
timeoutHandle = (0, index_js_namespaceObject.safeSetTimeout)(()=>{
|
|
693
|
+
this._logger.error('Timed out while shutting down PostHog');
|
|
694
|
+
hasTimedOut = true;
|
|
695
|
+
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
696
|
+
}, shutdownTimeoutMs);
|
|
697
|
+
}),
|
|
698
|
+
doShutdown()
|
|
699
|
+
]);
|
|
700
|
+
} finally{
|
|
701
|
+
clearTimeout(timeoutHandle);
|
|
702
|
+
}
|
|
698
703
|
}
|
|
699
704
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
700
705
|
if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
|
|
@@ -244,7 +244,7 @@ class PostHogCoreStateless {
|
|
|
244
244
|
this._events.emit('error', error);
|
|
245
245
|
});
|
|
246
246
|
}
|
|
247
|
-
async getFlags(distinctId, groups = {}, personProperties = {}, groupProperties = {}, extraPayload = {}, fetchConfig =
|
|
247
|
+
async getFlags(distinctId, groups = {}, personProperties = {}, groupProperties = {}, extraPayload = {}, fetchConfig = false) {
|
|
248
248
|
await this._initPromise;
|
|
249
249
|
const configParam = fetchConfig ? '&config=true' : '';
|
|
250
250
|
const url = `${this.host}/flags/?v=2${configParam}`;
|
|
@@ -602,11 +602,6 @@ class PostHogCoreStateless {
|
|
|
602
602
|
this._events.emit('flush', sentMessages);
|
|
603
603
|
}
|
|
604
604
|
async fetchWithRetry(url, options, retryOptions, requestTimeout) {
|
|
605
|
-
AbortSignal.timeout ??= function(ms) {
|
|
606
|
-
const ctrl = new AbortController();
|
|
607
|
-
setTimeout(()=>ctrl.abort(), ms);
|
|
608
|
-
return ctrl.signal;
|
|
609
|
-
};
|
|
610
605
|
const body = options.body ? options.body : '';
|
|
611
606
|
let reqByteLength = -1;
|
|
612
607
|
try {
|
|
@@ -619,14 +614,19 @@ class PostHogCoreStateless {
|
|
|
619
614
|
}
|
|
620
615
|
}
|
|
621
616
|
return await retriable(async ()=>{
|
|
617
|
+
const ctrl = new AbortController();
|
|
618
|
+
const timeoutMs = requestTimeout ?? this.requestTimeout;
|
|
619
|
+
const timer = safeSetTimeout(()=>ctrl.abort(), timeoutMs);
|
|
622
620
|
let res = null;
|
|
623
621
|
try {
|
|
624
622
|
res = await this.fetch(url, {
|
|
625
|
-
signal:
|
|
623
|
+
signal: ctrl.signal,
|
|
626
624
|
...options
|
|
627
625
|
});
|
|
628
626
|
} catch (e) {
|
|
629
627
|
throw new PostHogFetchNetworkError(e);
|
|
628
|
+
} finally{
|
|
629
|
+
clearTimeout(timer);
|
|
630
630
|
}
|
|
631
631
|
const isNoCors = 'no-cors' === options.mode;
|
|
632
632
|
if (!isNoCors && (res.status < 200 || res.status >= 400)) throw new PostHogFetchHttpError(res, reqByteLength);
|
|
@@ -654,16 +654,21 @@ class PostHogCoreStateless {
|
|
|
654
654
|
await logFlushError(e);
|
|
655
655
|
}
|
|
656
656
|
};
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
657
|
+
let timeoutHandle;
|
|
658
|
+
try {
|
|
659
|
+
return await Promise.race([
|
|
660
|
+
new Promise((_, reject)=>{
|
|
661
|
+
timeoutHandle = safeSetTimeout(()=>{
|
|
662
|
+
this._logger.error('Timed out while shutting down PostHog');
|
|
663
|
+
hasTimedOut = true;
|
|
664
|
+
reject('Timeout while shutting down PostHog. Some events may not have been sent.');
|
|
665
|
+
}, shutdownTimeoutMs);
|
|
666
|
+
}),
|
|
667
|
+
doShutdown()
|
|
668
|
+
]);
|
|
669
|
+
} finally{
|
|
670
|
+
clearTimeout(timeoutHandle);
|
|
671
|
+
}
|
|
667
672
|
}
|
|
668
673
|
async shutdown(shutdownTimeoutMs = 30000) {
|
|
669
674
|
if (this.shutdownPromise) this._logger.warn('shutdown() called while already shutting down. shutdown() is meant to be called once before process exit - use flush() for per-request cleanup');
|
|
@@ -15,5 +15,11 @@ export declare const detectBrowser: (user_agent: string, vendor: string | undefi
|
|
|
15
15
|
export declare const detectBrowserVersion: (userAgent: string, vendor: string | undefined) => number | null;
|
|
16
16
|
export declare const detectOS: (user_agent: string) => [string, string];
|
|
17
17
|
export declare const detectDevice: (user_agent: string) => string;
|
|
18
|
-
export declare const detectDeviceType: (user_agent: string
|
|
18
|
+
export declare const detectDeviceType: (user_agent: string, options?: {
|
|
19
|
+
userAgentDataPlatform?: string;
|
|
20
|
+
maxTouchPoints?: number;
|
|
21
|
+
screenWidth?: number;
|
|
22
|
+
screenHeight?: number;
|
|
23
|
+
devicePixelRatio?: number;
|
|
24
|
+
}) => string;
|
|
19
25
|
//# sourceMappingURL=user-agent-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"user-agent-utils.d.ts","sourceRoot":"","sources":["../../src/utils/user-agent-utils.ts"],"names":[],"mappings":"AAqFA;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAa,YAAY,MAAM,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,MA4CvF,CAAA;AAsBD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAAa,WAAW,MAAM,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,IAetG,CAAA;AA0FD,eAAO,MAAM,QAAQ,GAAa,YAAY,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAUrE,CAAA;AAED,eAAO,MAAM,YAAY,GAAa,YAAY,MAAM,KAAG,MAuD1D,CAAA;AAED,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"user-agent-utils.d.ts","sourceRoot":"","sources":["../../src/utils/user-agent-utils.ts"],"names":[],"mappings":"AAqFA;;;;GAIG;AACH,eAAO,MAAM,aAAa,GAAa,YAAY,MAAM,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,MA4CvF,CAAA;AAsBD;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAAa,WAAW,MAAM,EAAE,QAAQ,MAAM,GAAG,SAAS,KAAG,MAAM,GAAG,IAetG,CAAA;AA0FD,eAAO,MAAM,QAAQ,GAAa,YAAY,MAAM,KAAG,CAAC,MAAM,EAAE,MAAM,CAUrE,CAAA;AAED,eAAO,MAAM,YAAY,GAAa,YAAY,MAAM,KAAG,MAuD1D,CAAA;AAED,eAAO,MAAM,gBAAgB,GAC3B,YAAY,MAAM,EAClB,UAAU;IACR,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B,KACA,MA4BF,CAAA"}
|
|
@@ -359,12 +359,17 @@ const detectDevice = function(user_agent) {
|
|
|
359
359
|
else if (new RegExp(TABLET, 'i').test(user_agent) && !new RegExp(TABLET + ' pc', 'i').test(user_agent)) return GENERIC_TABLET;
|
|
360
360
|
else return '';
|
|
361
361
|
};
|
|
362
|
-
const detectDeviceType = function(user_agent) {
|
|
362
|
+
const detectDeviceType = function(user_agent, options) {
|
|
363
363
|
const device = detectDevice(user_agent);
|
|
364
364
|
if (device === IPAD || device === ANDROID_TABLET || 'Kobo' === device || 'Kindle Fire' === device || device === GENERIC_TABLET) return TABLET;
|
|
365
365
|
if (device === NINTENDO || device === XBOX || device === PLAYSTATION || device === OUYA) return 'Console';
|
|
366
366
|
if (device === APPLE_WATCH) return 'Wearable';
|
|
367
367
|
if (device) return MOBILE;
|
|
368
|
+
if (options?.userAgentDataPlatform === 'Android' && (options?.maxTouchPoints ?? 0) > 0) {
|
|
369
|
+
const shortSide = Math.min(options?.screenWidth ?? 0, options?.screenHeight ?? 0);
|
|
370
|
+
const shortSideDp = shortSide / (options?.devicePixelRatio ?? 1);
|
|
371
|
+
return shortSideDp >= 600 ? TABLET : MOBILE;
|
|
372
|
+
}
|
|
368
373
|
return 'Desktop';
|
|
369
374
|
};
|
|
370
375
|
exports.detectBrowser = __webpack_exports__.detectBrowser;
|
|
@@ -327,12 +327,17 @@ const detectDevice = function(user_agent) {
|
|
|
327
327
|
else if (new RegExp(TABLET, 'i').test(user_agent) && !new RegExp(TABLET + ' pc', 'i').test(user_agent)) return GENERIC_TABLET;
|
|
328
328
|
else return '';
|
|
329
329
|
};
|
|
330
|
-
const detectDeviceType = function(user_agent) {
|
|
330
|
+
const detectDeviceType = function(user_agent, options) {
|
|
331
331
|
const device = detectDevice(user_agent);
|
|
332
332
|
if (device === IPAD || device === ANDROID_TABLET || 'Kobo' === device || 'Kindle Fire' === device || device === GENERIC_TABLET) return TABLET;
|
|
333
333
|
if (device === NINTENDO || device === XBOX || device === PLAYSTATION || device === OUYA) return 'Console';
|
|
334
334
|
if (device === APPLE_WATCH) return 'Wearable';
|
|
335
335
|
if (device) return MOBILE;
|
|
336
|
+
if (options?.userAgentDataPlatform === 'Android' && (options?.maxTouchPoints ?? 0) > 0) {
|
|
337
|
+
const shortSide = Math.min(options?.screenWidth ?? 0, options?.screenHeight ?? 0);
|
|
338
|
+
const shortSideDp = shortSide / (options?.devicePixelRatio ?? 1);
|
|
339
|
+
return shortSideDp >= 600 ? TABLET : MOBILE;
|
|
340
|
+
}
|
|
336
341
|
return 'Desktop';
|
|
337
342
|
};
|
|
338
343
|
export { detectBrowser, detectBrowserVersion, detectDevice, detectDeviceType, detectOS };
|
package/package.json
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import { isBuiltin, isPrimitive } from '@/utils'
|
|
1
|
+
import { isBuiltin, isEvent, isPrimitive } from '@/utils'
|
|
2
2
|
import { CoercingContext, ErrorTrackingCoercer, ExceptionLike } from '../types'
|
|
3
3
|
|
|
4
|
+
type EventWithDetailReason = Event & { detail: { reason: unknown } }
|
|
5
|
+
|
|
4
6
|
// Web only
|
|
5
|
-
export class PromiseRejectionEventCoercer implements ErrorTrackingCoercer<
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
export class PromiseRejectionEventCoercer implements ErrorTrackingCoercer<
|
|
8
|
+
PromiseRejectionEvent | EventWithDetailReason
|
|
9
|
+
> {
|
|
10
|
+
match(err: unknown): err is PromiseRejectionEvent | EventWithDetailReason {
|
|
11
|
+
return isBuiltin(err, 'PromiseRejectionEvent') || this.isCustomEventWrappingRejection(err)
|
|
8
12
|
}
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
private isCustomEventWrappingRejection(err: unknown): err is EventWithDetailReason {
|
|
15
|
+
if (!isEvent(err)) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
try {
|
|
19
|
+
const detail = (err as EventWithDetailReason).detail
|
|
20
|
+
return detail != null && typeof detail === 'object' && 'reason' in detail
|
|
21
|
+
} catch {
|
|
22
|
+
return false
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
coerce(err: PromiseRejectionEvent | EventWithDetailReason, ctx: CoercingContext): ExceptionLike | undefined {
|
|
11
27
|
const reason = this.getUnhandledRejectionReason(err)
|
|
12
28
|
if (isPrimitive(reason)) {
|
|
13
29
|
return {
|
|
@@ -21,28 +37,21 @@ export class PromiseRejectionEventCoercer implements ErrorTrackingCoercer<Promis
|
|
|
21
37
|
}
|
|
22
38
|
}
|
|
23
39
|
|
|
24
|
-
private getUnhandledRejectionReason(error:
|
|
25
|
-
if (isPrimitive(error)) {
|
|
26
|
-
return error
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// dig the object of the rejection out of known event types
|
|
40
|
+
private getUnhandledRejectionReason(error: PromiseRejectionEvent | EventWithDetailReason): unknown {
|
|
30
41
|
try {
|
|
31
|
-
type ErrorWithReason = { reason: unknown }
|
|
32
42
|
// PromiseRejectionEvents store the object of the rejection under 'reason'
|
|
33
43
|
// see https://developer.mozilla.org/en-US/docs/Web/API/PromiseRejectionEvent
|
|
34
|
-
if ('reason' in
|
|
35
|
-
return
|
|
44
|
+
if ('reason' in error) {
|
|
45
|
+
return error.reason
|
|
36
46
|
}
|
|
37
47
|
|
|
38
|
-
type CustomEventWithDetail = { detail: { reason: unknown } }
|
|
39
48
|
// something, somewhere, (likely a browser extension) effectively casts PromiseRejectionEvents
|
|
40
49
|
// to CustomEvents, moving the `promise` and `reason` attributes of the PRE into
|
|
41
50
|
// the CustomEvent's `detail` attribute, since they're not part of CustomEvent's spec
|
|
42
51
|
// see https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent and
|
|
43
52
|
// https://github.com/getsentry/sentry-javascript/issues/2380
|
|
44
|
-
if ('detail' in
|
|
45
|
-
return
|
|
53
|
+
if ('detail' in error && error.detail != null && typeof error.detail === 'object' && 'reason' in error.detail) {
|
|
54
|
+
return error.detail.reason
|
|
46
55
|
}
|
|
47
56
|
} catch {
|
|
48
57
|
// no-empty
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
DOMExceptionCoercer,
|
|
3
|
+
ErrorEventCoercer,
|
|
4
|
+
ErrorCoercer,
|
|
5
|
+
ObjectCoercer,
|
|
6
|
+
StringCoercer,
|
|
7
|
+
EventCoercer,
|
|
8
|
+
} from './coercers'
|
|
2
9
|
import { PrimitiveCoercer } from './coercers/primitive-coercer'
|
|
3
10
|
import { PromiseRejectionEventCoercer } from './coercers/promise-rejection-event'
|
|
4
11
|
import { ErrorPropertiesBuilder } from './error-properties-builder'
|
|
@@ -21,6 +28,7 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
21
28
|
new ErrorEventCoercer(),
|
|
22
29
|
new ErrorCoercer(),
|
|
23
30
|
new PromiseRejectionEventCoercer(),
|
|
31
|
+
new EventCoercer(),
|
|
24
32
|
new ObjectCoercer(),
|
|
25
33
|
new StringCoercer(),
|
|
26
34
|
new PrimitiveCoercer(),
|
|
@@ -165,7 +173,7 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
165
173
|
const exception = coerceInput(event, syntheticError)
|
|
166
174
|
expect(exception).toMatchObject({
|
|
167
175
|
type: 'MouseEvent',
|
|
168
|
-
value:
|
|
176
|
+
value: 'MouseEvent captured as exception with keys: [object has no keys]',
|
|
169
177
|
stack: syntheticError.stack,
|
|
170
178
|
synthetic: true,
|
|
171
179
|
})
|
|
@@ -199,5 +207,23 @@ describe('ErrorPropertiesBuilder', () => {
|
|
|
199
207
|
synthetic: false,
|
|
200
208
|
})
|
|
201
209
|
})
|
|
210
|
+
|
|
211
|
+
it('should extract the buried Error from a CustomEvent wrapping a PromiseRejectionEvent', () => {
|
|
212
|
+
const buriedError = new Error('Extension context invalidated.')
|
|
213
|
+
const customEvent = new CustomEvent('unhandledrejection', {
|
|
214
|
+
detail: {
|
|
215
|
+
reason: buriedError,
|
|
216
|
+
promise: Promise.resolve(),
|
|
217
|
+
},
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
const exception = coerceInput(customEvent)
|
|
221
|
+
|
|
222
|
+
expect(exception).toMatchObject({
|
|
223
|
+
type: 'Error',
|
|
224
|
+
value: 'Extension context invalidated.',
|
|
225
|
+
stack: buriedError.stack,
|
|
226
|
+
})
|
|
227
|
+
})
|
|
202
228
|
})
|
|
203
229
|
})
|
|
@@ -462,7 +462,7 @@ export abstract class PostHogCoreStateless {
|
|
|
462
462
|
personProperties: Record<string, string> = {},
|
|
463
463
|
groupProperties: Record<string, Record<string, string>> = {},
|
|
464
464
|
extraPayload: Record<string, any> = {},
|
|
465
|
-
fetchConfig: boolean =
|
|
465
|
+
fetchConfig: boolean = false
|
|
466
466
|
): Promise<GetFlagsResult> {
|
|
467
467
|
await this._initPromise
|
|
468
468
|
|
|
@@ -1174,12 +1174,6 @@ export abstract class PostHogCoreStateless {
|
|
|
1174
1174
|
retryOptions?: Partial<RetriableOptions>,
|
|
1175
1175
|
requestTimeout?: number
|
|
1176
1176
|
): Promise<PostHogFetchResponse> {
|
|
1177
|
-
;(AbortSignal as any).timeout ??= function timeout(ms: number) {
|
|
1178
|
-
const ctrl = new AbortController()
|
|
1179
|
-
setTimeout(() => ctrl.abort(), ms)
|
|
1180
|
-
return ctrl.signal
|
|
1181
|
-
}
|
|
1182
|
-
|
|
1183
1177
|
const body = options.body ? options.body : ''
|
|
1184
1178
|
let reqByteLength = -1
|
|
1185
1179
|
try {
|
|
@@ -1199,15 +1193,21 @@ export abstract class PostHogCoreStateless {
|
|
|
1199
1193
|
|
|
1200
1194
|
return await retriable(
|
|
1201
1195
|
async () => {
|
|
1196
|
+
const ctrl = new AbortController()
|
|
1197
|
+
const timeoutMs = requestTimeout ?? this.requestTimeout
|
|
1198
|
+
const timer = safeSetTimeout(() => ctrl.abort(), timeoutMs)
|
|
1199
|
+
|
|
1202
1200
|
let res: PostHogFetchResponse | null = null
|
|
1203
1201
|
try {
|
|
1204
1202
|
res = await this.fetch(url, {
|
|
1205
|
-
signal:
|
|
1203
|
+
signal: ctrl.signal,
|
|
1206
1204
|
...options,
|
|
1207
1205
|
})
|
|
1208
1206
|
} catch (e) {
|
|
1209
1207
|
// fetch will only throw on network errors or on timeouts
|
|
1210
1208
|
throw new PostHogFetchNetworkError(e)
|
|
1209
|
+
} finally {
|
|
1210
|
+
clearTimeout(timer)
|
|
1211
1211
|
}
|
|
1212
1212
|
// If we're in no-cors mode, we can't access the response status
|
|
1213
1213
|
// We only throw on HTTP errors if we're not in no-cors mode
|
|
@@ -1259,16 +1259,21 @@ export abstract class PostHogCoreStateless {
|
|
|
1259
1259
|
}
|
|
1260
1260
|
}
|
|
1261
1261
|
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1262
|
+
let timeoutHandle: ReturnType<typeof safeSetTimeout> | undefined
|
|
1263
|
+
try {
|
|
1264
|
+
return await Promise.race([
|
|
1265
|
+
new Promise<void>((_, reject) => {
|
|
1266
|
+
timeoutHandle = safeSetTimeout(() => {
|
|
1267
|
+
this._logger.error('Timed out while shutting down PostHog')
|
|
1268
|
+
hasTimedOut = true
|
|
1269
|
+
reject('Timeout while shutting down PostHog. Some events may not have been sent.')
|
|
1270
|
+
}, shutdownTimeoutMs)
|
|
1271
|
+
}),
|
|
1272
|
+
doShutdown(),
|
|
1273
|
+
])
|
|
1274
|
+
} finally {
|
|
1275
|
+
clearTimeout(timeoutHandle)
|
|
1276
|
+
}
|
|
1272
1277
|
}
|
|
1273
1278
|
|
|
1274
1279
|
/**
|
|
@@ -336,7 +336,16 @@ export const detectDevice = function (user_agent: string): string {
|
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
338
|
|
|
339
|
-
export const detectDeviceType = function (
|
|
339
|
+
export const detectDeviceType = function (
|
|
340
|
+
user_agent: string,
|
|
341
|
+
options?: {
|
|
342
|
+
userAgentDataPlatform?: string
|
|
343
|
+
maxTouchPoints?: number
|
|
344
|
+
screenWidth?: number
|
|
345
|
+
screenHeight?: number
|
|
346
|
+
devicePixelRatio?: number
|
|
347
|
+
}
|
|
348
|
+
): string {
|
|
340
349
|
const device = detectDevice(user_agent)
|
|
341
350
|
if (
|
|
342
351
|
device === IPAD ||
|
|
@@ -352,7 +361,16 @@ export const detectDeviceType = function (user_agent: string): string {
|
|
|
352
361
|
return 'Wearable'
|
|
353
362
|
} else if (device) {
|
|
354
363
|
return MOBILE
|
|
355
|
-
} else {
|
|
356
|
-
return 'Desktop'
|
|
357
364
|
}
|
|
365
|
+
|
|
366
|
+
// Chrome on Android tablets defaults to "request desktop site" mode, sending
|
|
367
|
+
// a desktop-like UA (e.g. "X11; Linux x86_64") indistinguishable from desktop Linux.
|
|
368
|
+
// The Client Hints API reports the true platform even when the UA lies.
|
|
369
|
+
if (options?.userAgentDataPlatform === 'Android' && (options?.maxTouchPoints ?? 0) > 0) {
|
|
370
|
+
const shortSide = Math.min(options?.screenWidth ?? 0, options?.screenHeight ?? 0)
|
|
371
|
+
const shortSideDp = shortSide / (options?.devicePixelRatio ?? 1)
|
|
372
|
+
return shortSideDp >= 600 ? TABLET : MOBILE
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return 'Desktop'
|
|
358
376
|
}
|