1
1
var coderr = ( function ( exports ) {
2
2
'use strict' ;
3
3
4
- function toCollection ( collectionName , anyObject ) {
5
- var props = [ ] ;
4
+ function toCollection ( collectionName , anyObject , removeUndefined ) {
5
+ if ( removeUndefined === void 0 ) { removeUndefined = false ; }
6
+ var props = { } ;
6
7
function addItem ( name , value ) {
7
8
if ( Array . isArray ( value ) ) {
8
9
value . forEach ( function ( item , index ) {
9
10
addItem ( name + "[" + index + "]" , item ) ;
10
11
} ) ;
11
12
}
13
+ else if ( typeof value === 'function' ) ;
12
14
else if ( typeof value === 'object' ) {
13
15
for ( var key in value ) {
14
16
if ( ! value . hasOwnProperty ( key ) ) {
@@ -24,7 +26,20 @@ var coderr = (function (exports) {
24
26
}
25
27
}
26
28
else {
27
- props . push ( { name : name , value : value } ) ;
29
+ var valueStr = void 0 ;
30
+ if ( typeof value === 'undefined' ) {
31
+ if ( removeUndefined ) {
32
+ return ;
33
+ }
34
+ valueStr = 'undefined' ;
35
+ }
36
+ else if ( value === null ) {
37
+ valueStr = 'null' ;
38
+ }
39
+ else {
40
+ valueStr = value . toString ( ) ;
41
+ }
42
+ props [ name ] = valueStr ;
28
43
}
29
44
}
30
45
addItem ( '' , anyObject ) ;
@@ -35,19 +50,25 @@ var coderr = (function (exports) {
35
50
return false ;
36
51
}
37
52
var result = false ;
38
- var element = new Image ( ) ;
39
- element . __defineGetter__ ( 'id' , function ( ) {
40
- result = true ;
41
- } ) ;
42
- console . log ( element ) ;
53
+ try {
54
+ var element = new Image ( ) ;
55
+ element . __defineGetter__ ( 'id' , function ( ) {
56
+ result = true ;
57
+ } ) ;
58
+ console . log ( element ) ;
59
+ }
60
+ catch ( _a ) {
61
+ // probably that the Image could not be created,
62
+ // so ignore the error as we wont have dev tools then.
63
+ }
43
64
return result ;
44
65
}
45
66
// source: https://stackoverflow.com/questions/3231459/create-unique-id-with-javascript
46
67
function uniqueid ( ) {
47
68
// always start with a letter (for DOM friendlyness)
48
- var idstr = String . fromCharCode ( Math . floor ( ( Math . random ( ) * 25 ) + 65 ) ) ;
69
+ var idstr = String . fromCharCode ( Math . floor ( Math . random ( ) * 25 + 65 ) ) ;
49
70
do {
50
- var asciiCode = Math . floor ( ( Math . random ( ) * 42 ) + 48 ) ;
71
+ var asciiCode = Math . floor ( Math . random ( ) * 42 + 48 ) ;
51
72
if ( asciiCode < 58 || asciiCode > 64 ) {
52
73
// exclude all chars between : (58) and @ (64)
53
74
idstr += String . fromCharCode ( asciiCode ) ;
@@ -82,25 +103,49 @@ var coderr = (function (exports) {
82
103
return Configuration ;
83
104
} ( ) ) ;
84
105
var Reporter = /** @class */ ( function ( ) {
85
- function Reporter ( configuration ) {
106
+ function Reporter ( configuration , uploader ) {
86
107
this . configuration = configuration ;
108
+ this . uploader = uploader ;
87
109
if ( this . configuration . environmentName === '' &&
88
110
detectDeveloperTools ( ) ) {
89
111
this . configuration . environmentName = 'Development' ;
90
112
}
113
+ Reporter . instance = this ;
91
114
}
92
115
Reporter . prototype . reportErr = function ( error , contextData ) {
93
116
var _this = this ;
117
+ if ( contextData === void 0 ) { contextData = null ; }
94
118
var ctx = new VanillaContext ( this , error ) ;
95
119
this . configuration . contextFactories . forEach ( function ( element ) {
96
120
if ( ! element . canHandle ( _this , error ) ) {
97
121
return ;
98
122
}
99
123
ctx = element . createContext ( _this , error ) ;
100
124
} ) ;
101
- if ( contextData ) {
102
- var col = toCollection ( 'ContextData' , contextData ) ;
103
- ctx . contextCollections . push ( col ) ;
125
+ if ( contextData ) {
126
+ if ( Array . isArray ( contextData ) ) {
127
+ contextData . forEach ( function ( x , index ) {
128
+ if ( ! x . name || ! x . properties ) {
129
+ if ( index === 0 ) {
130
+ x = toCollection ( 'ContextData' , x ) ;
131
+ }
132
+ else {
133
+ x = toCollection ( 'ContextData' + ( index + 1 ) , x ) ;
134
+ }
135
+ }
136
+ ctx . contextCollections . push ( x ) ;
137
+ } ) ;
138
+ }
139
+ else {
140
+ var collection = void 0 ;
141
+ if ( ! contextData . name || ! contextData . properties ) {
142
+ collection = toCollection ( 'ContextData' , contextData ) ;
143
+ }
144
+ else {
145
+ collection = contextData ;
146
+ }
147
+ ctx . contextCollections . push ( collection ) ;
148
+ }
104
149
}
105
150
this . reportByContext ( ctx ) ;
106
151
} ;
@@ -122,18 +167,33 @@ var coderr = (function (exports) {
122
167
} ;
123
168
Reporter . prototype . upload = function ( report ) {
124
169
var url = this . configuration . serverUrl + "receiver/report/" + this . configuration . appKey + "/" ;
125
- var httpRequest = new XMLHttpRequest ( ) ;
126
- httpRequest . open ( 'POST' , url , true ) ;
127
- httpRequest . setRequestHeader ( 'Content-type' , 'application/json' ) ;
128
- httpRequest . setRequestHeader ( 'X-Library' , 'javascript' ) ;
129
- var data = JSON . stringify ( report ) ;
130
- httpRequest . send ( data ) ;
170
+ var uploader = this . uploader || this . configuration . uploader ;
171
+ if ( uploader ) {
172
+ uploader ( {
173
+ appKey : this . configuration . appKey ,
174
+ report : report ,
175
+ url : this . configuration . serverUrl ,
176
+ } ) ;
177
+ }
178
+ else {
179
+ var data = JSON . stringify ( report ) ;
180
+ var httpRequest = new XMLHttpRequest ( ) ;
181
+ httpRequest . open ( 'POST' , url , true ) ;
182
+ httpRequest . setRequestHeader ( 'Content-type' , 'application/json' ) ;
183
+ httpRequest . setRequestHeader ( 'X-Library' , 'javascript' ) ;
184
+ httpRequest . send ( data ) ;
185
+ }
131
186
} ;
132
187
Reporter . prototype . convertCollections = function ( collections ) {
133
188
var dtos = [ ] ;
134
189
collections . forEach ( function ( item ) {
135
190
var dict = { } ;
136
- item . properties . forEach ( function ( x ) { return ( dict [ x . name ] = x . value ) ; } ) ;
191
+ for ( var key in item . properties ) {
192
+ if ( item . properties . hasOwnProperty ( key ) ) {
193
+ var value = item . properties [ key ] ;
194
+ dict [ key ] = value ;
195
+ }
196
+ }
137
197
var dto = {
138
198
Name : item . name ,
139
199
Properties : dict ,
@@ -1093,7 +1153,7 @@ var coderr = (function (exports) {
1093
1153
return DomContextFactory ;
1094
1154
} ( ) ) ;
1095
1155
function catchDomErrors ( configuration ) {
1096
- document . addEventListener ( 'error' , function ( event ) {
1156
+ window . addEventListener ( 'error' , function ( event ) {
1097
1157
var domContext = new DomErrorContext ( event . target , event . error , window . document , window ) ;
1098
1158
Reporter . instance . reportByContext ( domContext ) ;
1099
1159
} ) ;
@@ -1117,40 +1177,53 @@ var coderr = (function (exports) {
1117
1177
if ( ! document ) {
1118
1178
return [ ] ;
1119
1179
}
1120
- var doc = toCollection ( 'document' , {
1121
- baseURI : document . baseURI ,
1122
- characterSet : document . characterSet ,
1123
- charset : document . charset ,
1124
- contentType : document . contentType ,
1125
- cookie : document . cookie ,
1126
- fullscreenEnabled : document . fullscreenEnabled ,
1127
- compatMode : document . compatMode ,
1128
- lastModified : document . lastModified ,
1129
- location : document . location . href ,
1130
- readyState : document . readyState ,
1131
- referrer : document . referrer ,
1132
- title : document . title ,
1133
- } ) ;
1134
-
1135
- if ( ! document . body ) {
1136
- console . log ( 'no body' , document ) ;
1137
- } else {
1138
- doc . body = {
1139
- clientHeight : document . body . clientHeight ,
1140
- clientLeft : document . body . clientLeft ,
1141
- clientTop : document . body . clientTop ,
1142
- clientWidth : document . body . clientWidth ,
1143
- baseURI : document . body . baseURI ,
1144
- draggable : document . body . draggable ,
1145
- inputMode : document . body . inputMode ,
1146
- offsetHeight : document . body . offsetHeight ,
1147
- offsetLeft : document . body . offsetLeft ,
1148
- offsetParent : document . body . offsetParent ,
1149
- offsetTop : document . body . offsetTop ,
1150
- offsetWidth : document . body . offsetWidth ,
1151
- } ;
1180
+ var doc = null ;
1181
+ if ( document . body ) {
1182
+ doc = toCollection ( 'document' , {
1183
+ baseURI : document . baseURI ,
1184
+ characterSet : document . characterSet ,
1185
+ charset : document . charset ,
1186
+ contentType : document . contentType ,
1187
+ cookie : document . cookie ,
1188
+ body : {
1189
+ clientHeight : document . body . clientHeight ,
1190
+ clientLeft : document . body . clientLeft ,
1191
+ clientTop : document . body . clientTop ,
1192
+ clientWidth : document . body . clientWidth ,
1193
+ baseURI : document . body . baseURI ,
1194
+ draggable : document . body . draggable ,
1195
+ inputMode : document . body . inputMode ,
1196
+ offsetHeight : document . body . offsetHeight ,
1197
+ offsetLeft : document . body . offsetLeft ,
1198
+ offsetParent : document . body . offsetParent ,
1199
+ offsetTop : document . body . offsetTop ,
1200
+ offsetWidth : document . body . offsetWidth ,
1201
+ } ,
1202
+ fullscreenEnabled : document . fullscreenEnabled ,
1203
+ compatMode : document . compatMode ,
1204
+ lastModified : document . lastModified ,
1205
+ location : document . location . href ,
1206
+ readyState : document . readyState ,
1207
+ referrer : document . referrer ,
1208
+ title : document . title ,
1209
+ } ) ;
1210
+ }
1211
+ else {
1212
+ doc = toCollection ( 'document' , {
1213
+ baseURI : document . baseURI ,
1214
+ characterSet : document . characterSet ,
1215
+ charset : document . charset ,
1216
+ contentType : document . contentType ,
1217
+ cookie : document . cookie ,
1218
+ fullscreenEnabled : document . fullscreenEnabled ,
1219
+ compatMode : document . compatMode ,
1220
+ lastModified : document . lastModified ,
1221
+ location : document . location . href ,
1222
+ readyState : document . readyState ,
1223
+ referrer : document . referrer ,
1224
+ title : document . title ,
1225
+ } ) ;
1152
1226
}
1153
-
1154
1227
return [ doc ] ;
1155
1228
} ;
1156
1229
return DocumentCollectionProvider ;
@@ -1179,24 +1252,24 @@ var coderr = (function (exports) {
1179
1252
browser : {
1180
1253
name : parser . getBrowser ( ) . name ,
1181
1254
major : parser . getBrowser ( ) . major ,
1182
- version : parser . getBrowser ( ) . version
1255
+ version : parser . getBrowser ( ) . version ,
1183
1256
} ,
1184
1257
OS : {
1185
1258
name : parser . getOS ( ) . name ,
1186
- version : parser . getOS ( ) . version
1259
+ version : parser . getOS ( ) . version ,
1187
1260
} ,
1188
1261
CPU : {
1189
1262
architecture : parser . getCPU ( ) . architecture ,
1190
1263
} ,
1191
1264
device : {
1192
1265
model : parser . getDevice ( ) . model ,
1193
1266
type : parser . getDevice ( ) . type ,
1194
- version : parser . getBrowser ( ) . version
1267
+ version : parser . getBrowser ( ) . version ,
1195
1268
} ,
1196
1269
engine : {
1197
1270
name : parser . getEngine ( ) . name ,
1198
- version : parser . getEngine ( ) . version
1199
- }
1271
+ version : parser . getEngine ( ) . version ,
1272
+ } ,
1200
1273
} ) ;
1201
1274
return [ col , uaCollection ] ;
1202
1275
} ;
0 commit comments