@posthog/core 1.52.0 → 1.52.2
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/index.d.ts +1 -1
- package/dist/error-tracking/index.d.ts.map +1 -1
- package/dist/error-tracking/parsers/base.d.ts.map +1 -1
- package/dist/error-tracking/parsers/base.js +19 -2
- package/dist/error-tracking/parsers/base.mjs +19 -2
- package/package.json +2 -2
- package/src/error-tracking/index.ts +24 -1
- package/src/error-tracking/parsers/base.spec.ts +77 -7
- package/src/error-tracking/parsers/base.ts +42 -19
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export * from './error-properties-builder';
|
|
2
|
-
export type
|
|
2
|
+
export type { severityLevels, SeverityLevel, PolymorphicEvent, EventHint, PreviouslyCapturedError, ErrorProperties, Exception, ExceptionList, Mechanism, GetModuleFn, StackParser, StackLineParser, StackFrameModifierFn, Platform, StackFrame, CoercingContext, ChunkIdMapType, ParsingContext, ErrorTrackingCoercer, ExceptionLike, ParsedException, } from './types';
|
|
3
3
|
export * from './parsers';
|
|
4
4
|
export * from './coercers';
|
|
5
5
|
export * from './utils';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error-tracking/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/error-tracking/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAE1C,YAAY,EACV,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,uBAAuB,EACvB,eAAe,EACf,SAAS,EACT,aAAa,EACb,SAAS,EACT,WAAW,EACX,WAAW,EACX,eAAe,EACf,oBAAoB,EACpB,QAAQ,EACR,UAAU,EACV,eAAe,EACf,cAAc,EACd,cAAc,EACd,oBAAoB,EACpB,aAAa,EACb,eAAe,GAChB,MAAM,SAAS,CAAA;AAChB,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,SAAS,CAAA;AACvB,cAAc,mBAAmB,CAAA;AACjC,cAAc,WAAW,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/base.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,eAAO,MAAM,gBAAgB,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../../src/error-tracking/parsers/base.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAErC,eAAO,MAAM,gBAAgB,MAAM,CAAA;AA2CnC,wBAAgB,WAAW,CACzB,QAAQ,EAAE,UAAU,CAAC,UAAU,CAAC,EAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,MAAM,CAAC,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACb,UAAU,CAoBZ"}
|
|
@@ -33,14 +33,31 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
33
33
|
});
|
|
34
34
|
const index_js_namespaceObject = require("../../utils/index.js");
|
|
35
35
|
const UNKNOWN_FUNCTION = '?';
|
|
36
|
-
const MASKED_URL_PREFIX = 'webkit-masked-url://';
|
|
37
36
|
const ANONYMOUS_FILENAME = '<anonymous>';
|
|
37
|
+
const URL_SCHEME = /^([a-z][a-z0-9.+-]+):/i;
|
|
38
|
+
const APP_URL_SCHEMES = [
|
|
39
|
+
'http',
|
|
40
|
+
'https',
|
|
41
|
+
'file',
|
|
42
|
+
'blob',
|
|
43
|
+
'app',
|
|
44
|
+
'capacitor',
|
|
45
|
+
'ionic',
|
|
46
|
+
'webpack',
|
|
47
|
+
'webpack-internal',
|
|
48
|
+
'ng'
|
|
49
|
+
];
|
|
50
|
+
function isAppFilename(filename) {
|
|
51
|
+
if (!filename || filename === ANONYMOUS_FILENAME) return false;
|
|
52
|
+
const scheme = URL_SCHEME.exec(filename);
|
|
53
|
+
return !scheme || APP_URL_SCHEMES.includes(scheme[1].toLowerCase());
|
|
54
|
+
}
|
|
38
55
|
function createFrame(platform, filename, func, lineno, colno) {
|
|
39
56
|
const frame = {
|
|
40
57
|
platform,
|
|
41
58
|
filename,
|
|
42
59
|
function: '<anonymous>' === func ? UNKNOWN_FUNCTION : func,
|
|
43
|
-
in_app:
|
|
60
|
+
in_app: isAppFilename(filename)
|
|
44
61
|
};
|
|
45
62
|
if (!(0, index_js_namespaceObject.isUndefined)(lineno)) frame.lineno = lineno;
|
|
46
63
|
if (!(0, index_js_namespaceObject.isUndefined)(colno)) frame.colno = colno;
|
|
@@ -1,13 +1,30 @@
|
|
|
1
1
|
import { isUndefined } from "../../utils/index.mjs";
|
|
2
2
|
const UNKNOWN_FUNCTION = '?';
|
|
3
|
-
const MASKED_URL_PREFIX = 'webkit-masked-url://';
|
|
4
3
|
const ANONYMOUS_FILENAME = '<anonymous>';
|
|
4
|
+
const URL_SCHEME = /^([a-z][a-z0-9.+-]+):/i;
|
|
5
|
+
const APP_URL_SCHEMES = [
|
|
6
|
+
'http',
|
|
7
|
+
'https',
|
|
8
|
+
'file',
|
|
9
|
+
'blob',
|
|
10
|
+
'app',
|
|
11
|
+
'capacitor',
|
|
12
|
+
'ionic',
|
|
13
|
+
'webpack',
|
|
14
|
+
'webpack-internal',
|
|
15
|
+
'ng'
|
|
16
|
+
];
|
|
17
|
+
function isAppFilename(filename) {
|
|
18
|
+
if (!filename || filename === ANONYMOUS_FILENAME) return false;
|
|
19
|
+
const scheme = URL_SCHEME.exec(filename);
|
|
20
|
+
return !scheme || APP_URL_SCHEMES.includes(scheme[1].toLowerCase());
|
|
21
|
+
}
|
|
5
22
|
function createFrame(platform, filename, func, lineno, colno) {
|
|
6
23
|
const frame = {
|
|
7
24
|
platform,
|
|
8
25
|
filename,
|
|
9
26
|
function: '<anonymous>' === func ? UNKNOWN_FUNCTION : func,
|
|
10
|
-
in_app:
|
|
27
|
+
in_app: isAppFilename(filename)
|
|
11
28
|
};
|
|
12
29
|
if (!isUndefined(lineno)) frame.lineno = lineno;
|
|
13
30
|
if (!isUndefined(colno)) frame.colno = colno;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@posthog/core",
|
|
3
|
-
"version": "1.52.
|
|
3
|
+
"version": "1.52.2",
|
|
4
4
|
"bugs": {
|
|
5
5
|
"url": "https://github.com/PostHog/posthog-js/issues"
|
|
6
6
|
},
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
}
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
-
"@posthog/types": "^1.
|
|
73
|
+
"@posthog/types": "^1.410.1"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"@rslib/core": "0.23.2",
|
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
export * from './error-properties-builder'
|
|
2
|
-
|
|
2
|
+
// Named type exports keep this barrel compatible with TypeScript 4.7.
|
|
3
|
+
export type {
|
|
4
|
+
severityLevels,
|
|
5
|
+
SeverityLevel,
|
|
6
|
+
PolymorphicEvent,
|
|
7
|
+
EventHint,
|
|
8
|
+
PreviouslyCapturedError,
|
|
9
|
+
ErrorProperties,
|
|
10
|
+
Exception,
|
|
11
|
+
ExceptionList,
|
|
12
|
+
Mechanism,
|
|
13
|
+
GetModuleFn,
|
|
14
|
+
StackParser,
|
|
15
|
+
StackLineParser,
|
|
16
|
+
StackFrameModifierFn,
|
|
17
|
+
Platform,
|
|
18
|
+
StackFrame,
|
|
19
|
+
CoercingContext,
|
|
20
|
+
ChunkIdMapType,
|
|
21
|
+
ParsingContext,
|
|
22
|
+
ErrorTrackingCoercer,
|
|
23
|
+
ExceptionLike,
|
|
24
|
+
ParsedException,
|
|
25
|
+
} from './types'
|
|
3
26
|
export * from './parsers'
|
|
4
27
|
export * from './coercers'
|
|
5
28
|
export * from './utils'
|
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
import { createFrame } from './base'
|
|
2
2
|
import { createDefaultStackParser } from './index'
|
|
3
3
|
|
|
4
|
-
describe('createFrame', () => {
|
|
5
|
-
const platform = 'web:javascript'
|
|
6
|
-
|
|
4
|
+
describe.each(['web:javascript', 'hermes'] as const)('createFrame (%s)', (platform) => {
|
|
7
5
|
it('marks ordinary browser frames as in_app', () => {
|
|
8
6
|
const frame = createFrame(platform, 'https://example.com/app.js', 'doThing', 1, 2)
|
|
9
7
|
expect(frame.in_app).toBe(true)
|
|
10
8
|
})
|
|
11
9
|
|
|
12
|
-
it(
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
it.each([
|
|
11
|
+
['Safari masking an extension content script', 'webkit-masked-url://hidden/'],
|
|
12
|
+
['an Android in-app browser bridge', 'iabjs://navigation_performance_logger_android'],
|
|
13
|
+
['a Chromium extension content script', 'chrome-extension://abcdef/content.js'],
|
|
14
|
+
['a Firefox extension content script', 'moz-extension://abcdef/content.js'],
|
|
15
|
+
['a Safari extension, which the parser prefixes with a bare scheme', 'safari-extension:abcdef/content.js'],
|
|
16
|
+
['a Safari web extension', 'safari-web-extension:abcdef/content.js'],
|
|
17
|
+
['an extension with a mixed-case scheme', 'CHROME-Extension://abcdef/content.js'],
|
|
18
|
+
['an unknown container scheme', 'other-bridge://injected.js'],
|
|
19
|
+
['an inline data URL', 'data:text/javascript,void 0'],
|
|
20
|
+
])('does not mark a frame the container injected as in_app: %s', (_name, filename) => {
|
|
21
|
+
const frame = createFrame(platform, filename, 'doThing', 1, 2)
|
|
16
22
|
expect(frame.in_app).toBe(false)
|
|
17
23
|
})
|
|
18
24
|
|
|
25
|
+
it.each([
|
|
26
|
+
['a script served over http', 'http://localhost:8000/app.js'],
|
|
27
|
+
['a Cordova or Electron app served from disk', 'file:///android_asset/www/app.js'],
|
|
28
|
+
['a worker the page created from a blob', 'blob:https://example.com/6b0b0e6a'],
|
|
29
|
+
['a Capacitor webview', 'capacitor://localhost/app.js'],
|
|
30
|
+
['an Ionic webview', 'ionic://localhost/app.js'],
|
|
31
|
+
['a script with a mixed-case scheme', 'HTTPS://example.com/app.js'],
|
|
32
|
+
['a webpack source frame', 'webpack:///./src/App.js'],
|
|
33
|
+
['an Angular JIT component', 'ng:///CheckoutComponent.js'],
|
|
34
|
+
['a custom app scheme, as an Electron or React Native shell serves', 'app://checkout.js'],
|
|
35
|
+
['a bundler-rewritten dev frame', 'webpack-internal:///./src/App.js'],
|
|
36
|
+
['a React Native release bundle, which has no scheme', 'index.android.bundle'],
|
|
37
|
+
['an absolute path with no scheme', '/data/user/0/com.example/files/index.bundle'],
|
|
38
|
+
['a Windows path with backslashes', 'C:\\app\\index.bundle'],
|
|
39
|
+
['a Windows path with forward slashes', 'C:/app/index.bundle'],
|
|
40
|
+
])("still marks the app's own code as in_app: %s", (_name, filename) => {
|
|
41
|
+
const frame = createFrame(platform, filename, 'doThing', 1, 2)
|
|
42
|
+
expect(frame.in_app).toBe(true)
|
|
43
|
+
})
|
|
44
|
+
|
|
19
45
|
it('keeps the masked frame rather than discarding it', () => {
|
|
20
46
|
const frame = createFrame(platform, 'webkit-masked-url://hidden/', 'someFn', 3, 4)
|
|
21
47
|
expect(frame).toMatchObject({
|
|
@@ -70,6 +96,50 @@ describe('createDefaultStackParser in_app classification', () => {
|
|
|
70
96
|
])
|
|
71
97
|
})
|
|
72
98
|
|
|
99
|
+
it('demotes the bridge frames an Android in-app browser serves from its own scheme', () => {
|
|
100
|
+
const frames = parse(
|
|
101
|
+
'Error: Error invoking postMessage: Java object is gone\n' +
|
|
102
|
+
' at sendDataToNative (iabjs://navigation_performance_logger_android:1:10198)\n' +
|
|
103
|
+
' at sendJsBlockingTimeMessage (iabjs://navigation_performance_logger_android:1:14668)'
|
|
104
|
+
)
|
|
105
|
+
expect(frames.map((f) => [f.function, f.in_app])).toEqual([
|
|
106
|
+
['sendJsBlockingTimeMessage', false],
|
|
107
|
+
['sendDataToNative', false],
|
|
108
|
+
])
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it.each([
|
|
112
|
+
' at CheckoutComponent_Template (ng:///CheckoutComponent.js:10:5)',
|
|
113
|
+
'CheckoutComponent_Template@ng:///CheckoutComponent.js:10:5',
|
|
114
|
+
])('keeps Angular JIT application frames as in_app: %s', (stackLine) => {
|
|
115
|
+
const frames = parse(`Error: template failed\n${stackLine}`)
|
|
116
|
+
expect(frames).toEqual([
|
|
117
|
+
expect.objectContaining({
|
|
118
|
+
filename: 'ng:///CheckoutComponent.js',
|
|
119
|
+
function: 'CheckoutComponent_Template',
|
|
120
|
+
lineno: 10,
|
|
121
|
+
colno: 5,
|
|
122
|
+
in_app: true,
|
|
123
|
+
}),
|
|
124
|
+
])
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it.each([
|
|
128
|
+
'webkit-masked-url://hidden/',
|
|
129
|
+
'<anonymous>',
|
|
130
|
+
'iabjs://navigation_performance_logger_android',
|
|
131
|
+
'chrome-extension://abcdef/content.js',
|
|
132
|
+
'moz-extension://abcdef/content.js',
|
|
133
|
+
])('retains injected frames without demoting the calling app frame: %s', (filename) => {
|
|
134
|
+
const frames = parse(
|
|
135
|
+
`Error: boom\n at injected (${filename}:1:2)\n at checkout (https://example.com/app.js:10:5)`
|
|
136
|
+
)
|
|
137
|
+
expect(frames.map((frame) => [frame.filename, frame.in_app])).toEqual([
|
|
138
|
+
['https://example.com/app.js', true],
|
|
139
|
+
[filename, false],
|
|
140
|
+
])
|
|
141
|
+
})
|
|
142
|
+
|
|
73
143
|
it("keeps the page's own eval'd code as in_app", () => {
|
|
74
144
|
// V8 attributes eval'd code to the script that called eval; the chrome parser already
|
|
75
145
|
// rewrites these frames to that URL, so they must not be caught by the <anonymous> rule.
|
|
@@ -7,21 +7,47 @@ import { StackFrame } from '../types'
|
|
|
7
7
|
|
|
8
8
|
export const UNKNOWN_FUNCTION = '?'
|
|
9
9
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
const MASKED_URL_PREFIX = 'webkit-masked-url://'
|
|
16
|
-
|
|
17
|
-
// Chromium's counterpart: a script with no URL at all -- code injected by an extension
|
|
18
|
-
// (`chrome.scripting.executeScript`), pasted into devtools, or evaluated from a string -- shows
|
|
19
|
-
// up as a bare `<anonymous>:line:col` frame. The page's own eval'd code is *not* affected: V8
|
|
20
|
-
// reports it as `eval at <anonymous> (https://site/app.js:1:2)` and the chrome parser already
|
|
21
|
-
// rewrites that to the site URL. A bare `<anonymous>` can never be symbolicated, so treating it
|
|
22
|
-
// as in_app only ever pulled an unresolvable frame into the site's own stack.
|
|
10
|
+
// Chromium reports a script with no URL at all -- code injected by an extension
|
|
11
|
+
// (`chrome.scripting.executeScript`), pasted into devtools, or evaluated from a string -- as a bare
|
|
12
|
+
// `<anonymous>:line:col` frame. The page's own eval'd code is *not* affected: V8 reports it as
|
|
13
|
+
// `eval at <anonymous> (https://site/app.js:1:2)` and the chrome parser already rewrites that to
|
|
14
|
+
// the site URL. A bare `<anonymous>` can never be symbolicated.
|
|
23
15
|
const ANONYMOUS_FILENAME = '<anonymous>'
|
|
24
16
|
|
|
17
|
+
// A leading `scheme:` in a filename, needing two characters or more so that a Windows drive letter
|
|
18
|
+
// such as `C:` does not read as one.
|
|
19
|
+
const URL_SCHEME = /^([a-z][a-z0-9.+-]+):/i
|
|
20
|
+
|
|
21
|
+
// The schemes an app is served over. Everything else names code the container put into the page
|
|
22
|
+
// rather than code the app loaded: Safari masks extension content scripts as `webkit-masked-url://`,
|
|
23
|
+
// Chromium serves them from `chrome-extension://`, and Android in-app browsers serve their native
|
|
24
|
+
// bridge from schemes such as `iabjs://`. Listing every injector's scheme never keeps up with the
|
|
25
|
+
// next one, so accept the schemes an app is served over and reject the rest.
|
|
26
|
+
const APP_URL_SCHEMES = [
|
|
27
|
+
'http',
|
|
28
|
+
'https',
|
|
29
|
+
'file',
|
|
30
|
+
'blob',
|
|
31
|
+
'app',
|
|
32
|
+
'capacitor',
|
|
33
|
+
'ionic',
|
|
34
|
+
'webpack',
|
|
35
|
+
'webpack-internal',
|
|
36
|
+
'ng',
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
// Is this filename a script the app itself loaded? A filename with no scheme is one: React Native
|
|
40
|
+
// names its own bundle `index.android.bundle`, and a bundler can report a bare path.
|
|
41
|
+
function isAppFilename(filename: string): boolean {
|
|
42
|
+
if (!filename || filename === ANONYMOUS_FILENAME) {
|
|
43
|
+
return false
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const scheme = URL_SCHEME.exec(filename)
|
|
47
|
+
|
|
48
|
+
return !scheme || APP_URL_SCHEMES.includes((scheme[1] as string).toLowerCase())
|
|
49
|
+
}
|
|
50
|
+
|
|
25
51
|
export function createFrame(
|
|
26
52
|
platform: StackFrame['platform'],
|
|
27
53
|
filename: string,
|
|
@@ -34,12 +60,9 @@ export function createFrame(
|
|
|
34
60
|
platform,
|
|
35
61
|
filename,
|
|
36
62
|
function: func === '<anonymous>' ? UNKNOWN_FUNCTION : func,
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
// bridge scripts this way. Such a frame can never be symbolicated either, so it must not
|
|
41
|
-
// count as the page's own code.
|
|
42
|
-
in_app: !!filename && !filename.startsWith(MASKED_URL_PREFIX) && filename !== ANONYMOUS_FILENAME,
|
|
63
|
+
// Keep a frame the app did not load -- it is still useful context -- but do not let it count as
|
|
64
|
+
// in_app and pull the issue into the app's own stack.
|
|
65
|
+
in_app: isAppFilename(filename),
|
|
43
66
|
}
|
|
44
67
|
|
|
45
68
|
if (!isUndefined(lineno)) {
|