@cloudcare/browser-core 1.1.2 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/{cookie.js → browser/cookie.js} +6 -37
- package/cjs/browser/fetchObservable.js +91 -0
- package/cjs/browser/xhrObservable.js +118 -0
- package/cjs/configuration/configuration.js +70 -0
- package/cjs/configuration/transportConfiguration.js +64 -0
- package/cjs/console/consoleObservable.js +84 -0
- package/cjs/dataMap.js +26 -21
- package/cjs/error/trackRuntimeError.js +27 -0
- package/cjs/helper/catchUserErrors.js +20 -0
- package/cjs/helper/contextHistory.js +134 -0
- package/cjs/helper/createEventRateLimiter.js +47 -0
- package/cjs/helper/deviceInfo.js +8 -25
- package/cjs/helper/display.js +31 -0
- package/cjs/helper/enums.js +28 -2
- package/cjs/helper/errorTools.js +63 -2
- package/cjs/helper/instrumentMethod.js +93 -0
- package/cjs/helper/lifeCycle.js +5 -3
- package/cjs/helper/observable.js +40 -2
- package/cjs/helper/tools.js +217 -11
- package/cjs/index.js +153 -23
- package/cjs/init.js +17 -27
- package/cjs/report/reportObservable.js +112 -0
- package/cjs/session/sessionConstants.js +13 -0
- package/cjs/session/sessionCookieStore.js +188 -0
- package/cjs/session/sessionManagement.js +96 -0
- package/cjs/session/sessionStore.js +150 -0
- package/cjs/synthetics/syntheticsWorkerValues.js +32 -0
- package/cjs/synthetics/usr.js +32 -0
- package/cjs/tracekit/computeStackTrace.js +73 -563
- package/cjs/tracekit/index.js +3 -15
- package/cjs/tracekit/tracekit.js +113 -0
- package/cjs/transport/batch.js +332 -0
- package/cjs/transport/httpRequest.js +112 -0
- package/cjs/transport/index.js +29 -0
- package/cjs/transport/sendWithRetryStrategy.js +177 -0
- package/cjs/transport/startBatchWithReplica.js +24 -0
- package/esm/{cookie.js → browser/cookie.js} +4 -35
- package/esm/browser/fetchObservable.js +77 -0
- package/esm/browser/xhrObservable.js +106 -0
- package/esm/configuration/configuration.js +55 -0
- package/esm/configuration/transportConfiguration.js +54 -0
- package/esm/console/consoleObservable.js +70 -0
- package/esm/dataMap.js +26 -21
- package/esm/error/trackRuntimeError.js +16 -0
- package/esm/helper/catchUserErrors.js +12 -0
- package/esm/helper/contextHistory.js +106 -0
- package/esm/helper/createEventRateLimiter.js +38 -0
- package/esm/helper/deviceInfo.js +6 -25
- package/esm/helper/display.js +21 -0
- package/esm/helper/enums.js +25 -1
- package/esm/helper/errorTools.js +58 -3
- package/esm/helper/instrumentMethod.js +81 -0
- package/esm/helper/lifeCycle.js +5 -3
- package/esm/helper/observable.js +39 -3
- package/esm/helper/tools.js +173 -3
- package/esm/index.js +17 -7
- package/esm/init.js +17 -22
- package/esm/report/reportObservable.js +98 -0
- package/esm/session/sessionConstants.js +3 -0
- package/esm/session/sessionCookieStore.js +168 -0
- package/esm/session/sessionManagement.js +78 -0
- package/esm/session/sessionStore.js +139 -0
- package/esm/synthetics/syntheticsWorkerValues.js +15 -0
- package/esm/synthetics/usr.js +18 -0
- package/esm/tracekit/computeStackTrace.js +73 -557
- package/esm/tracekit/index.js +1 -1
- package/esm/tracekit/tracekit.js +103 -0
- package/esm/transport/batch.js +316 -0
- package/esm/transport/httpRequest.js +104 -0
- package/esm/transport/index.js +3 -0
- package/esm/transport/sendWithRetryStrategy.js +165 -0
- package/esm/transport/startBatchWithReplica.js +15 -0
- package/package.json +2 -2
- package/src/.DS_Store +0 -0
- package/src/{cookie.js → browser/cookie.js} +6 -34
- package/src/browser/fetchObservable.js +86 -0
- package/src/browser/xhrObservable.js +102 -0
- package/src/configuration/configuration.js +61 -0
- package/src/configuration/transportConfiguration.js +42 -0
- package/src/console/consoleObservable.js +65 -0
- package/src/dataMap.js +26 -21
- package/src/error/trackRuntimeError.js +19 -0
- package/src/helper/catchUserErrors.js +12 -0
- package/src/helper/contextHistory.js +85 -0
- package/src/helper/createEventRateLimiter.js +37 -0
- package/src/helper/deviceInfo.js +5 -51
- package/src/helper/display.js +21 -0
- package/src/helper/enums.js +38 -14
- package/src/helper/errorTools.js +76 -12
- package/src/helper/instrumentMethod.js +97 -0
- package/src/helper/lifeCycle.js +5 -3
- package/src/helper/observable.js +33 -2
- package/src/helper/tools.js +159 -5
- package/src/index.js +18 -7
- package/src/init.js +17 -18
- package/src/report/reportObservable.js +113 -0
- package/src/session/sessionConstants.js +3 -0
- package/src/session/sessionCookieStore.js +159 -0
- package/src/session/sessionManagement.js +89 -0
- package/src/session/sessionStore.js +139 -0
- package/src/synthetics/syntheticsWorkerValues.js +22 -0
- package/src/synthetics/usr.js +18 -0
- package/src/tracekit/computeStackTrace.js +75 -551
- package/src/tracekit/index.js +1 -1
- package/src/tracekit/tracekit.js +100 -0
- package/src/transport/batch.js +289 -0
- package/src/transport/httpRequest.js +109 -0
- package/src/transport/index.js +3 -0
- package/src/transport/sendWithRetryStrategy.js +186 -0
- package/src/transport/startBatchWithReplica.js +26 -0
- package/cjs/configuration.js +0 -184
- package/cjs/errorCollection.js +0 -167
- package/cjs/fetchProxy.js +0 -162
- package/cjs/helper/errorFilter.js +0 -47
- package/cjs/sessionManagement.js +0 -221
- package/cjs/tracekit/report.js +0 -289
- package/cjs/transport.js +0 -373
- package/cjs/xhrProxy.js +0 -122
- package/esm/configuration.js +0 -167
- package/esm/errorCollection.js +0 -141
- package/esm/fetchProxy.js +0 -116
- package/esm/helper/errorFilter.js +0 -38
- package/esm/sessionManagement.js +0 -195
- package/esm/tracekit/report.js +0 -273
- package/esm/transport.js +0 -357
- package/esm/xhrProxy.js +0 -110
- package/src/configuration.js +0 -156
- package/src/errorCollection.js +0 -170
- package/src/fetchProxy.js +0 -109
- package/src/helper/errorFilter.js +0 -38
- package/src/sessionManagement.js +0 -224
- package/src/tracekit/report.js +0 -284
- package/src/transport.js +0 -380
- package/src/xhrProxy.js +0 -106
|
@@ -1,575 +1,132 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { each } from '../helper/tools';
|
|
2
2
|
var UNKNOWN_FUNCTION = '?';
|
|
3
|
-
/**
|
|
4
|
-
* computeStackTrace: cross-browser stack traces in JavaScript
|
|
5
|
-
*
|
|
6
|
-
* Syntax:
|
|
7
|
-
* ```js
|
|
8
|
-
* s = computeStackTraceOfCaller([depth])
|
|
9
|
-
* s = computeStackTrace(exception) // consider using report instead (see below)
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* Supports:
|
|
13
|
-
* - Firefox: full stack trace with line numbers and unreliable column
|
|
14
|
-
* number on top frame
|
|
15
|
-
* - Opera 10: full stack trace with line and column numbers
|
|
16
|
-
* - Opera 9-: full stack trace with line numbers
|
|
17
|
-
* - Chrome: full stack trace with line and column numbers
|
|
18
|
-
* - Safari: line and column number for the topmost stacktrace element
|
|
19
|
-
* only
|
|
20
|
-
* - IE: no line numbers whatsoever
|
|
21
|
-
*
|
|
22
|
-
* Tries to guess names of anonymous functions by looking for assignments
|
|
23
|
-
* in the source code. In IE and Safari, we have to guess source file names
|
|
24
|
-
* by searching for function bodies inside all page scripts. This will not
|
|
25
|
-
* work for scripts that are loaded cross-domain.
|
|
26
|
-
* Here be dragons: some function names may be guessed incorrectly, and
|
|
27
|
-
* duplicate functions may be mismatched.
|
|
28
|
-
*
|
|
29
|
-
* computeStackTrace should only be used for tracing purposes.
|
|
30
|
-
* Logging of unhandled exceptions should be done with report,
|
|
31
|
-
* which builds on top of computeStackTrace and provides better
|
|
32
|
-
* IE support by utilizing the window.onerror event to retrieve information
|
|
33
|
-
* about the top of the stack.
|
|
34
|
-
*
|
|
35
|
-
* Note: In IE and Safari, no stack trace is recorded on the Error object,
|
|
36
|
-
* so computeStackTrace instead walks its *own* chain of callers.
|
|
37
|
-
* This means that:
|
|
38
|
-
* * in Safari, some methods may be missing from the stack trace;
|
|
39
|
-
* * in IE, the topmost function in the stack trace will always be the
|
|
40
|
-
* caller of computeStackTrace.
|
|
41
|
-
*
|
|
42
|
-
* This is okay for tracing (because you are likely to be calling
|
|
43
|
-
* computeStackTrace from the function you want to be the topmost element
|
|
44
|
-
* of the stack trace anyway), but not okay for logging unhandled
|
|
45
|
-
* exceptions (because your catch block will likely be far away from the
|
|
46
|
-
* inner function that actually caused the exception).
|
|
47
|
-
*
|
|
48
|
-
* Tracing example:
|
|
49
|
-
* ```js
|
|
50
|
-
* function trace(message) {
|
|
51
|
-
* let stackInfo = computeStackTrace.ofCaller();
|
|
52
|
-
* let data = message + "\n";
|
|
53
|
-
* for(let i in stackInfo.stack) {
|
|
54
|
-
* let item = stackInfo.stack[i];
|
|
55
|
-
* data += (item.func || '[anonymous]') + "() in " + item.url + ":" + (item.line || '0') + "\n";
|
|
56
|
-
* }
|
|
57
|
-
* if (window.console)
|
|
58
|
-
* console.info(data);
|
|
59
|
-
* else
|
|
60
|
-
* alert(data);
|
|
61
|
-
* }
|
|
62
|
-
* ```
|
|
63
|
-
* @memberof TraceKit
|
|
64
|
-
* @namespace
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
3
|
/**
|
|
68
4
|
* Computes a stack trace for an exception.
|
|
69
|
-
* @param {Error} ex
|
|
70
|
-
* @param {(string|number)=} depth
|
|
71
|
-
* @memberof computeStackTrace
|
|
72
5
|
*/
|
|
73
6
|
|
|
74
|
-
export function computeStackTrace(ex
|
|
75
|
-
var stack;
|
|
76
|
-
var
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
// This must be tried first because Opera 10 *destroys*
|
|
80
|
-
// its stacktrace property if you try to access the stack
|
|
81
|
-
// property first!!
|
|
82
|
-
stack = computeStackTraceFromStacktraceProp(ex);
|
|
83
|
-
|
|
84
|
-
if (stack) {
|
|
85
|
-
return stack;
|
|
86
|
-
}
|
|
87
|
-
} catch (e) {
|
|
88
|
-
if (debug) {
|
|
89
|
-
throw e;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
stack = computeStackTraceFromStackProp(ex);
|
|
95
|
-
|
|
96
|
-
if (stack) {
|
|
97
|
-
return stack;
|
|
98
|
-
}
|
|
99
|
-
} catch (e) {
|
|
100
|
-
if (debug) {
|
|
101
|
-
throw e;
|
|
102
|
-
}
|
|
103
|
-
}
|
|
7
|
+
export function computeStackTrace(ex) {
|
|
8
|
+
var stack = [];
|
|
9
|
+
var stackProperty = tryToGetString(ex, 'stack');
|
|
104
10
|
|
|
105
|
-
|
|
106
|
-
|
|
11
|
+
if (stackProperty) {
|
|
12
|
+
each(stackProperty.split('\n'), function (line) {
|
|
13
|
+
var stackFrame = parseChromeLine(line) || parseChromeAnonymousLine(line) || parseWinLine(line) || parseGeckoLine(line);
|
|
107
14
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (debug) {
|
|
113
|
-
throw e;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
try {
|
|
118
|
-
stack = computeStackTraceByWalkingCallerChain(ex, normalizedDepth + 1);
|
|
15
|
+
if (stackFrame) {
|
|
16
|
+
if (!stackFrame.func && stackFrame.line) {
|
|
17
|
+
stackFrame.func = UNKNOWN_FUNCTION;
|
|
18
|
+
}
|
|
119
19
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
} catch (e) {
|
|
124
|
-
if (debug) {
|
|
125
|
-
throw e;
|
|
126
|
-
}
|
|
20
|
+
stack.push(stackFrame);
|
|
21
|
+
}
|
|
22
|
+
});
|
|
127
23
|
}
|
|
128
24
|
|
|
129
25
|
return {
|
|
130
26
|
message: tryToGetString(ex, 'message'),
|
|
131
27
|
name: tryToGetString(ex, 'name'),
|
|
132
|
-
stack:
|
|
28
|
+
stack: stack
|
|
133
29
|
};
|
|
134
30
|
}
|
|
135
|
-
var
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// ex.line = 59
|
|
140
|
-
// ex.sourceId = 580238192
|
|
141
|
-
// ex.sourceURL = http://...
|
|
142
|
-
// ex.expressionBeginOffset = 96
|
|
143
|
-
// ex.expressionCaretOffset = 98
|
|
144
|
-
// ex.expressionEndOffset = 98
|
|
145
|
-
// ex.name = ReferenceError
|
|
146
|
-
//
|
|
147
|
-
// FIREFOX:
|
|
148
|
-
// ex.message = qq is not defined
|
|
149
|
-
// ex.fileName = http://...
|
|
150
|
-
// ex.lineNumber = 59
|
|
151
|
-
// ex.columnNumber = 69
|
|
152
|
-
// ex.stack = ...stack trace... (see the example below)
|
|
153
|
-
// ex.name = ReferenceError
|
|
154
|
-
//
|
|
155
|
-
// CHROME:
|
|
156
|
-
// ex.message = qq is not defined
|
|
157
|
-
// ex.name = ReferenceError
|
|
158
|
-
// ex.type = not_defined
|
|
159
|
-
// ex.arguments = ['aa']
|
|
160
|
-
// ex.stack = ...stack trace...
|
|
161
|
-
//
|
|
162
|
-
// INTERNET EXPLORER:
|
|
163
|
-
// ex.message = ...
|
|
164
|
-
// ex.name = ReferenceError
|
|
165
|
-
//
|
|
166
|
-
// OPERA:
|
|
167
|
-
// ex.message = ...message... (see the example below)
|
|
168
|
-
// ex.name = ReferenceError
|
|
169
|
-
// ex.opera#sourceloc = 11 (pretty much useless, duplicates the info in ex.message)
|
|
170
|
-
// ex.stacktrace = n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'
|
|
31
|
+
var fileUrl = '((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\\w+\\.|\\/).*?)';
|
|
32
|
+
var filePosition = '(?::(\\d+))';
|
|
33
|
+
var CHROME_LINE_RE = new RegExp('^\\s*at (.*?) ?\\(' + fileUrl + filePosition + '?' + filePosition + '?\\)?\\s*$', 'i');
|
|
34
|
+
var CHROME_EVAL_RE = new RegExp('\\((\\S*)' + filePosition + filePosition + '\\)');
|
|
171
35
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
* Chrome and Gecko use this property.
|
|
175
|
-
* @param {Error} ex
|
|
176
|
-
* @return {?StackTrace} Stack trace information.
|
|
177
|
-
* @memberof computeStackTrace
|
|
178
|
-
*/
|
|
36
|
+
function parseChromeLine(line) {
|
|
37
|
+
var parts = CHROME_LINE_RE.exec(line);
|
|
179
38
|
|
|
180
|
-
|
|
181
|
-
var stacktrace = tryToGetString(ex, 'stack');
|
|
182
|
-
|
|
183
|
-
if (!stacktrace) {
|
|
39
|
+
if (!parts) {
|
|
184
40
|
return;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
var chrome = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|eval|webpack|<anonymous>|\/).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i; // eslint-disable-next-line max-len
|
|
189
|
-
|
|
190
|
-
var gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i; // eslint-disable-next-line max-len
|
|
191
|
-
|
|
192
|
-
var winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i; // Used to additionally parse URL/line/column from eval frames
|
|
193
|
-
|
|
194
|
-
var isEval;
|
|
195
|
-
var geckoEval = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
196
|
-
var chromeEval = /\((\S*)(?::(\d+))(?::(\d+))\)/;
|
|
197
|
-
var lines = stacktrace.split('\n');
|
|
198
|
-
var stack = [];
|
|
199
|
-
var submatch;
|
|
200
|
-
var parts;
|
|
201
|
-
var element;
|
|
202
|
-
|
|
203
|
-
for (var i = 0, j = lines.length; i < j; i += 1) {
|
|
204
|
-
if (chrome.exec(lines[i])) {
|
|
205
|
-
parts = chrome.exec(lines[i]);
|
|
206
|
-
var isNative = parts[2] && parts[2].indexOf('native') === 0; // start of line
|
|
207
|
-
|
|
208
|
-
isEval = parts[2] && parts[2].indexOf('eval') === 0; // start of line
|
|
209
|
-
|
|
210
|
-
submatch = chromeEval.exec(parts[2]);
|
|
211
|
-
|
|
212
|
-
if (isEval && submatch) {
|
|
213
|
-
// throw out eval line/column and use top-most line/column number
|
|
214
|
-
parts[2] = submatch[1]; // url
|
|
215
|
-
|
|
216
|
-
parts[3] = submatch[2]; // line
|
|
41
|
+
}
|
|
217
42
|
|
|
218
|
-
|
|
219
|
-
}
|
|
43
|
+
var isNative = parts[2] && parts[2].indexOf('native') === 0; // start of line
|
|
220
44
|
|
|
221
|
-
|
|
222
|
-
args: isNative ? [parts[2]] : [],
|
|
223
|
-
column: parts[4] ? +parts[4] : undefined,
|
|
224
|
-
func: parts[1] || UNKNOWN_FUNCTION,
|
|
225
|
-
line: parts[3] ? +parts[3] : undefined,
|
|
226
|
-
url: !isNative ? parts[2] : undefined
|
|
227
|
-
};
|
|
228
|
-
} else if (winjs.exec(lines[i])) {
|
|
229
|
-
parts = winjs.exec(lines[i]);
|
|
230
|
-
element = {
|
|
231
|
-
args: [],
|
|
232
|
-
column: parts[4] ? +parts[4] : undefined,
|
|
233
|
-
func: parts[1] || UNKNOWN_FUNCTION,
|
|
234
|
-
line: +parts[3],
|
|
235
|
-
url: parts[2]
|
|
236
|
-
};
|
|
237
|
-
} else if (gecko.exec(lines[i])) {
|
|
238
|
-
parts = gecko.exec(lines[i]);
|
|
239
|
-
isEval = parts[3] && parts[3].indexOf(' > eval') > -1;
|
|
240
|
-
submatch = geckoEval.exec(parts[3]);
|
|
45
|
+
var isEval = parts[2] && parts[2].indexOf('eval') === 0; // start of line
|
|
241
46
|
|
|
242
|
-
|
|
243
|
-
// throw out eval line/column and use top-most line number
|
|
244
|
-
parts[3] = submatch[1];
|
|
245
|
-
parts[4] = submatch[2];
|
|
246
|
-
parts[5] = undefined; // no column when eval
|
|
247
|
-
} else if (i === 0 && !parts[5] && !isUndefined(ex.columnNumber)) {
|
|
248
|
-
// FireFox uses this awesome columnNumber property for its top frame
|
|
249
|
-
// Also note, Firefox's column number is 0-based and everything else expects 1-based,
|
|
250
|
-
// so adding 1
|
|
251
|
-
// NOTE: this hack doesn't work if top-most frame is eval
|
|
252
|
-
stack[0].column = ex.columnNumber + 1;
|
|
253
|
-
}
|
|
47
|
+
var submatch = CHROME_EVAL_RE.exec(parts[2]);
|
|
254
48
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
func: parts[1] || UNKNOWN_FUNCTION,
|
|
259
|
-
line: parts[4] ? +parts[4] : undefined,
|
|
260
|
-
url: parts[3]
|
|
261
|
-
};
|
|
262
|
-
} else {
|
|
263
|
-
continue;
|
|
264
|
-
}
|
|
49
|
+
if (isEval && submatch) {
|
|
50
|
+
// throw out eval line/column and use top-most line/column number
|
|
51
|
+
parts[2] = submatch[1]; // url
|
|
265
52
|
|
|
266
|
-
|
|
267
|
-
element.func = UNKNOWN_FUNCTION;
|
|
268
|
-
}
|
|
53
|
+
parts[3] = submatch[2]; // line
|
|
269
54
|
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
if (!stack.length) {
|
|
274
|
-
return;
|
|
55
|
+
parts[4] = submatch[3]; // column
|
|
275
56
|
}
|
|
276
57
|
|
|
277
58
|
return {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
59
|
+
args: isNative ? [parts[2]] : [],
|
|
60
|
+
column: parts[4] ? +parts[4] : undefined,
|
|
61
|
+
func: parts[1] || UNKNOWN_FUNCTION,
|
|
62
|
+
line: parts[3] ? +parts[3] : undefined,
|
|
63
|
+
url: !isNative ? parts[2] : undefined
|
|
281
64
|
};
|
|
282
65
|
}
|
|
283
|
-
/**
|
|
284
|
-
* Computes stack trace information from the stacktrace property.
|
|
285
|
-
* Opera 10+ uses this property.
|
|
286
|
-
* @param {Error} ex
|
|
287
|
-
* @return {?StackTrace} Stack trace information.
|
|
288
|
-
* @memberof computeStackTrace
|
|
289
|
-
*/
|
|
290
66
|
|
|
291
|
-
|
|
292
|
-
// Access and store the stacktrace property before doing ANYTHING
|
|
293
|
-
// else to it because Opera is not very good at providing it
|
|
294
|
-
// reliably in other circumstances.
|
|
295
|
-
var stacktrace = tryToGetString(ex, 'stacktrace');
|
|
67
|
+
var CHROME_ANONYMOUS_FUNCTION_RE = new RegExp('^\\s*at ?' + fileUrl + filePosition + '?' + filePosition + '??\\s*$', 'i');
|
|
296
68
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
var opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i; // eslint-disable-next-line max-len
|
|
69
|
+
function parseChromeAnonymousLine(line) {
|
|
70
|
+
var parts = CHROME_ANONYMOUS_FUNCTION_RE.exec(line);
|
|
302
71
|
|
|
303
|
-
|
|
304
|
-
var lines = stacktrace.split('\n');
|
|
305
|
-
var stack = [];
|
|
306
|
-
var parts;
|
|
307
|
-
|
|
308
|
-
for (var line = 0; line < lines.length; line += 2) {
|
|
309
|
-
var element;
|
|
310
|
-
|
|
311
|
-
if (opera10Regex.exec(lines[line])) {
|
|
312
|
-
parts = opera10Regex.exec(lines[line]);
|
|
313
|
-
element = {
|
|
314
|
-
args: [],
|
|
315
|
-
column: undefined,
|
|
316
|
-
func: parts[3],
|
|
317
|
-
line: +parts[1],
|
|
318
|
-
url: parts[2]
|
|
319
|
-
};
|
|
320
|
-
} else if (opera11Regex.exec(lines[line])) {
|
|
321
|
-
parts = opera11Regex.exec(lines[line]);
|
|
322
|
-
element = {
|
|
323
|
-
args: parts[5] ? parts[5].split(',') : [],
|
|
324
|
-
column: +parts[2],
|
|
325
|
-
func: parts[3] || parts[4],
|
|
326
|
-
line: +parts[1],
|
|
327
|
-
url: parts[6]
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
if (element) {
|
|
332
|
-
if (!element.func && element.line) {
|
|
333
|
-
element.func = UNKNOWN_FUNCTION;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
element.context = [lines[line + 1]];
|
|
337
|
-
stack.push(element);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
if (!stack.length) {
|
|
72
|
+
if (!parts) {
|
|
342
73
|
return;
|
|
343
74
|
}
|
|
344
75
|
|
|
345
76
|
return {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
77
|
+
args: [],
|
|
78
|
+
column: parts[3] ? +parts[3] : undefined,
|
|
79
|
+
func: UNKNOWN_FUNCTION,
|
|
80
|
+
line: parts[2] ? +parts[2] : undefined,
|
|
81
|
+
url: parts[1]
|
|
349
82
|
};
|
|
350
83
|
}
|
|
351
|
-
/**
|
|
352
|
-
* NOT TESTED.
|
|
353
|
-
* Computes stack trace information from an error message that includes
|
|
354
|
-
* the stack trace.
|
|
355
|
-
* Opera 9 and earlier use this method if the option to show stack
|
|
356
|
-
* traces is turned on in opera:config.
|
|
357
|
-
* @param {Error} ex
|
|
358
|
-
* @return {?StackTrace} Stack information.
|
|
359
|
-
* @memberof computeStackTrace
|
|
360
|
-
*/
|
|
361
84
|
|
|
85
|
+
var WINJS_LINE_RE = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:file|ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i;
|
|
362
86
|
|
|
363
|
-
function
|
|
364
|
-
|
|
365
|
-
// Opera includes a stack trace into the exception message. An example is:
|
|
366
|
-
//
|
|
367
|
-
// Statement on line 3: Undefined variable: undefinedFunc
|
|
368
|
-
// Backtrace:
|
|
369
|
-
// Line 3 of linked script file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.js:
|
|
370
|
-
// In function zzz
|
|
371
|
-
// undefinedFunc(a);
|
|
372
|
-
// Line 7 of inline#1 script in file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.html:
|
|
373
|
-
// In function yyy
|
|
374
|
-
// zzz(x, y, z);
|
|
375
|
-
// Line 3 of inline#1 script in file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.html:
|
|
376
|
-
// In function xxx
|
|
377
|
-
// yyy(a, a, a);
|
|
378
|
-
// Line 1 of function script
|
|
379
|
-
// try { xxx('hi'); return false; } catch(ex) { report(ex); }
|
|
380
|
-
// ...
|
|
381
|
-
var message = tryToGetString(ex, 'message');
|
|
87
|
+
function parseWinLine(line) {
|
|
88
|
+
var parts = WINJS_LINE_RE.exec(line);
|
|
382
89
|
|
|
383
|
-
if (!
|
|
90
|
+
if (!parts) {
|
|
384
91
|
return;
|
|
385
92
|
}
|
|
386
93
|
|
|
387
|
-
var lines = message.split('\n');
|
|
388
|
-
|
|
389
|
-
if (lines.length < 4) {
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
var lineRE1 = /^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i;
|
|
394
|
-
var lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i;
|
|
395
|
-
var lineRE3 = /^\s*Line (\d+) of function script\s*$/i;
|
|
396
|
-
var stack = [];
|
|
397
|
-
var scripts = window && window.document && window.document.getElementsByTagName('script');
|
|
398
|
-
var inlineScriptBlocks = [];
|
|
399
|
-
var parts;
|
|
400
|
-
|
|
401
|
-
for (var s in scripts) {
|
|
402
|
-
if (has(scripts, s) && !scripts[s].src) {
|
|
403
|
-
inlineScriptBlocks.push(scripts[s]);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
for (var line = 2; line < lines.length; line += 2) {
|
|
408
|
-
var item;
|
|
409
|
-
|
|
410
|
-
if (lineRE1.exec(lines[line])) {
|
|
411
|
-
parts = lineRE1.exec(lines[line]);
|
|
412
|
-
item = {
|
|
413
|
-
args: [],
|
|
414
|
-
column: undefined,
|
|
415
|
-
func: parts[3],
|
|
416
|
-
line: +parts[1],
|
|
417
|
-
url: parts[2]
|
|
418
|
-
};
|
|
419
|
-
} else if (lineRE2.exec(lines[line])) {
|
|
420
|
-
parts = lineRE2.exec(lines[line]);
|
|
421
|
-
item = {
|
|
422
|
-
args: [],
|
|
423
|
-
column: undefined,
|
|
424
|
-
// TODO: Check to see if inline#1 (+parts[2]) points to the script number or column number.
|
|
425
|
-
func: parts[4],
|
|
426
|
-
line: +parts[1],
|
|
427
|
-
url: parts[3]
|
|
428
|
-
};
|
|
429
|
-
} else if (lineRE3.exec(lines[line])) {
|
|
430
|
-
parts = lineRE3.exec(lines[line]);
|
|
431
|
-
var url = window.location.href.replace(/#.*$/, '');
|
|
432
|
-
item = {
|
|
433
|
-
url: url,
|
|
434
|
-
args: [],
|
|
435
|
-
column: undefined,
|
|
436
|
-
func: '',
|
|
437
|
-
line: +parts[1]
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
if (item) {
|
|
442
|
-
if (!item.func) {
|
|
443
|
-
item.func = UNKNOWN_FUNCTION;
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
item.context = [lines[line + 1]];
|
|
447
|
-
stack.push(item);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
if (!stack.length) {
|
|
452
|
-
return; // could not parse multiline exception message as Opera stack trace
|
|
453
|
-
}
|
|
454
|
-
|
|
455
94
|
return {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
95
|
+
args: [],
|
|
96
|
+
column: parts[4] ? +parts[4] : undefined,
|
|
97
|
+
func: parts[1] || UNKNOWN_FUNCTION,
|
|
98
|
+
line: +parts[3],
|
|
99
|
+
url: parts[2]
|
|
459
100
|
};
|
|
460
101
|
}
|
|
461
|
-
/**
|
|
462
|
-
* Adds information about the first frame to incomplete stack traces.
|
|
463
|
-
* Safari and IE require this to get complete data on the first frame.
|
|
464
|
-
* @param {StackTrace} stackInfo Stack trace information from
|
|
465
|
-
* one of the compute* methods.
|
|
466
|
-
* @param {string=} url The URL of the script that caused an error.
|
|
467
|
-
* @param {(number|string)=} lineNo The line number of the script that
|
|
468
|
-
* caused an error.
|
|
469
|
-
* @param {string=} message The error generated by the browser, which
|
|
470
|
-
* hopefully contains the name of the object that caused the error.
|
|
471
|
-
* @return {boolean} Whether or not the stack information was
|
|
472
|
-
* augmented.
|
|
473
|
-
* @memberof computeStackTrace
|
|
474
|
-
*/
|
|
475
|
-
|
|
476
102
|
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
url: url,
|
|
480
|
-
line: lineNo ? +lineNo : undefined
|
|
481
|
-
};
|
|
103
|
+
var GECKO_LINE_RE = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|resource|capacitor|\[native).*?|[^@]*bundle)(?::(\d+))?(?::(\d+))?\s*$/i;
|
|
104
|
+
var GECKO_EVAL_RE = /(\S+) line (\d+)(?: > eval line \d+)* > eval/i;
|
|
482
105
|
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
var stack = stackInfo.stack;
|
|
106
|
+
function parseGeckoLine(line) {
|
|
107
|
+
var parts = GECKO_LINE_RE.exec(line);
|
|
486
108
|
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
if (stack[0].line === initial.line) {
|
|
490
|
-
return false; // already in stack trace
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
if (!stack[0].line && stack[0].func === initial.func) {
|
|
494
|
-
stack[0].line = initial.line;
|
|
495
|
-
stack[0].context = initial.context;
|
|
496
|
-
return false;
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
stack.unshift(initial);
|
|
502
|
-
stackInfo.partial = true;
|
|
503
|
-
return true;
|
|
109
|
+
if (!parts) {
|
|
110
|
+
return;
|
|
504
111
|
}
|
|
505
112
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Computes stack trace information by walking the arguments.caller
|
|
511
|
-
* chain at the time the exception occurred. This will cause earlier
|
|
512
|
-
* frames to be missed but is the only way to get any stack trace in
|
|
513
|
-
* Safari and IE. The top frame is restored by
|
|
514
|
-
* {@link augmentStackTraceWithInitialElement}.
|
|
515
|
-
* @param {Error} ex
|
|
516
|
-
* @param {number} depth
|
|
517
|
-
* @return {StackTrace} Stack trace information.
|
|
518
|
-
* @memberof computeStackTrace
|
|
519
|
-
*/
|
|
113
|
+
var isEval = parts[3] && parts[3].indexOf(' > eval') > -1;
|
|
114
|
+
var submatch = GECKO_EVAL_RE.exec(parts[3]);
|
|
520
115
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
var parts;
|
|
527
|
-
var item;
|
|
528
|
-
|
|
529
|
-
for (var curr = computeStackTraceByWalkingCallerChain.caller; curr && !recursion; curr = curr.caller) {
|
|
530
|
-
if (curr === computeStackTrace || curr === report) {
|
|
531
|
-
continue;
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
item = {
|
|
535
|
-
args: [],
|
|
536
|
-
column: undefined,
|
|
537
|
-
func: UNKNOWN_FUNCTION,
|
|
538
|
-
line: undefined,
|
|
539
|
-
url: undefined
|
|
540
|
-
};
|
|
541
|
-
parts = functionName.exec(curr.toString());
|
|
542
|
-
|
|
543
|
-
if (curr.name) {
|
|
544
|
-
item.func = curr.name;
|
|
545
|
-
} else if (parts) {
|
|
546
|
-
item.func = parts[1];
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
if (typeof item.func === 'undefined') {
|
|
550
|
-
item.func = parts ? parts.input.substring(0, parts.input.indexOf('{')) : undefined;
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if (funcs[curr.toString()]) {
|
|
554
|
-
recursion = true;
|
|
555
|
-
} else {
|
|
556
|
-
funcs[curr.toString()] = true;
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
stack.push(item);
|
|
116
|
+
if (isEval && submatch) {
|
|
117
|
+
// throw out eval line/column and use top-most line number
|
|
118
|
+
parts[3] = submatch[1];
|
|
119
|
+
parts[4] = submatch[2];
|
|
120
|
+
parts[5] = undefined; // no column when eval
|
|
560
121
|
}
|
|
561
122
|
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
message: tryToGetString(ex, 'message'),
|
|
569
|
-
name: tryToGetString(ex, 'name')
|
|
123
|
+
return {
|
|
124
|
+
args: parts[2] ? parts[2].split(',') : [],
|
|
125
|
+
column: parts[5] ? +parts[5] : undefined,
|
|
126
|
+
func: parts[1] || UNKNOWN_FUNCTION,
|
|
127
|
+
line: parts[4] ? +parts[4] : undefined,
|
|
128
|
+
url: parts[3]
|
|
570
129
|
};
|
|
571
|
-
augmentStackTraceWithInitialElement(result, tryToGetString(ex, 'sourceURL') || tryToGetString(ex, 'fileName'), tryToGetString(ex, 'line') || tryToGetString(ex, 'lineNumber'));
|
|
572
|
-
return result;
|
|
573
130
|
}
|
|
574
131
|
|
|
575
132
|
function tryToGetString(candidate, property) {
|
|
@@ -579,45 +136,4 @@ function tryToGetString(candidate, property) {
|
|
|
579
136
|
|
|
580
137
|
var value = candidate[property];
|
|
581
138
|
return typeof value === 'string' ? value : undefined;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* Logs a stacktrace starting from the previous call and working down.
|
|
585
|
-
* @param {(number|string)=} depth How many frames deep to trace.
|
|
586
|
-
* @return {StackTrace} Stack trace information.
|
|
587
|
-
* @memberof computeStackTrace
|
|
588
|
-
*/
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
export function computeStackTraceOfCaller(depth) {
|
|
592
|
-
var currentDepth = (depth === undefined ? 0 : +depth) + 1; // "+ 1" because "ofCaller" should drop one frame
|
|
593
|
-
|
|
594
|
-
try {
|
|
595
|
-
throw new Error();
|
|
596
|
-
} catch (ex) {
|
|
597
|
-
return computeStackTrace(ex, currentDepth + 1);
|
|
598
|
-
}
|
|
599
|
-
}
|
|
600
|
-
/**
|
|
601
|
-
* A better form of hasOwnProperty<br/>
|
|
602
|
-
* Example: `has(MainHostObject, property) === true/false`
|
|
603
|
-
*
|
|
604
|
-
* @param {Object} object to check property
|
|
605
|
-
* @param {string} key to check
|
|
606
|
-
* @return {Boolean} true if the object has the key and it is not inherited
|
|
607
|
-
*/
|
|
608
|
-
|
|
609
|
-
function has(object, key) {
|
|
610
|
-
return Object.prototype.hasOwnProperty.call(object, key);
|
|
611
|
-
}
|
|
612
|
-
/**
|
|
613
|
-
* Returns true if the parameter is undefined<br/>
|
|
614
|
-
* Example: `isUndefined(val) === true/false`
|
|
615
|
-
*
|
|
616
|
-
* @param {*} what Value to check
|
|
617
|
-
* @return {Boolean} true if undefined and false otherwise
|
|
618
|
-
*/
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
function isUndefined(what) {
|
|
622
|
-
return typeof what === 'undefined';
|
|
623
139
|
}
|
package/esm/tracekit/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { computeStackTrace } from './computeStackTrace';
|
|
2
|
-
export {
|
|
2
|
+
export { startUnhandledErrorCollection } from './tracekit';
|