Skip to content

Commit 6826bc9

Browse files
committed
Support for PhantomJS stacktrace. Fixes #76
1 parent e837911 commit 6826bc9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

stacktrace.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@
6464
* @return {String} mode of operation for the exception
6565
*/
6666
mode: function(e) {
67+
if (typeof window !== 'undefined' && window.navigator.userAgent.indexOf('PhantomJS') > -1) {
68+
return 'phantomjs';
69+
}
70+
6771
if (e['arguments'] && e.stack) {
6872
return 'chrome';
6973
}
@@ -278,6 +282,24 @@
278282
return result;
279283
},
280284

285+
phantomjs: function(e) {
286+
var ANON = '{anonymous}', lineRE = /(\S+) \((\S+)\)/i;
287+
var lines = e.stack.split('\n'), result = [];
288+
289+
for (var i = 1, len = lines.length; i < len; i++) {
290+
lines[i] = lines[i].replace(/^\s+at\s+/gm, '');
291+
var match = lineRE.exec(lines[i]);
292+
if (match) {
293+
result.push(match[1] + '()@' + match[2]);
294+
}
295+
else {
296+
result.push(ANON + '()@' + lines[i]);
297+
}
298+
}
299+
300+
return result;
301+
},
302+
281303
// Safari 5-, IE 9-, and others
282304
other: function(curr) {
283305
var ANON = '{anonymous}', fnRE = /function(?:\s+([\w$]+))?\s*\(/, stack = [], fn, args, maxStackSize = 10;

0 commit comments

Comments
 (0)