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