Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit a500782

Browse files
committed
fixup! fix($log): don't parse error stacks manually outside of IE/Edge
1 parent 32843ad commit a500782

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/ng/log.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ function $LogProvider() {
6767
};
6868

6969
this.$get = ['$window', function($window) {
70+
// Support: IE 9-11, Edge 12-14+
71+
// IE/Edge display errors in such a way that it requires the user to click in 4 places
72+
// to see the stack trace. There is no way to feature-detect it so there's a chance
73+
// of the user agent sniffing to go wrong but since it's only about logging, this shouldn't
74+
// break apps. Other browsers display errors in a sensible way and some of them map stack
75+
// traces along source maps if available so it makes sense to let browsers display it
76+
// as they want.
77+
var formatStackTrace = msie || /\bEdge\//.test($window.navigator && $window.navigator.userAgent);
78+
7079
return {
7180
/**
7281
* @ngdoc method
@@ -124,14 +133,7 @@ function $LogProvider() {
124133

125134
function formatError(arg) {
126135
if (arg instanceof Error) {
127-
// Support: IE 9-11, Edge 12-14+
128-
// IE/Edge display errors in such a way that it requires the user to click in 4 places
129-
// to see the stack trace. There is no way to feature-detect it so there's a chance
130-
// of the user agent sniffing to go wrong but since it's only about logging, this shouldn't
131-
// break apps. Other browsers display errors in a sensible way and some of them map stack
132-
// traces along source maps if available so it makes sense to let browsers display it
133-
// as they want.
134-
if (arg.stack && (msie || /\bEdge\//.test($window.navigator.userAgent))) {
136+
if (arg.stack && formatStackTrace) {
135137
arg = (arg.message && arg.stack.indexOf(arg.message) === -1)
136138
? 'Error: ' + arg.message + '\n' + arg.stack
137139
: arg.stack;

test/ng/logSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ describe('$log', function() {
6767
}
6868
));
6969

70+
it('should work if $window.navigator not defined', inject(
71+
function() {
72+
delete $window.navigator;
73+
},
74+
function($log) {}
75+
));
76+
7077
describe('IE logging behavior', function() {
7178
function removeApplyFunctionForIE() {
7279
log.apply = log.call =

0 commit comments

Comments
 (0)