1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
/**
* https://github.com/csnover/TraceKit
* @license MIT
* @namespace TraceKit
*/
(function(window, undefined) {
if (!window) {
return;
}
var TraceKit = {};
var _oldTraceKit = window.TraceKit;
// global reference to slice
var _slice = [].slice;
var UNKNOWN_FUNCTION = '?';
/**
* A better form of hasOwnProperty<br/>
* Example: `_has(MainHostObject, property) === true/false`
*
* @param {Object} object to check property
* @param {string} key to check
* @return {Boolean} true if the object has the key and it is not inherited
*/
function _has(object, key) {
return Object.prototype.hasOwnProperty.call(object, key);
}
/**
* Returns true if the parameter is undefined<br/>
* Example: `_isUndefined(val) === true/false`
*
* @param {*} what Value to check
* @return {Boolean} true if undefined and false otherwise
*/
function _isUndefined(what) {
return typeof what === 'undefined';
}
/**
* Export TraceKit out to another variable<br/>
* Example: `var TK = TraceKit.noConflict()`
* @return {Object} The TraceKit object
* @memberof TraceKit
*/
TraceKit.noConflict = function noConflict() {
window.TraceKit = _oldTraceKit;
return TraceKit;
};
/**
* Wrap any function in a TraceKit reporter<br/>
* Example: `func = TraceKit.wrap(func);`
*
* @param {Function} func Function to be wrapped
* @return {Function} The wrapped func
* @memberof TraceKit
*/
TraceKit.wrap = function traceKitWrapper(func) {
function wrapped() {
try {
return func.apply(this, arguments);
} catch (e) {
TraceKit.report(e);
throw e;
}
}
return wrapped;
};
/**
* Cross-browser processing of unhandled exceptions
*
* Syntax:
* ```js
* TraceKit.report.subscribe(function(stackInfo) { ... })
* TraceKit.report.unsubscribe(function(stackInfo) { ... })
* TraceKit.report(exception)
* try { ...code... } catch(ex) { TraceKit.report(ex); }
* ```
*
* Supports:
* - Firefox: full stack trace with line numbers, plus column number
* on top frame; column number is not guaranteed
* - Opera: full stack trace with line and column numbers
* - Chrome: full stack trace with line and column numbers
* - Safari: line and column number for the top frame only; some frames
* may be missing, and column number is not guaranteed
* - IE: line and column number for the top frame only; some frames
* may be missing, and column number is not guaranteed
*
* In theory, TraceKit should work on all of the following versions:
* - IE5.5+ (only 8.0 tested)
* - Firefox 0.9+ (only 3.5+ tested)
* - Opera 7+ (only 10.50 tested; versions 9 and earlier may require
* Exceptions Have Stacktrace to be enabled in opera:config)
* - Safari 3+ (only 4+ tested)
* - Chrome 1+ (only 5+ tested)
* - Konqueror 3.5+ (untested)
*
* Requires TraceKit.computeStackTrace.
*
* Tries to catch all unhandled exceptions and report them to the
* subscribed handlers. Please note that TraceKit.report will rethrow the
* exception. This is REQUIRED in order to get a useful stack trace in IE.
* If the exception does not reach the top of the browser, you will only
* get a stack trace from the point where TraceKit.report was called.
*
* Handlers receive a TraceKit.StackTrace object as described in the
* TraceKit.computeStackTrace docs.
*
* @memberof TraceKit
* @namespace
*/
TraceKit.report = (function reportModuleWrapper() {
var handlers = [],
lastArgs = null,
lastException = null,
lastExceptionStack = null;
/**
* Add a crash handler.
* @param {Function} handler
* @memberof TraceKit.report
*/
function subscribe(handler) {
installGlobalHandler();
handlers.push(handler);
}
/**
* Remove a crash handler.
* @param {Function} handler
* @memberof TraceKit.report
*/
function unsubscribe(handler) {
for (var i = handlers.length - 1; i >= 0; --i) {
if (handlers[i] === handler) {
handlers.splice(i, 1);
}
}
}
/**
* Dispatch stack information to all handlers.
* @param {TraceKit.StackTrace} stack
* @param {boolean} isWindowError Is this a top-level window error?
* @memberof TraceKit.report
* @throws An exception if an error occurs while calling an handler.
*/
function notifyHandlers(stack, isWindowError) {
var exception = null;
if (isWindowError && !TraceKit.collectWindowErrors) {
return;
}
for (var i in handlers) {
if (_has(handlers, i)) {
try {
handlers[i].apply(null, [stack].concat(_slice.call(arguments, 2)));
} catch (inner) {
exception = inner;
}
}
}
if (exception) {
throw exception;
}
}
var _oldOnerrorHandler, _onErrorHandlerInstalled;
/**
* Ensures all global unhandled exceptions are recorded.
* Supported by Gecko and IE.
* @param {string} message Error message.
* @param {string} url URL of script that generated the exception.
* @param {(number|string)} lineNo The line number at which the error occurred.
* @param {(number|string)=} columnNo The column number at which the error occurred.
* @param {Error=} errorObj The actual Error object.
* @memberof TraceKit.report
*/
function traceKitWindowOnError(message, url, lineNo, columnNo, errorObj) {
var stack = null;
if (lastExceptionStack) {
TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(lastExceptionStack, url, lineNo, message);
processLastException();
} else if (errorObj) {
stack = TraceKit.computeStackTrace(errorObj);
notifyHandlers(stack, true);
} else {
var location = {
'url': url,
'line': lineNo,
'column': columnNo
};
location.func = TraceKit.computeStackTrace.guessFunctionName(location.url, location.line);
location.context = TraceKit.computeStackTrace.gatherContext(location.url, location.line);
stack = {
'mode': 'onerror',
'message': message,
'stack': [location]
};
notifyHandlers(stack, true);
}
if (_oldOnerrorHandler) {
return _oldOnerrorHandler.apply(this, arguments);
}
return false;
}
/**
* Install a global onerror handler
* @memberof TraceKit.report
*/
function installGlobalHandler () {
if (_onErrorHandlerInstalled === true) {
return;
}
_oldOnerrorHandler = window.onerror;
window.onerror = traceKitWindowOnError;
_onErrorHandlerInstalled = true;
}
/**
* Process the most recent exception
* @memberof TraceKit.report
*/
function processLastException() {
var _lastExceptionStack = lastExceptionStack,
_lastArgs = lastArgs;
lastArgs = null;
lastExceptionStack = null;
lastException = null;
notifyHandlers.apply(null, [_lastExceptionStack, false].concat(_lastArgs));
}
/**
* Reports an unhandled Error to TraceKit.
* @param {Error} ex
* @memberof TraceKit.report
* @throws An exception if an incomplete stack trace is detected (old IE browsers).
*/
function report(ex) {
if (lastExceptionStack) {
if (lastException === ex) {
return; // already caught by an inner catch block, ignore
} else {
processLastException();
}
}
var stack = TraceKit.computeStackTrace(ex);
lastExceptionStack = stack;
lastException = ex;
lastArgs = _slice.call(arguments, 1);
// If the stack trace is incomplete, wait for 2 seconds for
// slow slow IE to see if onerror occurs or not before reporting
// this exception; otherwise, we will end up with an incomplete
// stack trace
window.setTimeout(function () {
if (lastException === ex) {
processLastException();
}
}, (stack.incomplete ? 2000 : 0));
throw ex; // re-throw to propagate to the top level (and cause window.onerror)
}
report.subscribe = subscribe;
report.unsubscribe = unsubscribe;
return report;
}());
/**
* An object representing a single stack frame.
* @typedef {Object} StackFrame
* @property {string} url The JavaScript or HTML file URL.
* @property {string} func The function name, or empty for anonymous functions (if guessing did not work).
* @property {string[]?} args The arguments passed to the function, if known.
* @property {number=} line The line number, if known.
* @property {number=} column The column number, if known.
* @property {string[]} context An array of source code lines; the middle element corresponds to the correct line#.
* @memberof TraceKit
*/
/**
* An object representing a JavaScript stack trace.
* @typedef {Object} StackTrace
* @property {string} name The name of the thrown exception.
* @property {string} message The exception error message.
* @property {TraceKit.StackFrame[]} stack An array of stack frames.
* @property {string} mode 'stack', 'stacktrace', 'multiline', 'callers', 'onerror', or 'failed' -- method used to collect the stack trace.
* @memberof TraceKit
*/
/**
* TraceKit.computeStackTrace: cross-browser stack traces in JavaScript
*
* Syntax:
* ```js
* s = TraceKit.computeStackTrace.ofCaller([depth])
* s = TraceKit.computeStackTrace(exception) // consider using TraceKit.report instead (see below)
* ```
*
* Supports:
* - Firefox: full stack trace with line numbers and unreliable column
* number on top frame
* - Opera 10: full stack trace with line and column numbers
* - Opera 9-: full stack trace with line numbers
* - Chrome: full stack trace with line and column numbers
* - Safari: line and column number for the topmost stacktrace element
* only
* - IE: no line numbers whatsoever
*
* Tries to guess names of anonymous functions by looking for assignments
* in the source code. In IE and Safari, we have to guess source file names
* by searching for function bodies inside all page scripts. This will not
* work for scripts that are loaded cross-domain.
* Here be dragons: some function names may be guessed incorrectly, and
* duplicate functions may be mismatched.
*
* TraceKit.computeStackTrace should only be used for tracing purposes.
* Logging of unhandled exceptions should be done with TraceKit.report,
* which builds on top of TraceKit.computeStackTrace and provides better
* IE support by utilizing the window.onerror event to retrieve information
* about the top of the stack.
*
* Note: In IE and Safari, no stack trace is recorded on the Error object,
* so computeStackTrace instead walks its *own* chain of callers.
* This means that:
* * in Safari, some methods may be missing from the stack trace;
* * in IE, the topmost function in the stack trace will always be the
* caller of computeStackTrace.
*
* This is okay for tracing (because you are likely to be calling
* computeStackTrace from the function you want to be the topmost element
* of the stack trace anyway), but not okay for logging unhandled
* exceptions (because your catch block will likely be far away from the
* inner function that actually caused the exception).
*
* Tracing example:
* ```js
* function trace(message) {
* var stackInfo = TraceKit.computeStackTrace.ofCaller();
* var data = message + "\n";
* for(var i in stackInfo.stack) {
* var item = stackInfo.stack[i];
* data += (item.func || '[anonymous]') + "() in " + item.url + ":" + (item.line || '0') + "\n";
* }
* if (window.console)
* console.info(data);
* else
* alert(data);
* }
* ```
* @memberof TraceKit
* @namespace
*/
TraceKit.computeStackTrace = (function computeStackTraceWrapper() {
var debug = false,
sourceCache = {};
/**
* Attempts to retrieve source code via XMLHttpRequest, which is used
* to look up anonymous function names.
* @param {string} url URL of source code.
* @return {string} Source contents.
* @memberof TraceKit.computeStackTrace
*/
function loadSource(url) {
if (!TraceKit.remoteFetching) { //Only attempt request if remoteFetching is on.
return '';
}
try {
var getXHR = function() {
try {
return new window.XMLHttpRequest();
} catch (e) {
// explicitly bubble up the exception if not found
return new window.ActiveXObject('Microsoft.XMLHTTP');
}
};
var request = getXHR();
request.open('GET', url, false);
request.send('');
return request.responseText;
} catch (e) {
return '';
}
}
/**
* Retrieves source code from the source code cache.
* @param {string} url URL of source code.
* @return {Array.<string>} Source contents.
* @memberof TraceKit.computeStackTrace
*/
function getSource(url) {
if (typeof url !== 'string') {
return [];
}
if (!_has(sourceCache, url)) {
// URL needs to be able to fetched within the acceptable domain. Otherwise,
// cross-domain errors will be triggered.
/*
Regex matches:
0 - Full Url
1 - Protocol
2 - Domain
3 - Port (Useful for internal applications)
4 - Path
*/
var source = '';
var domain = '';
try { domain = window.document.domain; } catch (e) { }
var match = /(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(url);
if (match && match[2] === domain) {
source = loadSource(url);
}
sourceCache[url] = source ? source.split('\n') : [];
}
return sourceCache[url];
}
/**
* Tries to use an externally loaded copy of source code to determine
* the name of a function by looking at the name of the variable it was
* assigned to, if any.
* @param {string} url URL of source code.
* @param {(string|number)} lineNo Line number in source code.
* @return {string} The function name, if discoverable.
* @memberof TraceKit.computeStackTrace
*/
function guessFunctionName(url, lineNo) {
var reFunctionArgNames = /function ([^(]*)\(([^)]*)\)/,
reGuessFunction = /['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,
line = '',
maxLines = 10,
source = getSource(url),
m;
if (!source.length) {
return UNKNOWN_FUNCTION;
}
// Walk backwards from the first line in the function until we find the line which
// matches the pattern above, which is the function definition
for (var i = 0; i < maxLines; ++i) {
line = source[lineNo - i] + line;
if (!_isUndefined(line)) {
if ((m = reGuessFunction.exec(line))) {
return m[1];
} else if ((m = reFunctionArgNames.exec(line))) {
return m[1];
}
}
}
return UNKNOWN_FUNCTION;
}
/**
* Retrieves the surrounding lines from where an exception occurred.
* @param {string} url URL of source code.
* @param {(string|number)} line Line number in source code to centre
* around for context.
* @return {?Array.<string>} Lines of source code.
* @memberof TraceKit.computeStackTrace
*/
function gatherContext(url, line) {
var source = getSource(url);
if (!source.length) {
return null;
}
var context = [],
// linesBefore & linesAfter are inclusive with the offending line.
// if linesOfContext is even, there will be one extra line
// *before* the offending line.
linesBefore = Math.floor(TraceKit.linesOfContext / 2),
// Add one extra line if linesOfContext is odd
linesAfter = linesBefore + (TraceKit.linesOfContext % 2),
start = Math.max(0, line - linesBefore - 1),
end = Math.min(source.length, line + linesAfter - 1);
line -= 1; // convert to 0-based index
for (var i = start; i < end; ++i) {
if (!_isUndefined(source[i])) {
context.push(source[i]);
}
}
return context.length > 0 ? context : null;
}
/**
* Escapes special characters, except for whitespace, in a string to be
* used inside a regular expression as a string literal.
* @param {string} text The string.
* @return {string} The escaped string literal.
* @memberof TraceKit.computeStackTrace
*/
function escapeRegExp(text) {
return text.replace(/[\-\[\]{}()*+?.,\\\^$|#]/g, '\\$&');
}
/**
* Escapes special characters in a string to be used inside a regular
* expression as a string literal. Also ensures that HTML entities will
* be matched the same as their literal friends.
* @param {string} body The string.
* @return {string} The escaped string.
* @memberof TraceKit.computeStackTrace
*/
function escapeCodeAsRegExpForMatchingInsideHTML(body) {
return escapeRegExp(body).replace('<', '(?:<|<)').replace('>', '(?:>|>)').replace('&', '(?:&|&)').replace('"', '(?:"|")').replace(/\s+/g, '\\s+');
}
/**
* Determines where a code fragment occurs in the source code.
* @param {RegExp} re The function definition.
* @param {Array.<string>} urls A list of URLs to search.
* @return {?Object.<string, (string|number)>} An object containing
* the url, line, and column number of the defined function.
* @memberof TraceKit.computeStackTrace
*/
function findSourceInUrls(re, urls) {
var source, m;
for (var i = 0, j = urls.length; i < j; ++i) {
// console.log('searching', urls[i]);
if ((source = getSource(urls[i])).length) {
source = source.join('\n');
if ((m = re.exec(source))) {
// console.log('Found function in ' + urls[i]);
return {
'url': urls[i],
'line': source.substring(0, m.index).split('\n').length,
'column': m.index - source.lastIndexOf('\n', m.index) - 1
};
}
}
}
// console.log('no match');
return null;
}
/**
* Determines at which column a code fragment occurs on a line of the
* source code.
* @param {string} fragment The code fragment.
* @param {string} url The URL to search.
* @param {(string|number)} line The line number to examine.
* @return {?number} The column number.
* @memberof TraceKit.computeStackTrace
*/
function findSourceInLine(fragment, url, line) {
var source = getSource(url),
re = new RegExp('\\b' + escapeRegExp(fragment) + '\\b'),
m;
line -= 1;
if (source && source.length > line && (m = re.exec(source[line]))) {
return m.index;
}
return null;
}
/**
* Determines where a function was defined within the source code.
* @param {(Function|string)} func A function reference or serialized
* function definition.
* @return {?Object.<string, (string|number)>} An object containing
* the url, line, and column number of the defined function.
* @memberof TraceKit.computeStackTrace
*/
function findSourceByFunctionBody(func) {
if (_isUndefined(window && window.document)) {
return;
}
var urls = [window.location.href],
scripts = window.document.getElementsByTagName('script'),
body,
code = '' + func,
codeRE = /^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
eventRE = /^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,
re,
parts,
result;
for (var i = 0; i < scripts.length; ++i) {
var script = scripts[i];
if (script.src) {
urls.push(script.src);
}
}
if (!(parts = codeRE.exec(code))) {
re = new RegExp(escapeRegExp(code).replace(/\s+/g, '\\s+'));
}
// not sure if this is really necessary, but I don’t have a test
// corpus large enough to confirm that and it was in the original.
else {
var name = parts[1] ? '\\s+' + parts[1] : '',
args = parts[2].split(',').join('\\s*,\\s*');
body = escapeRegExp(parts[3]).replace(/;$/, ';?'); // semicolon is inserted if the function ends with a comment.replace(/\s+/g, '\\s+');
re = new RegExp('function' + name + '\\s*\\(\\s*' + args + '\\s*\\)\\s*{\\s*' + body + '\\s*}');
}
// look for a normal function definition
if ((result = findSourceInUrls(re, urls))) {
return result;
}
// look for an old-school event handler function
if ((parts = eventRE.exec(code))) {
var event = parts[1];
body = escapeCodeAsRegExpForMatchingInsideHTML(parts[2]);
// look for a function defined in HTML as an onXXX handler
re = new RegExp('on' + event + '=[\\\'"]\\s*' + body + '\\s*[\\\'"]', 'i');
if ((result = findSourceInUrls(re, urls[0]))) {
return result;
}
// look for ???
re = new RegExp(body);
if ((result = findSourceInUrls(re, urls))) {
return result;
}
}
return null;
}
// Contents of Exception in various browsers.
//
// SAFARI:
// ex.message = Can't find variable: qq
// ex.line = 59
// ex.sourceId = 580238192
// ex.sourceURL = http://...
// ex.expressionBeginOffset = 96
// ex.expressionCaretOffset = 98
// ex.expressionEndOffset = 98
// ex.name = ReferenceError
//
// FIREFOX:
// ex.message = qq is not defined
// ex.fileName = http://...
// ex.lineNumber = 59
// ex.columnNumber = 69
// ex.stack = ...stack trace... (see the example below)
// ex.name = ReferenceError
//
// CHROME:
// ex.message = qq is not defined
// ex.name = ReferenceError
// ex.type = not_defined
// ex.arguments = ['aa']
// ex.stack = ...stack trace...
//
// INTERNET EXPLORER:
// ex.message = ...
// ex.name = ReferenceError
//
// OPERA:
// ex.message = ...message... (see the example below)
// ex.name = ReferenceError
// ex.opera#sourceloc = 11 (pretty much useless, duplicates the info in ex.message)
// ex.stacktrace = n/a; see 'opera:config#UserPrefs|Exceptions Have Stacktrace'
/**
* Computes stack trace information from the stack property.
* Chrome and Gecko use this property.
* @param {Error} ex
* @return {?TraceKit.StackTrace} Stack trace information.
* @memberof TraceKit.computeStackTrace
*/
function computeStackTraceFromStackProp(ex) {
if (!ex.stack) {
return null;
}
var chrome = /^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|webpack|eval).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,
gecko = /^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|\[native).*?)(?::(\d+))?(?::(\d+))?\s*$/i,
winjs = /^\s*at (?:((?:\[object object\])?.+) )?\(?((?:ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,
lines = ex.stack.split('\n'),
stack = [],
parts,
element,
reference = /^(.*) is undefined$/.exec(ex.message);
for (var i = 0, j = lines.length; i < j; ++i) {
if ((parts = chrome.exec(lines[i]))) {
var isNative = parts[2] && parts[2].indexOf('native') !== -1;
element = {
'url': !isNative ? parts[2] : null,
'func': parts[1] || UNKNOWN_FUNCTION,
'args': isNative ? [parts[2]] : [],
'line': parts[3] ? +parts[3] : null,
'column': parts[4] ? +parts[4] : null
};
} else if ( parts = winjs.exec(lines[i]) ) {
element = {
'url': parts[2],
'func': parts[1] || UNKNOWN_FUNCTION,
'args': [],
'line': +parts[3],
'column': parts[4] ? +parts[4] : null
};
} else if ((parts = gecko.exec(lines[i]))) {
element = {
'url': parts[3],
'func': parts[1] || UNKNOWN_FUNCTION,
'args': parts[2] ? parts[2].split(',') : [],
'line': parts[4] ? +parts[4] : null,
'column': parts[5] ? +parts[5] : null
};
} else {
continue;
}
if (!element.func && element.line) {
element.func = guessFunctionName(element.url, element.line);
}
if (element.line) {
element.context = gatherContext(element.url, element.line);
}
stack.push(element);
}
if (!stack.length) {
return null;
}
if (stack[0] && stack[0].line && !stack[0].column && reference) {
stack[0].column = findSourceInLine(reference[1], stack[0].url, stack[0].line);
} else if (!stack[0].column && !_isUndefined(ex.columnNumber)) {
// FireFox uses this awesome columnNumber property for its top frame
// Also note, Firefox's column number is 0-based and everything else expects 1-based,
// so adding 1
stack[0].column = ex.columnNumber + 1;
}
return {
'mode': 'stack',
'name': ex.name,
'message': ex.message,
'stack': stack
};
}
/**
* Computes stack trace information from the stacktrace property.
* Opera 10+ uses this property.
* @param {Error} ex
* @return {?TraceKit.StackTrace} Stack trace information.
* @memberof TraceKit.computeStackTrace
*/
function computeStackTraceFromStacktraceProp(ex) {
// Access and store the stacktrace property before doing ANYTHING
// else to it because Opera is not very good at providing it
// reliably in other circumstances.
var stacktrace = ex.stacktrace;
if (!stacktrace) {
return;
}
var opera10Regex = / line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,
opera11Regex = / line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,
lines = stacktrace.split('\n'),
stack = [],
parts;
for (var line = 0; line < lines.length; line += 2) {
var element = null;
if ((parts = opera10Regex.exec(lines[line]))) {
element = {
'url': parts[2],
'line': +parts[1],
'column': null,
'func': parts[3],
'args':[]
};
} else if ((parts = opera11Regex.exec(lines[line]))) {
element = {
'url': parts[6],
'line': +parts[1],
'column': +parts[2],
'func': parts[3] || parts[4],
'args': parts[5] ? parts[5].split(',') : []
};
}
if (element) {
if (!element.func && element.line) {
element.func = guessFunctionName(element.url, element.line);
}
if (element.line) {
try {
element.context = gatherContext(element.url, element.line);
} catch (exc) {}
}
if (!element.context) {
element.context = [lines[line + 1]];
}
stack.push(element);
}
}
if (!stack.length) {
return null;
}
return {
'mode': 'stacktrace',
'name': ex.name,
'message': ex.message,
'stack': stack
};
}
/**
* NOT TESTED.
* Computes stack trace information from an error message that includes
* the stack trace.
* Opera 9 and earlier use this method if the option to show stack
* traces is turned on in opera:config.
* @param {Error} ex
* @return {?TraceKit.StackTrace} Stack information.
* @memberof TraceKit.computeStackTrace
*/
function computeStackTraceFromOperaMultiLineMessage(ex) {
// TODO: Clean this function up
// Opera includes a stack trace into the exception message. An example is:
//
// Statement on line 3: Undefined variable: undefinedFunc
// Backtrace:
// Line 3 of linked script file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.js: In function zzz
// undefinedFunc(a);
// Line 7 of inline#1 script in file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.html: In function yyy
// zzz(x, y, z);
// Line 3 of inline#1 script in file://localhost/Users/andreyvit/Projects/TraceKit/javascript-client/sample.html: In function xxx
// yyy(a, a, a);
// Line 1 of function script
// try { xxx('hi'); return false; } catch(ex) { TraceKit.report(ex); }
// ...
var lines = ex.message.split('\n');
if (lines.length < 4) {
return null;
}
var lineRE1 = /^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,
lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,
lineRE3 = /^\s*Line (\d+) of function script\s*$/i,
stack = [],
scripts = (window && window.document && window.document.getElementsByTagName('script')),
inlineScriptBlocks = [],
parts;
for (var s in scripts) {
if (_has(scripts, s) && !scripts[s].src) {
inlineScriptBlocks.push(scripts[s]);
}
}
for (var line = 2; line < lines.length; line += 2) {
var item = null;
if ((parts = lineRE1.exec(lines[line]))) {
item = {
'url': parts[2],
'func': parts[3],
'args': [],
'line': +parts[1],
'column': null
};
} else if ((parts = lineRE2.exec(lines[line]))) {
item = {
'url': parts[3],
'func': parts[4],
'args': [],
'line': +parts[1],
'column': null // TODO: Check to see if inline#1 (+parts[2]) points to the script number or column number.
};
var relativeLine = (+parts[1]); // relative to the start of the <SCRIPT> block
var script = inlineScriptBlocks[parts[2] - 1];
if (script) {
var source = getSource(item.url);
if (source) {
source = source.join('\n');
var pos = source.indexOf(script.innerText);
if (pos >= 0) {
item.line = relativeLine + source.substring(0, pos).split('\n').length;
}
}
}
} else if ((parts = lineRE3.exec(lines[line]))) {
var url = window.location.href.replace(/#.*$/, '');
var re = new RegExp(escapeCodeAsRegExpForMatchingInsideHTML(lines[line + 1]));
var src = findSourceInUrls(re, [url]);
item = {
'url': url,
'func': '',
'args': [],
'line': src ? src.line : parts[1],
'column': null
};
}
if (item) {
if (!item.func) {
item.func = guessFunctionName(item.url, item.line);
}
var context = gatherContext(item.url, item.line);
var midline = (context ? context[Math.floor(context.length / 2)] : null);
if (context && midline.replace(/^\s*/, '') === lines[line + 1].replace(/^\s*/, '')) {
item.context = context;
} else {
// if (context) alert("Context mismatch. Correct midline:\n" + lines[i+1] + "\n\nMidline:\n" + midline + "\n\nContext:\n" + context.join("\n") + "\n\nURL:\n" + item.url);
item.context = [lines[line + 1]];
}
stack.push(item);
}
}
if (!stack.length) {
return null; // could not parse multiline exception message as Opera stack trace
}
return {
'mode': 'multiline',
'name': ex.name,
'message': lines[0],
'stack': stack
};
}
/**
* Adds information about the first frame to incomplete stack traces.
* Safari and IE require this to get complete data on the first frame.
* @param {TraceKit.StackTrace} stackInfo Stack trace information from
* one of the compute* methods.
* @param {string} url The URL of the script that caused an error.
* @param {(number|string)} lineNo The line number of the script that
* caused an error.
* @param {string=} message The error generated by the browser, which
* hopefully contains the name of the object that caused the error.
* @return {boolean} Whether or not the stack information was
* augmented.
* @memberof TraceKit.computeStackTrace
*/
function augmentStackTraceWithInitialElement(stackInfo, url, lineNo, message) {
var initial = {
'url': url,
'line': lineNo
};
if (initial.url && initial.line) {
stackInfo.incomplete = false;
if (!initial.func) {
initial.func = guessFunctionName(initial.url, initial.line);
}
if (!initial.context) {
initial.context = gatherContext(initial.url, initial.line);
}
var reference = / '([^']+)' /.exec(message);
if (reference) {
initial.column = findSourceInLine(reference[1], initial.url, initial.line);
}
if (stackInfo.stack.length > 0) {
if (stackInfo.stack[0].url === initial.url) {
if (stackInfo.stack[0].line === initial.line) {
return false; // already in stack trace
} else if (!stackInfo.stack[0].line && stackInfo.stack[0].func === initial.func) {
stackInfo.stack[0].line = initial.line;
stackInfo.stack[0].context = initial.context;
return false;
}
}
}
stackInfo.stack.unshift(initial);
stackInfo.partial = true;
return true;
} else {
stackInfo.incomplete = true;
}
return false;
}
/**
* Computes stack trace information by walking the arguments.caller
* chain at the time the exception occurred. This will cause earlier
* frames to be missed but is the only way to get any stack trace in
* Safari and IE. The top frame is restored by
* {@link augmentStackTraceWithInitialElement}.
* @param {Error} ex
* @return {TraceKit.StackTrace=} Stack trace information.
* @memberof TraceKit.computeStackTrace
*/
function computeStackTraceByWalkingCallerChain(ex, depth) {
var functionName = /function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,
stack = [],
funcs = {},
recursion = false,
parts,
item,
source;
for (var curr = computeStackTraceByWalkingCallerChain.caller; curr && !recursion; curr = curr.caller) {
if (curr === computeStackTrace || curr === TraceKit.report) {
// console.log('skipping internal function');
continue;
}
item = {
'url': null,
'func': UNKNOWN_FUNCTION,
'args': [],
'line': null,
'column': null
};
if (curr.name) {
item.func = curr.name;
} else if ((parts = functionName.exec(curr.toString()))) {
item.func = parts[1];
}
if (typeof item.func === 'undefined') {
try {
item.func = parts.input.substring(0, parts.input.indexOf('{'));
} catch (e) { }
}
if ((source = findSourceByFunctionBody(curr))) {
item.url = source.url;
item.line = source.line;
if (item.func === UNKNOWN_FUNCTION) {
item.func = guessFunctionName(item.url, item.line);
}
var reference = / '([^']+)' /.exec(ex.message || ex.description);
if (reference) {
item.column = findSourceInLine(reference[1], source.url, source.line);
}
}
if (funcs['' + curr]) {
recursion = true;
}else{
funcs['' + curr] = true;
}
stack.push(item);
}
if (depth) {
// console.log('depth is ' + depth);
// console.log('stack is ' + stack.length);
stack.splice(0, depth);
}
var result = {
'mode': 'callers',
'name': ex.name,
'message': ex.message,
'stack': stack
};
augmentStackTraceWithInitialElement(result, ex.sourceURL || ex.fileName, ex.line || ex.lineNumber, ex.message || ex.description);
return result;
}
/**
* Computes a stack trace for an exception.
* @param {Error} ex
* @param {(string|number)=} depth
* @memberof TraceKit.computeStackTrace
*/
function computeStackTrace(ex, depth) {
var stack = null;
depth = (depth == null ? 0 : +depth);
try {
// This must be tried first because Opera 10 *destroys*
// its stacktrace property if you try to access the stack
// property first!!
stack = computeStackTraceFromStacktraceProp(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceFromStackProp(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceFromOperaMultiLineMessage(ex);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
try {
stack = computeStackTraceByWalkingCallerChain(ex, depth + 1);
if (stack) {
return stack;
}
} catch (e) {
if (debug) {
throw e;
}
}
return {
'mode': 'failed'
};
}
/**
* Logs a stacktrace starting from the previous call and working down.
* @param {(number|string)=} depth How many frames deep to trace.
* @return {TraceKit.StackTrace} Stack trace information.
* @memberof TraceKit.computeStackTrace
*/
function computeStackTraceOfCaller(depth) {
depth = (depth == null ? 0 : +depth) + 1; // "+ 1" because "ofCaller" should drop one frame
try {
throw new Error();
} catch (ex) {
return computeStackTrace(ex, depth + 1);
}
}
computeStackTrace.augmentStackTraceWithInitialElement = augmentStackTraceWithInitialElement;
computeStackTrace.guessFunctionName = guessFunctionName;
computeStackTrace.gatherContext = gatherContext;
computeStackTrace.ofCaller = computeStackTraceOfCaller;
computeStackTrace.getSource = getSource;
return computeStackTrace;
}());
/**
* Extends support for global error handling for asynchronous browser
* functions. Adopted from Closure Library's errorhandler.js
* @memberof TraceKit
*/
TraceKit.extendToAsynchronousCallbacks = function () {
var _helper = function _helper(fnName) {
var originalFn = window[fnName];
window[fnName] = function traceKitAsyncExtension() {
// Make a copy of the arguments
var args = _slice.call(arguments);
var originalCallback = args[0];
if (typeof (originalCallback) === 'function') {
args[0] = TraceKit.wrap(originalCallback);
}
// IE < 9 doesn't support .call/.apply on setInterval/setTimeout, but it
// also only supports 2 argument and doesn't care what "this" is, so we
// can just call the original function directly.
if (originalFn.apply) {
return originalFn.apply(this, args);
} else {
return originalFn(args[0], args[1]);
}
};
};
_helper('setTimeout');
_helper('setInterval');
};
//Default options:
if (!TraceKit.remoteFetching) {
TraceKit.remoteFetching = true;
}
if (!TraceKit.collectWindowErrors) {
TraceKit.collectWindowErrors = true;
}
if (!TraceKit.linesOfContext || TraceKit.linesOfContext < 1) {
// 5 lines before, the offending line, 5 lines after
TraceKit.linesOfContext = 11;
}
// UMD export
if (typeof module !== 'undefined' && module.exports && window.module !== module) {
module.exports = TraceKit;
} else if (typeof define === 'function' && define.amd) {
define('TraceKit', [], TraceKit);
} else {
window.TraceKit = TraceKit;
}
}(typeof window !== 'undefined' ? window : global));
(function(root, factory) {
var require, exports, module;
if (typeof define === 'function' && define.amd) {
define('exceptionless', ["require","exports","module","TraceKit"], factory);
} else if (typeof exports === 'object') {
module.exports = factory(require, exports, module, require('TraceKit'));
} else {
root.exceptionless = factory(require, exports, module, root.TraceKit);
}
}(this, function(require, exports, module, TraceKit) {
if (!require) {
require = function(name) {
return (typeof window !== "undefined" ? window : global)[name];
}
}
if (!exports) {
var exports = {};
}
"use strict";
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var TraceKit = require('TraceKit');
var SubmissionResponse = (function () {
function SubmissionResponse(statusCode, message) {
this.success = false;
this.badRequest = false;
this.serviceUnavailable = false;
this.paymentRequired = false;
this.unableToAuthenticate = false;
this.notFound = false;
this.requestEntityTooLarge = false;
this.statusCode = statusCode;
this.message = message;
this.success = statusCode >= 200 && statusCode <= 299;
this.badRequest = statusCode === 400;
this.serviceUnavailable = statusCode === 503;
this.paymentRequired = statusCode === 402;
this.unableToAuthenticate = statusCode === 401 || statusCode === 403;
this.notFound = statusCode === 404;
this.requestEntityTooLarge = statusCode === 413;
}
return SubmissionResponse;
}());
exports.SubmissionResponse = SubmissionResponse;
var SettingsManager = (function () {
function SettingsManager() {
}
SettingsManager.onChanged = function (handler) {
!!handler && this._handlers.push(handler);
};
SettingsManager.applySavedServerSettings = function (config) {
if (!config || !config.isValid) {
return;
}
var savedSettings = this.getSavedServerSettings(config);
config.log.info("Applying saved settings: v" + savedSettings.version);
config.settings = Utils.merge(config.settings, savedSettings.settings);
this.changed(config);
};
SettingsManager.getVersion = function (config) {
if (!config || !config.isValid) {
return 0;
}
var savedSettings = this.getSavedServerSettings(config);
return savedSettings.version || 0;
};
SettingsManager.checkVersion = function (version, config) {
var currentVersion = this.getVersion(config);
if (version <= currentVersion) {
return;
}
config.log.info("Updating settings from v" + currentVersion + " to v" + version);
this.updateSettings(config, currentVersion);
};
SettingsManager.updateSettings = function (config, version) {
var _this = this;
if (!config || !config.enabled) {
return;
}
var unableToUpdateMessage = 'Unable to update settings';
if (!config.isValid) {
config.log.error(unableToUpdateMessage + ": ApiKey is not set.");
return;
}
if (!version || version < 0) {
version = this.getVersion(config);
}
config.log.info("Checking for updated settings from: v" + version + ".");
config.submissionClient.getSettings(config, version, function (response) {
if (!config || !response || !response.success || !response.settings) {
config.log.warn(unableToUpdateMessage + ": " + response.message);
return;
}
config.settings = Utils.merge(config.settings, response.settings);
var savedServerSettings = SettingsManager.getSavedServerSettings(config);
for (var key in savedServerSettings) {
if (response.settings[key]) {
continue;
}
delete config.settings[key];
}
var newSettings = {
version: response.settingsVersion,
settings: response.settings
};
config.storage.settings.save(newSettings);
config.log.info("Updated settings: v" + newSettings.version);
_this.changed(config);
});
};
SettingsManager.changed = function (config) {
var handlers = this._handlers;
for (var index = 0; index < handlers.length; index++) {
try {
handlers[index](config);
}
catch (ex) {
config.log.error("Error calling onChanged handler: " + ex);
}
}
};
SettingsManager.getSavedServerSettings = function (config) {
var item = config.storage.settings.get()[0];
if (item && item.value && item.value.version && item.value.settings) {
return item.value;
}
return { version: 0, settings: {} };
};
SettingsManager._handlers = [];
return SettingsManager;
}());
exports.SettingsManager = SettingsManager;
var DefaultLastReferenceIdManager = (function () {
function DefaultLastReferenceIdManager() {
this._lastReferenceId = null;
}
DefaultLastReferenceIdManager.prototype.getLast = function () {
return this._lastReferenceId;
};
DefaultLastReferenceIdManager.prototype.clearLast = function () {
this._lastReferenceId = null;
};
DefaultLastReferenceIdManager.prototype.setLast = function (eventId) {
this._lastReferenceId = eventId;
};
return DefaultLastReferenceIdManager;
}());
exports.DefaultLastReferenceIdManager = DefaultLastReferenceIdManager;
var ConsoleLog = (function () {
function ConsoleLog() {
}
ConsoleLog.prototype.trace = function (message) {
this.log('trace', message);
};
ConsoleLog.prototype.info = function (message) {
this.log('info', message);
};
ConsoleLog.prototype.warn = function (message) {
this.log('warn', message);
};
ConsoleLog.prototype.error = function (message) {
this.log('error', message);
};
ConsoleLog.prototype.log = function (level, message) {
if (console) {
var msg = "[" + level + "] Exceptionless: " + message;
if (console[level]) {
console[level](msg);
}
else if (console.log) {
console["log"](msg);
}
}
};
return ConsoleLog;
}());
exports.ConsoleLog = ConsoleLog;
var NullLog = (function () {
function NullLog() {
}
NullLog.prototype.trace = function (message) { };
NullLog.prototype.info = function (message) { };
NullLog.prototype.warn = function (message) { };
NullLog.prototype.error = function (message) { };
return NullLog;
}());
exports.NullLog = NullLog;
var EventPluginContext = (function () {
function EventPluginContext(client, event, contextData) {
this.client = client;
this.event = event;
this.contextData = contextData ? contextData : new ContextData();
}
Object.defineProperty(EventPluginContext.prototype, "log", {
get: function () {
return this.client.config.log;
},
enumerable: true,
configurable: true
});
return EventPluginContext;
}());
exports.EventPluginContext = EventPluginContext;
var EventPluginManager = (function () {
function EventPluginManager() {
}
EventPluginManager.run = function (context, callback) {
var wrap = function (plugin, next) {
return function () {
try {
if (!context.cancelled) {
plugin.run(context, next);
}
}
catch (ex) {
context.cancelled = true;
context.log.error("Error running plugin '" + plugin.name + "': " + ex.message + ". Discarding Event.");
}
if (context.cancelled && !!callback) {
callback(context);
}
};
};
var plugins = context.client.config.plugins;
var wrappedPlugins = [];
if (!!callback) {
wrappedPlugins[plugins.length] = wrap({ name: 'cb', priority: 9007199254740992, run: callback }, null);
}
for (var index = plugins.length - 1; index > -1; index--) {
wrappedPlugins[index] = wrap(plugins[index], !!callback || (index < plugins.length - 1) ? wrappedPlugins[index + 1] : null);
}
wrappedPlugins[0]();
};
EventPluginManager.addDefaultPlugins = function (config) {
config.addPlugin(new ConfigurationDefaultsPlugin());
config.addPlugin(new ErrorPlugin());
config.addPlugin(new DuplicateCheckerPlugin());
config.addPlugin(new EventExclusionPlugin());
config.addPlugin(new ModuleInfoPlugin());
config.addPlugin(new RequestInfoPlugin());
config.addPlugin(new EnvironmentInfoPlugin());
config.addPlugin(new SubmissionMethodPlugin());
};
return EventPluginManager;
}());
exports.EventPluginManager = EventPluginManager;
var HeartbeatPlugin = (function () {
function HeartbeatPlugin(heartbeatInterval) {
if (heartbeatInterval === void 0) { heartbeatInterval = 30000; }
this.priority = 100;
this.name = 'HeartbeatPlugin';
this._interval = heartbeatInterval;
}
HeartbeatPlugin.prototype.run = function (context, next) {
clearInterval(this._intervalId);
var user = context.event.data['@user'];
if (user && user.identity) {
this._intervalId = setInterval(function () { return context.client.submitSessionHeartbeat(user.identity); }, this._interval);
}
next && next();
};
return HeartbeatPlugin;
}());
exports.HeartbeatPlugin = HeartbeatPlugin;
var ReferenceIdPlugin = (function () {
function ReferenceIdPlugin() {
this.priority = 20;
this.name = 'ReferenceIdPlugin';
}
ReferenceIdPlugin.prototype.run = function (context, next) {
if ((!context.event.reference_id || context.event.reference_id.length === 0) && context.event.type === 'error') {
context.event.reference_id = Utils.guid().replace('-', '').substring(0, 10);
}
next && next();
};
return ReferenceIdPlugin;
}());
exports.ReferenceIdPlugin = ReferenceIdPlugin;
var DefaultEventQueue = (function () {
function DefaultEventQueue(config) {
this._handlers = [];
this._processingQueue = false;
this._config = config;
}
DefaultEventQueue.prototype.enqueue = function (event) {
var eventWillNotBeQueued = 'The event will not be queued.';
var config = this._config;
var log = config.log;
if (!config.enabled) {
log.info("Configuration is disabled. " + eventWillNotBeQueued);
return;
}
if (!config.isValid) {
log.info("Invalid Api Key. " + eventWillNotBeQueued);
return;
}
if (this.areQueuedItemsDiscarded()) {
log.info("Queue items are currently being discarded. " + eventWillNotBeQueued);
return;
}
this.ensureQueueTimer();
var timestamp = config.storage.queue.save(event);
var logText = "type=" + event.type + " " + (!!event.reference_id ? 'refid=' + event.reference_id : '');
if (timestamp) {
log.info("Enqueuing event: " + timestamp + " " + logText);
}
else {
log.error("Could not enqueue event " + logText);
}
};
DefaultEventQueue.prototype.process = function (isAppExiting) {
var _this = this;
var queueNotProcessed = 'The queue will not be processed.';
var config = this._config;
var log = config.log;
if (this._processingQueue) {
return;
}
log.info('Processing queue...');
if (!config.enabled) {
log.info("Configuration is disabled. " + queueNotProcessed);
return;
}
if (!config.isValid) {
log.info("Invalid Api Key. " + queueNotProcessed);
return;
}
this._processingQueue = true;
this.ensureQueueTimer();
try {
var events_1 = config.storage.queue.get(config.submissionBatchSize);
if (!events_1 || events_1.length === 0) {
this._processingQueue = false;
return;
}
log.info("Sending " + events_1.length + " events to " + config.serverUrl + ".");
config.submissionClient.postEvents(events_1.map(function (e) { return e.value; }), config, function (response) {
_this.processSubmissionResponse(response, events_1);
_this.eventsPosted(events_1.map(function (e) { return e.value; }), response);
log.info('Finished processing queue.');
_this._processingQueue = false;
}, isAppExiting);
}
catch (ex) {
log.error("Error processing queue: " + ex);
this.suspendProcessing();
this._processingQueue = false;
}
};
DefaultEventQueue.prototype.suspendProcessing = function (durationInMinutes, discardFutureQueuedItems, clearQueue) {
var config = this._config;
if (!durationInMinutes || durationInMinutes <= 0) {
durationInMinutes = 5;
}
config.log.info("Suspending processing for " + durationInMinutes + " minutes.");
this._suspendProcessingUntil = new Date(new Date().getTime() + (durationInMinutes * 60000));
if (discardFutureQueuedItems) {
this._discardQueuedItemsUntil = this._suspendProcessingUntil;
}
if (clearQueue) {
config.storage.queue.clear();
}
};
DefaultEventQueue.prototype.onEventsPosted = function (handler) {
!!handler && this._handlers.push(handler);
};
DefaultEventQueue.prototype.eventsPosted = function (events, response) {
var handlers = this._handlers;
for (var index = 0; index < handlers.length; index++) {
try {
handlers[index](events, response);
}
catch (ex) {
this._config.log.error("Error calling onEventsPosted handler: " + ex);
}
}
};
DefaultEventQueue.prototype.areQueuedItemsDiscarded = function () {
return this._discardQueuedItemsUntil && this._discardQueuedItemsUntil > new Date();
};
DefaultEventQueue.prototype.ensureQueueTimer = function () {
var _this = this;
if (!this._queueTimer) {
this._queueTimer = setInterval(function () { return _this.onProcessQueue(); }, 10000);
}
};
DefaultEventQueue.prototype.isQueueProcessingSuspended = function () {
return this._suspendProcessingUntil && this._suspendProcessingUntil > new Date();
};
DefaultEventQueue.prototype.onProcessQueue = function () {
if (!this.isQueueProcessingSuspended() && !this._processingQueue) {
this.process();
}
};
DefaultEventQueue.prototype.processSubmissionResponse = function (response, events) {
var noSubmission = 'The event will not be submitted.';
var config = this._config;
var log = config.log;
if (response.success) {
log.info("Sent " + events.length + " events.");
this.removeEvents(events);
return;
}
if (response.serviceUnavailable) {
log.error('Server returned service unavailable.');
this.suspendProcessing();
return;
}
if (response.paymentRequired) {
log.info('Too many events have been submitted, please upgrade your plan.');
this.suspendProcessing(null, true, true);
return;
}
if (response.unableToAuthenticate) {
log.info("Unable to authenticate, please check your configuration. " + noSubmission);
this.suspendProcessing(15);
this.removeEvents(events);
return;
}
if (response.notFound || response.badRequest) {
log.error("Error while trying to submit data: " + response.message);
this.suspendProcessing(60 * 4);
this.removeEvents(events);
return;
}
if (response.requestEntityTooLarge) {
var message = 'Event submission discarded for being too large.';
if (config.submissionBatchSize > 1) {
log.error(message + " Retrying with smaller batch size.");
config.submissionBatchSize = Math.max(1, Math.round(config.submissionBatchSize / 1.5));
}
else {
log.error(message + " " + noSubmission);
this.removeEvents(events);
}
return;
}
if (!response.success) {
log.error("Error submitting events: " + (response.message || 'Please check the network tab for more info.'));
this.suspendProcessing();
}
};
DefaultEventQueue.prototype.removeEvents = function (events) {
for (var index = 0; index < (events || []).length; index++) {
this._config.storage.queue.remove(events[index].timestamp);
}
};
return DefaultEventQueue;
}());
exports.DefaultEventQueue = DefaultEventQueue;
var InMemoryStorageProvider = (function () {
function InMemoryStorageProvider(maxQueueItems) {
if (maxQueueItems === void 0) { maxQueueItems = 250; }
this.queue = new InMemoryStorage(maxQueueItems);
this.settings = new InMemoryStorage(1);
}
return InMemoryStorageProvider;
}());
exports.InMemoryStorageProvider = InMemoryStorageProvider;
var DefaultSubmissionClient = (function () {
function DefaultSubmissionClient() {
this.configurationVersionHeader = 'x-exceptionless-configversion';
}
DefaultSubmissionClient.prototype.postEvents = function (events, config, callback, isAppExiting) {
var data = JSON.stringify(events);
var request = this.createRequest(config, 'POST', config.serverUrl + "/api/v2/events", data);
var cb = this.createSubmissionCallback(config, callback);
return config.submissionAdapter.sendRequest(request, cb, isAppExiting);
};
DefaultSubmissionClient.prototype.postUserDescription = function (referenceId, description, config, callback) {
var path = config.serverUrl + "/api/v2/events/by-ref/" + encodeURIComponent(referenceId) + "/user-description";
var data = JSON.stringify(description);
var request = this.createRequest(config, 'POST', path, data);
var cb = this.createSubmissionCallback(config, callback);
return config.submissionAdapter.sendRequest(request, cb);
};
DefaultSubmissionClient.prototype.getSettings = function (config, version, callback) {
var request = this.createRequest(config, 'GET', config.serverUrl + "/api/v2/projects/config?v=" + version);
var cb = function (status, message, data, headers) {
if (status !== 200) {
return callback(new SettingsResponse(false, null, -1, null, message));
}
var settings;
try {
settings = JSON.parse(data);
}
catch (e) {
config.log.error("Unable to parse settings: '" + data + "'");
}
if (!settings || isNaN(settings.version)) {
return callback(new SettingsResponse(false, null, -1, null, 'Invalid configuration settings.'));
}
callback(new SettingsResponse(true, settings.settings || {}, settings.version));
};
return config.submissionAdapter.sendRequest(request, cb);
};
DefaultSubmissionClient.prototype.sendHeartbeat = function (sessionIdOrUserId, closeSession, config) {
var request = this.createRequest(config, 'GET', config.heartbeatServerUrl + "/api/v2/events/session/heartbeat?id=" + sessionIdOrUserId + "&close=" + closeSession);
config.submissionAdapter.sendRequest(request);
};
DefaultSubmissionClient.prototype.createRequest = function (config, method, url, data) {
if (data === void 0) { data = null; }
return {
method: method,
url: url,
data: data,
apiKey: config.apiKey,
userAgent: config.userAgent
};
};
DefaultSubmissionClient.prototype.createSubmissionCallback = function (config, callback) {
var _this = this;
return function (status, message, data, headers) {
var settingsVersion = headers && parseInt(headers[_this.configurationVersionHeader], 10);
SettingsManager.checkVersion(settingsVersion, config);
callback(new SubmissionResponse(status, message));
};
};
return DefaultSubmissionClient;
}());
exports.DefaultSubmissionClient = DefaultSubmissionClient;
var Utils = (function () {
function Utils() {
}
Utils.addRange = function (target) {
var values = [];
for (var _i = 1; _i < arguments.length; _i++) {
values[_i - 1] = arguments[_i];
}
if (!target) {
target = [];
}
if (!values || values.length === 0) {
return target;
}
for (var index = 0; index < values.length; index++) {
if (values[index] && target.indexOf(values[index]) < 0) {
target.push(values[index]);
}
}
return target;
};
Utils.getHashCode = function (source) {
if (!source || source.length === 0) {
return 0;
}
var hash = 0;
for (var index = 0; index < source.length; index++) {
var character = source.charCodeAt(index);
hash = ((hash << 5) - hash) + character;
hash |= 0;
}
return hash;
};
Utils.getCookies = function (cookies, exclusions) {
var result = {};
var parts = (cookies || '').split('; ');
for (var index = 0; index < parts.length; index++) {
var cookie = parts[index].split('=');
if (!Utils.isMatch(cookie[0], exclusions)) {
result[cookie[0]] = cookie[1];
}
}
return !Utils.isEmpty(result) ? result : null;
};
Utils.guid = function () {
function s4() {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
};
Utils.merge = function (defaultValues, values) {
var result = {};
for (var key in defaultValues || {}) {
if (!!defaultValues[key]) {
result[key] = defaultValues[key];
}
}
for (var key in values || {}) {
if (!!values[key]) {
result[key] = values[key];
}
}
return result;
};
Utils.parseVersion = function (source) {
if (!source) {
return null;
}
var versionRegex = /(v?((\d+)\.(\d+)(\.(\d+))?)(?:-([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?(?:\+([\dA-Za-z\-]+(?:\.[\dA-Za-z\-]+)*))?)/;
var matches = versionRegex.exec(source);
if (matches && matches.length > 0) {
return matches[0];
}
return null;
};
Utils.parseQueryString = function (query, exclusions) {
if (!query || query.length === 0) {
return null;
}
var pairs = query.split('&');
if (pairs.length === 0) {
return null;
}
var result = {};
for (var index = 0; index < pairs.length; index++) {
var pair = pairs[index].split('=');
if (!Utils.isMatch(pair[0], exclusions)) {
result[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1]);
}
}
return !Utils.isEmpty(result) ? result : null;
};
Utils.randomNumber = function () {
return Math.floor(Math.random() * 9007199254740992);
};
Utils.isMatch = function (input, patterns, ignoreCase) {
if (ignoreCase === void 0) { ignoreCase = true; }
if (!input || typeof input !== 'string') {
return false;
}
var trim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
input = (ignoreCase ? input.toLowerCase() : input).replace(trim, '');
return (patterns || []).some(function (pattern) {
if (typeof pattern !== 'string') {
return false;
}
pattern = (ignoreCase ? pattern.toLowerCase() : pattern).replace(trim, '');
if (pattern.length <= 0) {
return false;
}
var startsWithWildcard = pattern[0] === '*';
if (startsWithWildcard) {
pattern = pattern.slice(1);
}
var endsWithWildcard = pattern[pattern.length - 1] === '*';
if (endsWithWildcard) {
pattern = pattern.substring(0, pattern.length - 1);
}
if (startsWithWildcard && endsWithWildcard) {
return pattern.length <= input.length && input.indexOf(pattern, 0) !== -1;
}
if (startsWithWildcard) {
return Utils.endsWith(input, pattern);
}
if (endsWithWildcard) {
return Utils.startsWith(input, pattern);
}
return input === pattern;
});
};
Utils.isEmpty = function (input) {
return input === null || (typeof (input) === 'object' && Object.keys(input).length === 0);
};
Utils.startsWith = function (input, prefix) {
return input.substring(0, prefix.length) === prefix;
};
Utils.endsWith = function (input, suffix) {
return input.indexOf(suffix, input.length - suffix.length) !== -1;
};
Utils.stringify = function (data, exclusions, maxDepth) {
function stringifyImpl(obj, excludedKeys) {
var cache = [];
return JSON.stringify(obj, function (key, value) {
if (Utils.isMatch(key, excludedKeys)) {
return;
}
if (typeof value === 'object' && !!value) {
if (cache.indexOf(value) !== -1) {
return;
}
cache.push(value);
}
return value;
});
}
if (({}).toString.call(data) === '[object Object]') {
var flattened = {};
for (var prop in data) {
var value = data[prop];
if (value === data) {
continue;
}
flattened[prop] = data[prop];
}
return stringifyImpl(flattened, exclusions);
}
if (({}).toString.call(data) === '[object Array]') {
var result = [];
for (var index = 0; index < data.length; index++) {
result[index] = JSON.parse(stringifyImpl(data[index], exclusions));
}
return JSON.stringify(result);
}
return stringifyImpl(data, exclusions);
};
Utils.toBoolean = function (input, defaultValue) {
if (defaultValue === void 0) { defaultValue = false; }
if (typeof input === 'boolean') {
return input;
}
if (input === null || typeof input !== 'number' && typeof input !== 'string') {
return defaultValue;
}
switch ((input + '').toLowerCase().trim()) {
case 'true':
case 'yes':
case '1': return true;
case 'false':
case 'no':
case '0':
case null: return false;
}
return defaultValue;
};
return Utils;
}());
exports.Utils = Utils;
var Configuration = (function () {
function Configuration(configSettings) {
this.defaultTags = [];
this.defaultData = {};
this.enabled = true;
this.lastReferenceIdManager = new DefaultLastReferenceIdManager();
this.settings = {};
this._serverUrl = 'https://collector.exceptionless.io';
this._heartbeatServerUrl = 'https://heartbeat.exceptionless.io';
this._updateSettingsWhenIdleInterval = 120000;
this._dataExclusions = [];
this._userAgentBotPatterns = [];
this._plugins = [];
this._handlers = [];
function inject(fn) {
return typeof fn === 'function' ? fn(this) : fn;
}
configSettings = Utils.merge(Configuration.defaults, configSettings);
this.log = inject(configSettings.log) || new NullLog();
this.apiKey = configSettings.apiKey;
this.serverUrl = configSettings.serverUrl;
this.heartbeatServerUrl = configSettings.heartbeatServerUrl;
this.updateSettingsWhenIdleInterval = configSettings.updateSettingsWhenIdleInterval;
this.environmentInfoCollector = inject(configSettings.environmentInfoCollector);
this.errorParser = inject(configSettings.errorParser);
this.lastReferenceIdManager = inject(configSettings.lastReferenceIdManager) || new DefaultLastReferenceIdManager();
this.moduleCollector = inject(configSettings.moduleCollector);
this.requestInfoCollector = inject(configSettings.requestInfoCollector);
this.submissionBatchSize = inject(configSettings.submissionBatchSize) || 50;
this.submissionAdapter = inject(configSettings.submissionAdapter);
this.submissionClient = inject(configSettings.submissionClient) || new DefaultSubmissionClient();
this.storage = inject(configSettings.storage) || new InMemoryStorageProvider();
this.queue = inject(configSettings.queue) || new DefaultEventQueue(this);
SettingsManager.applySavedServerSettings(this);
EventPluginManager.addDefaultPlugins(this);
}
Object.defineProperty(Configuration.prototype, "apiKey", {
get: function () {
return this._apiKey;
},
set: function (value) {
this._apiKey = value || null;
this.log.info("apiKey: " + this._apiKey);
this.changed();
},
enumerable: true,
configurable: true
});
Object.defineProperty(Configuration.prototype, "isValid", {
get: function () {
return !!this.apiKey && this.apiKey.length >= 10;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Configuration.prototype, "serverUrl", {
get: function () {
return this._serverUrl;
},
set: function (value) {
if (!!value) {
this._serverUrl = value;
this._heartbeatServerUrl = value;
this.log.info("serverUrl: " + value);
this.changed();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Configuration.prototype, "heartbeatServerUrl", {
get: function () {
return this._heartbeatServerUrl;
},
set: function (value) {
if (!!value) {
this._heartbeatServerUrl = value;
this.log.info("heartbeatServerUrl: " + value);
this.changed();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(Configuration.prototype, "updateSettingsWhenIdleInterval", {
get: function () {
return this._updateSettingsWhenIdleInterval;
},
set: function (value) {
if (typeof value !== 'number') {
return;
}
if (value <= 0) {
value = -1;
}
else if (value > 0 && value < 15000) {
value = 15000;
}
this._updateSettingsWhenIdleInterval = value;
this.log.info("updateSettingsWhenIdleInterval: " + value);
this.changed();
},
enumerable: true,
configurable: true
});
Object.defineProperty(Configuration.prototype, "dataExclusions", {
get: function () {
var exclusions = this.settings['@@DataExclusions'];
return this._dataExclusions.concat(exclusions && exclusions.split(',') || []);
},
enumerable: true,
configurable: true
});
Configuration.prototype.addDataExclusions = function () {
var exclusions = [];
for (var _i = 0; _i < arguments.length; _i++) {
exclusions[_i - 0] = arguments[_i];
}
this._dataExclusions = Utils.addRange.apply(Utils, [this._dataExclusions].concat(exclusions));
};
Object.defineProperty(Configuration.prototype, "userAgentBotPatterns", {
get: function () {
var patterns = this.settings['@@UserAgentBotPatterns'];
return this._userAgentBotPatterns.concat(patterns && patterns.split(',') || []);
},
enumerable: true,
configurable: true
});
Configuration.prototype.addUserAgentBotPatterns = function () {
var userAgentBotPatterns = [];
for (var _i = 0; _i < arguments.length; _i++) {
userAgentBotPatterns[_i - 0] = arguments[_i];
}
this._userAgentBotPatterns = Utils.addRange.apply(Utils, [this._userAgentBotPatterns].concat(userAgentBotPatterns));
};
Object.defineProperty(Configuration.prototype, "plugins", {
get: function () {
return this._plugins.sort(function (p1, p2) {
return (p1.priority < p2.priority) ? -1 : (p1.priority > p2.priority) ? 1 : 0;
});
},
enumerable: true,
configurable: true
});
Configuration.prototype.addPlugin = function (pluginOrName, priority, pluginAction) {
var plugin = !!pluginAction ? { name: pluginOrName, priority: priority, run: pluginAction } : pluginOrName;
if (!plugin || !plugin.run) {
this.log.error('Add plugin failed: Run method not defined');
return;
}
if (!plugin.name) {
plugin.name = Utils.guid();
}
if (!plugin.priority) {
plugin.priority = 0;
}
var pluginExists = false;
var plugins = this._plugins;
for (var index = 0; index < plugins.length; index++) {
if (plugins[index].name === plugin.name) {
pluginExists = true;
break;
}
}
if (!pluginExists) {
plugins.push(plugin);
}
};
Configuration.prototype.removePlugin = function (pluginOrName) {
var name = typeof pluginOrName === 'string' ? pluginOrName : pluginOrName.name;
if (!name) {
this.log.error('Remove plugin failed: Plugin name not defined');
return;
}
var plugins = this._plugins;
for (var index = 0; index < plugins.length; index++) {
if (plugins[index].name === name) {
plugins.splice(index, 1);
break;
}
}
};
Configuration.prototype.setVersion = function (version) {
if (!!version) {
this.defaultData['@version'] = version;
}
};
Configuration.prototype.setUserIdentity = function (userInfoOrIdentity, name) {
var USER_KEY = '@user';
var userInfo = typeof userInfoOrIdentity !== 'string' ? userInfoOrIdentity : { identity: userInfoOrIdentity, name: name };
var shouldRemove = !userInfo || (!userInfo.identity && !userInfo.name);
if (shouldRemove) {
delete this.defaultData[USER_KEY];
}
else {
this.defaultData[USER_KEY] = userInfo;
}
this.log.info("user identity: " + (shouldRemove ? 'null' : userInfo.identity));
};
Object.defineProperty(Configuration.prototype, "userAgent", {
get: function () {
return 'exceptionless-js/1.4.3';
},
enumerable: true,
configurable: true
});
Configuration.prototype.useSessions = function (sendHeartbeats, heartbeatInterval) {
if (sendHeartbeats === void 0) { sendHeartbeats = true; }
if (heartbeatInterval === void 0) { heartbeatInterval = 30000; }
if (sendHeartbeats) {
this.addPlugin(new HeartbeatPlugin(heartbeatInterval));
}
};
Configuration.prototype.useReferenceIds = function () {
this.addPlugin(new ReferenceIdPlugin());
};
Configuration.prototype.useLocalStorage = function () {
};
Configuration.prototype.useDebugLogger = function () {
this.log = new ConsoleLog();
};
Configuration.prototype.onChanged = function (handler) {
!!handler && this._handlers.push(handler);
};
Configuration.prototype.changed = function () {
var handlers = this._handlers;
for (var index = 0; index < handlers.length; index++) {
try {
handlers[index](this);
}
catch (ex) {
this.log.error("Error calling onChanged handler: " + ex);
}
}
};
Object.defineProperty(Configuration, "defaults", {
get: function () {
if (Configuration._defaultSettings === null) {
Configuration._defaultSettings = {};
}
return Configuration._defaultSettings;
},
enumerable: true,
configurable: true
});
Configuration._defaultSettings = null;
return Configuration;
}());
exports.Configuration = Configuration;
var EventBuilder = (function () {
function EventBuilder(event, client, pluginContextData) {
this._validIdentifierErrorMessage = 'must contain between 8 and 100 alphanumeric or \'-\' characters.';
this.target = event;
this.client = client;
this.pluginContextData = pluginContextData || new ContextData();
}
EventBuilder.prototype.setType = function (type) {
if (!!type) {
this.target.type = type;
}
return this;
};
EventBuilder.prototype.setSource = function (source) {
if (!!source) {
this.target.source = source;
}
return this;
};
EventBuilder.prototype.setReferenceId = function (referenceId) {
if (!this.isValidIdentifier(referenceId)) {
throw new Error("ReferenceId " + this._validIdentifierErrorMessage);
}
this.target.reference_id = referenceId;
return this;
};
EventBuilder.prototype.setEventReference = function (name, id) {
if (!name) {
throw new Error('Invalid name');
}
if (!id || !this.isValidIdentifier(id)) {
throw new Error("Id " + this._validIdentifierErrorMessage);
}
this.setProperty('@ref:' + name, id);
return this;
};
EventBuilder.prototype.setMessage = function (message) {
if (!!message) {
this.target.message = message;
}
return this;
};
EventBuilder.prototype.setGeo = function (latitude, longitude) {
if (latitude < -90.0 || latitude > 90.0) {
throw new Error('Must be a valid latitude value between -90.0 and 90.0.');
}
if (longitude < -180.0 || longitude > 180.0) {
throw new Error('Must be a valid longitude value between -180.0 and 180.0.');
}
this.target.geo = latitude + "," + longitude;
return this;
};
EventBuilder.prototype.setUserIdentity = function (userInfoOrIdentity, name) {
var userInfo = typeof userInfoOrIdentity !== 'string' ? userInfoOrIdentity : { identity: userInfoOrIdentity, name: name };
if (!userInfo || (!userInfo.identity && !userInfo.name)) {
return this;
}
this.setProperty('@user', userInfo);
return this;
};
EventBuilder.prototype.setUserDescription = function (emailAddress, description) {
if (emailAddress && description) {
this.setProperty('@user_description', { email_address: emailAddress, description: description });
}
return this;
};
EventBuilder.prototype.setManualStackingInfo = function (signatureData, title) {
if (signatureData) {
var stack = {
signature_data: signatureData
};
if (title) {
stack.title = title;
}
this.setProperty('@stack', stack);
}
return this;
};
EventBuilder.prototype.setManualStackingKey = function (manualStackingKey, title) {
if (manualStackingKey) {
var data = {
'ManualStackingKey': manualStackingKey
};
this.setManualStackingInfo(data, title);
}
return this;
};
EventBuilder.prototype.setValue = function (value) {
if (!!value) {
this.target.value = value;
}
return this;
};
EventBuilder.prototype.addTags = function () {
var tags = [];
for (var _i = 0; _i < arguments.length; _i++) {
tags[_i - 0] = arguments[_i];
}
this.target.tags = Utils.addRange.apply(Utils, [this.target.tags].concat(tags));
return this;
};
EventBuilder.prototype.setProperty = function (name, value, maxDepth, excludedPropertyNames) {
if (!name || (value === undefined || value == null)) {
return this;
}
if (!this.target.data) {
this.target.data = {};
}
var result = JSON.parse(Utils.stringify(value, this.client.config.dataExclusions.concat(excludedPropertyNames || []), maxDepth));
if (!Utils.isEmpty(result)) {
this.target.data[name] = result;
}
return this;
};
EventBuilder.prototype.markAsCritical = function (critical) {
if (critical) {
this.addTags('Critical');
}
return this;
};
EventBuilder.prototype.addRequestInfo = function (request) {
if (!!request) {
this.pluginContextData['@request'] = request;
}
return this;
};
EventBuilder.prototype.submit = function (callback) {
this.client.submitEvent(this.target, this.pluginContextData, callback);
};
EventBuilder.prototype.isValidIdentifier = function (value) {
if (!value) {
return true;
}
if (value.length < 8 || value.length > 100) {
return false;
}
for (var index = 0; index < value.length; index++) {
var code = value.charCodeAt(index);
var isDigit = (code >= 48) && (code <= 57);
var isLetter = ((code >= 65) && (code <= 90)) || ((code >= 97) && (code <= 122));
var isMinus = code === 45;
if (!(isDigit || isLetter) && !isMinus) {
return false;
}
}
return true;
};
return EventBuilder;
}());
exports.EventBuilder = EventBuilder;
var ContextData = (function () {
function ContextData() {
}
ContextData.prototype.setException = function (exception) {
if (exception) {
this['@@_Exception'] = exception;
}
};
Object.defineProperty(ContextData.prototype, "hasException", {
get: function () {
return !!this['@@_Exception'];
},
enumerable: true,
configurable: true
});
ContextData.prototype.getException = function () {
return this['@@_Exception'] || null;
};
ContextData.prototype.markAsUnhandledError = function () {
this['@@_IsUnhandledError'] = true;
};
Object.defineProperty(ContextData.prototype, "isUnhandledError", {
get: function () {
return !!this['@@_IsUnhandledError'];
},
enumerable: true,
configurable: true
});
ContextData.prototype.setSubmissionMethod = function (method) {
if (method) {
this['@@_SubmissionMethod'] = method;
}
};
ContextData.prototype.getSubmissionMethod = function () {
return this['@@_SubmissionMethod'] || null;
};
return ContextData;
}());
exports.ContextData = ContextData;
var ExceptionlessClient = (function () {
function ExceptionlessClient(settingsOrApiKey, serverUrl) {
var _this = this;
if (typeof settingsOrApiKey === 'object') {
this.config = new Configuration(settingsOrApiKey);
}
else {
this.config = new Configuration({ apiKey: settingsOrApiKey, serverUrl: serverUrl });
}
this.updateSettingsTimer(5000);
this.config.onChanged(function (config) { return _this.updateSettingsTimer(_this._timeoutId > 0 ? 5000 : 0); });
this.config.queue.onEventsPosted(function (events, response) { return _this.updateSettingsTimer(); });
}
ExceptionlessClient.prototype.createException = function (exception) {
var pluginContextData = new ContextData();
pluginContextData.setException(exception);
return this.createEvent(pluginContextData).setType('error');
};
ExceptionlessClient.prototype.submitException = function (exception, callback) {
this.createException(exception).submit(callback);
};
ExceptionlessClient.prototype.createUnhandledException = function (exception, submissionMethod) {
var builder = this.createException(exception);
builder.pluginContextData.markAsUnhandledError();
builder.pluginContextData.setSubmissionMethod(submissionMethod);
return builder;
};
ExceptionlessClient.prototype.submitUnhandledException = function (exception, submissionMethod, callback) {
this.createUnhandledException(exception, submissionMethod).submit(callback);
};
ExceptionlessClient.prototype.createFeatureUsage = function (feature) {
return this.createEvent().setType('usage').setSource(feature);
};
ExceptionlessClient.prototype.submitFeatureUsage = function (feature, callback) {
this.createFeatureUsage(feature).submit(callback);
};
ExceptionlessClient.prototype.createLog = function (sourceOrMessage, message, level) {
var builder = this.createEvent().setType('log');
if (message && level) {
builder = builder.setSource(sourceOrMessage).setMessage(message).setProperty('@level', level);
}
else if (message) {
builder = builder.setSource(sourceOrMessage).setMessage(message);
}
else {
builder = builder.setMessage(sourceOrMessage);
try {
var caller = this.createLog.caller;
builder = builder.setSource(caller && caller.caller && caller.caller.name);
}
catch (e) {
this.config.log.trace('Unable to resolve log source: ' + e.message);
}
}
return builder;
};
ExceptionlessClient.prototype.submitLog = function (sourceOrMessage, message, level, callback) {
this.createLog(sourceOrMessage, message, level).submit(callback);
};
ExceptionlessClient.prototype.createNotFound = function (resource) {
return this.createEvent().setType('404').setSource(resource);
};
ExceptionlessClient.prototype.submitNotFound = function (resource, callback) {
this.createNotFound(resource).submit(callback);
};
ExceptionlessClient.prototype.createSessionStart = function () {
return this.createEvent().setType('session');
};
ExceptionlessClient.prototype.submitSessionStart = function (callback) {
this.createSessionStart().submit(callback);
};
ExceptionlessClient.prototype.submitSessionEnd = function (sessionIdOrUserId) {
if (sessionIdOrUserId) {
this.config.log.info("Submitting session end: " + sessionIdOrUserId);
this.config.submissionClient.sendHeartbeat(sessionIdOrUserId, true, this.config);
}
};
ExceptionlessClient.prototype.submitSessionHeartbeat = function (sessionIdOrUserId) {
if (sessionIdOrUserId) {
this.config.log.info("Submitting session heartbeat: " + sessionIdOrUserId);
this.config.submissionClient.sendHeartbeat(sessionIdOrUserId, false, this.config);
}
};
ExceptionlessClient.prototype.createEvent = function (pluginContextData) {
return new EventBuilder({ date: new Date() }, this, pluginContextData);
};
ExceptionlessClient.prototype.submitEvent = function (event, pluginContextData, callback) {
function cancelled(context) {
if (!!context) {
context.cancelled = true;
}
return !!callback && callback(context);
}
var context = new EventPluginContext(this, event, pluginContextData);
if (!event) {
return cancelled(context);
}
if (!this.config.enabled) {
this.config.log.info('Event submission is currently disabled.');
return cancelled(context);
}
if (!event.data) {
event.data = {};
}
if (!event.tags || !event.tags.length) {
event.tags = [];
}
EventPluginManager.run(context, function (ctx) {
var config = ctx.client.config;
var ev = ctx.event;
if (!ctx.cancelled) {
if (!ev.type || ev.type.length === 0) {
ev.type = 'log';
}
if (!ev.date) {
ev.date = new Date();
}
config.queue.enqueue(ev);
if (ev.reference_id && ev.reference_id.length > 0) {
ctx.log.info("Setting last reference id '" + ev.reference_id + "'");
config.lastReferenceIdManager.setLast(ev.reference_id);
}
}
!!callback && callback(ctx);
});
};
ExceptionlessClient.prototype.updateUserEmailAndDescription = function (referenceId, email, description, callback) {
var _this = this;
if (!referenceId || !email || !description || !this.config.enabled) {
return !!callback && callback(new SubmissionResponse(500, 'cancelled'));
}
var userDescription = { email_address: email, description: description };
this.config.submissionClient.postUserDescription(referenceId, userDescription, this.config, function (response) {
if (!response.success) {
_this.config.log.error("Failed to submit user email and description for event '" + referenceId + "': " + response.statusCode + " " + response.message);
}
!!callback && callback(response);
});
};
ExceptionlessClient.prototype.getLastReferenceId = function () {
return this.config.lastReferenceIdManager.getLast();
};
ExceptionlessClient.prototype.updateSettingsTimer = function (initialDelay) {
var _this = this;
this.config.log.info("Updating settings timer with delay: " + initialDelay);
this._timeoutId = clearTimeout(this._timeoutId);
this._timeoutId = clearInterval(this._intervalId);
var interval = this.config.updateSettingsWhenIdleInterval;
if (interval > 0) {
var updateSettings = function () { return SettingsManager.updateSettings(_this.config); };
if (initialDelay > 0) {
this._timeoutId = setTimeout(updateSettings, initialDelay);
}
this._intervalId = setInterval(updateSettings, interval);
}
};
Object.defineProperty(ExceptionlessClient, "default", {
get: function () {
if (ExceptionlessClient._instance === null) {
ExceptionlessClient._instance = new ExceptionlessClient(null);
}
return ExceptionlessClient._instance;
},
enumerable: true,
configurable: true
});
ExceptionlessClient._instance = null;
return ExceptionlessClient;
}());
exports.ExceptionlessClient = ExceptionlessClient;
var ConfigurationDefaultsPlugin = (function () {
function ConfigurationDefaultsPlugin() {
this.priority = 10;
this.name = 'ConfigurationDefaultsPlugin';
}
ConfigurationDefaultsPlugin.prototype.run = function (context, next) {
var config = context.client.config;
var defaultTags = config.defaultTags || [];
for (var index = 0; index < defaultTags.length; index++) {
var tag = defaultTags[index];
if (!!tag && context.event.tags.indexOf(tag) < 0) {
context.event.tags.push(tag);
}
}
var defaultData = config.defaultData || {};
for (var key in defaultData) {
if (!!defaultData[key]) {
var result = JSON.parse(Utils.stringify(defaultData[key], config.dataExclusions));
if (!Utils.isEmpty(result)) {
context.event.data[key] = result;
}
}
}
next && next();
};
return ConfigurationDefaultsPlugin;
}());
exports.ConfigurationDefaultsPlugin = ConfigurationDefaultsPlugin;
var ErrorPlugin = (function () {
function ErrorPlugin() {
this.priority = 30;
this.name = 'ErrorPlugin';
}
ErrorPlugin.prototype.run = function (context, next) {
var ERROR_KEY = '@error';
var ignoredProperties = [
'arguments',
'column',
'columnNumber',
'description',
'fileName',
'message',
'name',
'number',
'line',
'lineNumber',
'opera#sourceloc',
'sourceId',
'sourceURL',
'stack',
'stackArray',
'stacktrace'
];
var exception = context.contextData.getException();
if (!!exception) {
context.event.type = 'error';
if (!context.event.data[ERROR_KEY]) {
var config = context.client.config;
var parser = config.errorParser;
if (!parser) {
throw new Error('No error parser was defined.');
}
var result = parser.parse(context, exception);
if (!!result) {
var additionalData = JSON.parse(Utils.stringify(exception, config.dataExclusions.concat(ignoredProperties)));
if (!Utils.isEmpty(additionalData)) {
if (!result.data) {
result.data = {};
}
result.data['@ext'] = additionalData;
}
context.event.data[ERROR_KEY] = result;
}
}
}
next && next();
};
return ErrorPlugin;
}());
exports.ErrorPlugin = ErrorPlugin;
var ModuleInfoPlugin = (function () {
function ModuleInfoPlugin() {
this.priority = 50;
this.name = 'ModuleInfoPlugin';
}
ModuleInfoPlugin.prototype.run = function (context, next) {
var ERROR_KEY = '@error';
var collector = context.client.config.moduleCollector;
if (context.event.data[ERROR_KEY] && !context.event.data['@error'].modules && !!collector) {
var modules = collector.getModules(context);
if (modules && modules.length > 0) {
context.event.data[ERROR_KEY].modules = modules;
}
}
next && next();
};
return ModuleInfoPlugin;
}());
exports.ModuleInfoPlugin = ModuleInfoPlugin;
var RequestInfoPlugin = (function () {
function RequestInfoPlugin() {
this.priority = 70;
this.name = 'RequestInfoPlugin';
}
RequestInfoPlugin.prototype.run = function (context, next) {
var REQUEST_KEY = '@request';
var config = context.client.config;
var collector = config.requestInfoCollector;
if (!context.event.data[REQUEST_KEY] && !!collector) {
var requestInfo = collector.getRequestInfo(context);
if (!!requestInfo) {
if (Utils.isMatch(requestInfo.user_agent, config.userAgentBotPatterns)) {
context.log.info('Cancelling event as the request user agent matches a known bot pattern');
context.cancelled = true;
}
else {
context.event.data[REQUEST_KEY] = requestInfo;
}
}
}
next && next();
};
return RequestInfoPlugin;
}());
exports.RequestInfoPlugin = RequestInfoPlugin;
var EnvironmentInfoPlugin = (function () {
function EnvironmentInfoPlugin() {
this.priority = 80;
this.name = 'EnvironmentInfoPlugin';
}
EnvironmentInfoPlugin.prototype.run = function (context, next) {
var ENVIRONMENT_KEY = '@environment';
var collector = context.client.config.environmentInfoCollector;
if (!context.event.data[ENVIRONMENT_KEY] && collector) {
var environmentInfo = collector.getEnvironmentInfo(context);
if (!!environmentInfo) {
context.event.data[ENVIRONMENT_KEY] = environmentInfo;
}
}
next && next();
};
return EnvironmentInfoPlugin;
}());
exports.EnvironmentInfoPlugin = EnvironmentInfoPlugin;
var SubmissionMethodPlugin = (function () {
function SubmissionMethodPlugin() {
this.priority = 100;
this.name = 'SubmissionMethodPlugin';
}
SubmissionMethodPlugin.prototype.run = function (context, next) {
var submissionMethod = context.contextData.getSubmissionMethod();
if (!!submissionMethod) {
context.event.data['@submission_method'] = submissionMethod;
}
next && next();
};
return SubmissionMethodPlugin;
}());
exports.SubmissionMethodPlugin = SubmissionMethodPlugin;
var DuplicateCheckerPlugin = (function () {
function DuplicateCheckerPlugin(getCurrentTime, interval) {
var _this = this;
if (getCurrentTime === void 0) { getCurrentTime = function () { return Date.now(); }; }
if (interval === void 0) { interval = 30000; }
this.priority = 1010;
this.name = 'DuplicateCheckerPlugin';
this._mergedEvents = [];
this._processedHashcodes = [];
this._getCurrentTime = getCurrentTime;
this._interval = interval;
setInterval(function () {
while (_this._mergedEvents.length > 0) {
_this._mergedEvents.shift().resubmit();
}
}, interval);
}
DuplicateCheckerPlugin.prototype.run = function (context, next) {
var _this = this;
function getHashCode(error) {
var hashCode = 0;
while (error) {
if (error.message && error.message.length) {
hashCode += (hashCode * 397) ^ Utils.getHashCode(error.message);
}
if (error.stack_trace && error.stack_trace.length) {
hashCode += (hashCode * 397) ^ Utils.getHashCode(JSON.stringify(error.stack_trace));
}
error = error.inner;
}
return hashCode;
}
var error = context.event.data['@error'];
var hashCode = getHashCode(error);
if (hashCode) {
var count = context.event.count || 1;
var now_1 = this._getCurrentTime();
var merged = this._mergedEvents.filter(function (s) { return s.hashCode === hashCode; })[0];
if (merged) {
merged.incrementCount(count);
merged.updateDate(context.event.date);
context.log.info('Ignoring duplicate event with hash: ' + hashCode);
context.cancelled = true;
}
if (!context.cancelled && this._processedHashcodes.some(function (h) { return h.hash === hashCode && h.timestamp >= (now_1 - _this._interval); })) {
context.log.trace('Adding event with hash: ' + hashCode);
this._mergedEvents.push(new MergedEvent(hashCode, context, count));
context.cancelled = true;
}
if (!context.cancelled) {
context.log.trace('Enqueueing event with hash: ' + hashCode + 'to cache.');
this._processedHashcodes.push({ hash: hashCode, timestamp: now_1 });
while (this._processedHashcodes.length > 50) {
this._processedHashcodes.shift();
}
}
}
next && next();
};
return DuplicateCheckerPlugin;
}());
exports.DuplicateCheckerPlugin = DuplicateCheckerPlugin;
var MergedEvent = (function () {
function MergedEvent(hashCode, context, count) {
this.hashCode = hashCode;
this._context = context;
this._count = count;
}
MergedEvent.prototype.incrementCount = function (count) {
this._count += count;
};
MergedEvent.prototype.resubmit = function () {
this._context.event.count = this._count;
this._context.client.config.queue.enqueue(this._context.event);
};
MergedEvent.prototype.updateDate = function (date) {
if (date > this._context.event.date) {
this._context.event.date = date;
}
};
return MergedEvent;
}());
var EventExclusionPlugin = (function () {
function EventExclusionPlugin() {
this.priority = 45;
this.name = 'EventExclusionPlugin';
}
EventExclusionPlugin.prototype.run = function (context, next) {
function getLogLevel(level) {
switch ((level || '').toLowerCase().trim()) {
case 'trace':
case 'true':
case '1':
case 'yes':
return 0;
case 'debug':
return 1;
case 'info':
return 2;
case 'warn':
return 3;
case 'error':
return 4;
case 'fatal':
return 5;
case 'off':
case 'false':
case '0':
case 'no':
return 6;
default:
return -1;
}
}
function getMinLogLevel(settings, loggerName) {
if (loggerName === void 0) { loggerName = '*'; }
return getLogLevel(getTypeAndSourceSetting(settings, 'log', loggerName, 'Trace') + '');
}
function getTypeAndSourceSetting(settings, type, source, defaultValue) {
if (settings === void 0) { settings = {}; }
if (defaultValue === void 0) { defaultValue = undefined; }
if (!type) {
return defaultValue;
}
var isLog = type === 'log';
var sourcePrefix = "@@" + type + ":";
var value = settings[sourcePrefix + source];
if (value) {
return !isLog ? Utils.toBoolean(value) : value;
}
for (var key in settings) {
if (Utils.startsWith(key.toLowerCase(), sourcePrefix.toLowerCase()) && Utils.isMatch(source, [key.substring(sourcePrefix.length)])) {
return !isLog ? Utils.toBoolean(settings[key]) : settings[key];
}
}
return defaultValue;
}
var ev = context.event;
var log = context.log;
var settings = context.client.config.settings;
if (ev.type === 'log') {
var minLogLevel = getMinLogLevel(settings, ev.source);
var logLevel = getLogLevel(ev.data['@level']);
if (logLevel >= 0 && (logLevel > 5 || logLevel < minLogLevel)) {
log.info('Cancelling log event due to minimum log level.');
context.cancelled = true;
}
}
else if (ev.type === 'error') {
var error = ev.data['@error'];
while (!context.cancelled && error) {
if (getTypeAndSourceSetting(settings, ev.type, error.type, true) === false) {
log.info("Cancelling error from excluded exception type: " + error.type);
context.cancelled = true;
}
error = error.inner;
}
}
else if (getTypeAndSourceSetting(settings, ev.type, ev.source, true) === false) {
log.info("Cancelling event from excluded type: " + ev.type + " and source: " + ev.source);
context.cancelled = true;
}
next && next();
};
return EventExclusionPlugin;
}());
exports.EventExclusionPlugin = EventExclusionPlugin;
var SettingsResponse = (function () {
function SettingsResponse(success, settings, settingsVersion, exception, message) {
if (settingsVersion === void 0) { settingsVersion = -1; }
if (exception === void 0) { exception = null; }
if (message === void 0) { message = null; }
this.success = false;
this.settingsVersion = -1;
this.success = success;
this.settings = settings;
this.settingsVersion = settingsVersion;
this.exception = exception;
this.message = message;
}
return SettingsResponse;
}());
exports.SettingsResponse = SettingsResponse;
var InMemoryStorage = (function () {
function InMemoryStorage(maxItems) {
this.items = [];
this.lastTimestamp = 0;
this.maxItems = maxItems;
}
InMemoryStorage.prototype.save = function (value) {
if (!value) {
return null;
}
var items = this.items;
var timestamp = Math.max(Date.now(), this.lastTimestamp + 1);
var item = { timestamp: timestamp, value: value };
if (items.push(item) > this.maxItems) {
items.shift();
}
this.lastTimestamp = timestamp;
return item.timestamp;
};
InMemoryStorage.prototype.get = function (limit) {
return this.items.slice(0, limit);
};
InMemoryStorage.prototype.remove = function (timestamp) {
var items = this.items;
for (var i = 0; i < items.length; i++) {
if (items[i].timestamp === timestamp) {
items.splice(i, 1);
return;
}
}
};
InMemoryStorage.prototype.clear = function () {
this.items = [];
};
return InMemoryStorage;
}());
exports.InMemoryStorage = InMemoryStorage;
var KeyValueStorageBase = (function () {
function KeyValueStorageBase(maxItems) {
this.lastTimestamp = 0;
this.maxItems = maxItems;
}
KeyValueStorageBase.prototype.save = function (value, single) {
if (!value) {
return null;
}
this.ensureIndex();
var items = this.items;
var timestamp = Math.max(Date.now(), this.lastTimestamp + 1);
var key = this.getKey(timestamp);
var json = JSON.stringify(value);
try {
this.write(key, json);
this.lastTimestamp = timestamp;
if (items.push(timestamp) > this.maxItems) {
this.delete(this.getKey(items.shift()));
}
}
catch (e) {
return null;
}
return timestamp;
};
KeyValueStorageBase.prototype.get = function (limit) {
var _this = this;
this.ensureIndex();
return this.items.slice(0, limit)
.map(function (timestamp) {
var key = _this.getKey(timestamp);
try {
var json = _this.read(key);
var value = JSON.parse(json, parseDate);
return { timestamp: timestamp, value: value };
}
catch (error) {
_this.safeDelete(key);
return null;
}
})
.filter(function (item) { return item != null; });
};
KeyValueStorageBase.prototype.remove = function (timestamp) {
this.ensureIndex();
var items = this.items;
var index = items.indexOf(timestamp);
if (index >= 0) {
var key = this.getKey(timestamp);
this.safeDelete(key);
items.splice(index, 1);
}
;
};
KeyValueStorageBase.prototype.clear = function () {
var _this = this;
this.items.forEach(function (item) { return _this.safeDelete(_this.getKey(item)); });
this.items = [];
};
KeyValueStorageBase.prototype.ensureIndex = function () {
if (!this.items) {
this.items = this.createIndex();
this.lastTimestamp = Math.max.apply(Math, [0].concat(this.items)) + 1;
}
};
KeyValueStorageBase.prototype.safeDelete = function (key) {
try {
this.delete(key);
}
catch (error) {
}
};
KeyValueStorageBase.prototype.createIndex = function () {
var _this = this;
try {
var keys = this.readAllKeys();
return keys.map(function (key) {
try {
var timestamp = _this.getTimestamp(key);
if (!timestamp) {
_this.safeDelete(key);
return null;
}
return timestamp;
}
catch (error) {
_this.safeDelete(key);
return null;
}
}).filter(function (timestamp) { return timestamp != null; })
.sort(function (a, b) { return a - b; });
}
catch (error) {
return [];
}
};
return KeyValueStorageBase;
}());
exports.KeyValueStorageBase = KeyValueStorageBase;
function parseDate(key, value) {
var dateRegx = /\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)/g;
if (typeof value === 'string') {
var a = dateRegx.exec(value);
if (a) {
return new Date(value);
}
}
return value;
}
;
var BrowserStorage = (function (_super) {
__extends(BrowserStorage, _super);
function BrowserStorage(namespace, prefix, maxItems) {
if (prefix === void 0) { prefix = 'com.exceptionless.'; }
if (maxItems === void 0) { maxItems = 20; }
_super.call(this, maxItems);
this.prefix = prefix + namespace + '-';
}
BrowserStorage.isAvailable = function () {
try {
var storage = window.localStorage, x = '__storage_test__';
storage.setItem(x, x);
storage.removeItem(x);
return true;
}
catch (e) {
return false;
}
};
BrowserStorage.prototype.write = function (key, value) {
window.localStorage.setItem(key, value);
};
BrowserStorage.prototype.read = function (key) {
return window.localStorage.getItem(key);
};
BrowserStorage.prototype.readAllKeys = function () {
var _this = this;
return Object.keys(window.localStorage)
.filter(function (key) { return key.indexOf(_this.prefix) === 0; });
};
BrowserStorage.prototype.delete = function (key) {
window.localStorage.removeItem(key);
};
BrowserStorage.prototype.getKey = function (timestamp) {
return this.prefix + timestamp;
};
BrowserStorage.prototype.getTimestamp = function (key) {
return parseInt(key.substr(this.prefix.length), 10);
};
return BrowserStorage;
}(KeyValueStorageBase));
exports.BrowserStorage = BrowserStorage;
var DefaultErrorParser = (function () {
function DefaultErrorParser() {
}
DefaultErrorParser.prototype.parse = function (context, exception) {
function getParameters(parameters) {
var params = (typeof parameters === 'string' ? [parameters] : parameters) || [];
var result = [];
for (var index = 0; index < params.length; index++) {
result.push({ name: params[index] });
}
return result;
}
function getStackFrames(stackFrames) {
var ANONYMOUS = '<anonymous>';
var frames = [];
for (var index = 0; index < stackFrames.length; index++) {
var frame = stackFrames[index];
frames.push({
name: (frame.func || ANONYMOUS).replace('?', ANONYMOUS),
parameters: getParameters(frame.args),
file_name: frame.url,
line_number: frame.line || 0,
column: frame.column || 0
});
}
return frames;
}
var TRACEKIT_STACK_TRACE_KEY = '@@_TraceKit.StackTrace';
var stackTrace = !!context.contextData[TRACEKIT_STACK_TRACE_KEY]
? context.contextData[TRACEKIT_STACK_TRACE_KEY]
: TraceKit.computeStackTrace(exception, 25);
if (!stackTrace) {
throw new Error('Unable to parse the exceptions stack trace.');
}
var message = typeof (exception) === 'string' ? exception : undefined;
return {
type: stackTrace.name,
message: stackTrace.message || exception.message || message,
stack_trace: getStackFrames(stackTrace.stack || [])
};
};
return DefaultErrorParser;
}());
exports.DefaultErrorParser = DefaultErrorParser;
var DefaultModuleCollector = (function () {
function DefaultModuleCollector() {
}
DefaultModuleCollector.prototype.getModules = function (context) {
if (document && document.getElementsByTagName) {
return null;
}
var modules = [];
var scripts = document.getElementsByTagName('script');
if (scripts && scripts.length > 0) {
for (var index = 0; index < scripts.length; index++) {
if (scripts[index].src) {
modules.push({
module_id: index,
name: scripts[index].src,
version: Utils.parseVersion(scripts[index].src)
});
}
else if (!!scripts[index].innerHTML) {
modules.push({
module_id: index,
name: 'Script Tag',
version: Utils.getHashCode(scripts[index].innerHTML).toString()
});
}
}
}
return modules;
};
return DefaultModuleCollector;
}());
exports.DefaultModuleCollector = DefaultModuleCollector;
var DefaultRequestInfoCollector = (function () {
function DefaultRequestInfoCollector() {
}
DefaultRequestInfoCollector.prototype.getRequestInfo = function (context) {
if (!document || !navigator || !location) {
return null;
}
var exclusions = context.client.config.dataExclusions;
var requestInfo = {
user_agent: navigator.userAgent,
is_secure: location.protocol === 'https:',
host: location.hostname,
port: location.port && location.port !== '' ? parseInt(location.port, 10) : 80,
path: location.pathname,
cookies: Utils.getCookies(document.cookie, exclusions),
query_string: Utils.parseQueryString(location.search.substring(1), exclusions)
};
if (document.referrer && document.referrer !== '') {
requestInfo.referrer = document.referrer;
}
return requestInfo;
};
return DefaultRequestInfoCollector;
}());
exports.DefaultRequestInfoCollector = DefaultRequestInfoCollector;
var DefaultSubmissionAdapter = (function () {
function DefaultSubmissionAdapter() {
}
DefaultSubmissionAdapter.prototype.sendRequest = function (request, callback, isAppExiting) {
var TIMEOUT = 'timeout';
var LOADED = 'loaded';
var WITH_CREDENTIALS = 'withCredentials';
var isCompleted = false;
var useSetTimeout = false;
function complete(mode, xhr) {
function parseResponseHeaders(headerStr) {
function trim(value) {
return value.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
}
var headers = {};
var headerPairs = (headerStr || '').split('\u000d\u000a');
for (var index = 0; index < headerPairs.length; index++) {
var headerPair = headerPairs[index];
var separator = headerPair.indexOf('\u003a\u0020');
if (separator > 0) {
headers[trim(headerPair.substring(0, separator).toLowerCase())] = headerPair.substring(separator + 2);
}
}
return headers;
}
if (isCompleted) {
return;
}
isCompleted = true;
var message = xhr.statusText;
var responseText = xhr.responseText;
var status = xhr.status;
if (mode === TIMEOUT || status === 0) {
message = 'Unable to connect to server.';
status = 0;
}
else if (mode === LOADED && !status) {
status = request.method === 'POST' ? 202 : 200;
}
else if (status < 200 || status > 299) {
var responseBody = xhr.responseBody;
if (!!responseBody && !!responseBody.message) {
message = responseBody.message;
}
else if (!!responseText && responseText.indexOf('message') !== -1) {
try {
message = JSON.parse(responseText).message;
}
catch (e) {
message = responseText;
}
}
}
callback && callback(status || 500, message || '', responseText, parseResponseHeaders(xhr.getAllResponseHeaders && xhr.getAllResponseHeaders()));
}
function createRequest(userAgent, method, url) {
var xhr = new XMLHttpRequest();
if (WITH_CREDENTIALS in xhr) {
xhr.open(method, url, true);
xhr.setRequestHeader('X-Exceptionless-Client', userAgent);
if (method === 'POST') {
xhr.setRequestHeader('Content-Type', 'application/json');
}
}
else if (typeof XDomainRequest !== 'undefined') {
useSetTimeout = true;
xhr = new XDomainRequest();
xhr.open(method, location.protocol === 'http:' ? url.replace('https:', 'http:') : url);
}
else {
xhr = null;
}
if (xhr) {
xhr.timeout = 10000;
}
return xhr;
}
var url = "" + request.url + (request.url.indexOf('?') === -1 ? '?' : '&') + "access_token=" + encodeURIComponent(request.apiKey);
var xhr = createRequest(request.userAgent, request.method || 'POST', url);
if (!xhr) {
return (callback && callback(503, 'CORS not supported.'));
}
if (WITH_CREDENTIALS in xhr) {
xhr.onreadystatechange = function () {
if (xhr.readyState !== 4) {
return;
}
complete(LOADED, xhr);
};
}
xhr.onprogress = function () { };
xhr.ontimeout = function () { return complete(TIMEOUT, xhr); };
xhr.onerror = function () { return complete('error', xhr); };
xhr.onload = function () { return complete(LOADED, xhr); };
if (useSetTimeout) {
setTimeout(function () { return xhr.send(request.data); }, 500);
}
else {
xhr.send(request.data);
}
};
return DefaultSubmissionAdapter;
}());
exports.DefaultSubmissionAdapter = DefaultSubmissionAdapter;
var BrowserStorageProvider = (function () {
function BrowserStorageProvider(prefix, maxQueueItems) {
if (maxQueueItems === void 0) { maxQueueItems = 250; }
this.queue = new BrowserStorage('q', prefix, maxQueueItems);
this.settings = new BrowserStorage('settings', prefix, 1);
}
return BrowserStorageProvider;
}());
exports.BrowserStorageProvider = BrowserStorageProvider;
function getDefaultsSettingsFromScriptTag() {
if (!document || !document.getElementsByTagName) {
return null;
}
var scripts = document.getElementsByTagName('script');
for (var index = 0; index < scripts.length; index++) {
if (scripts[index].src && scripts[index].src.indexOf('/exceptionless') > -1) {
return Utils.parseQueryString(scripts[index].src.split('?').pop());
}
}
return null;
}
function processUnhandledException(stackTrace, options) {
var builder = ExceptionlessClient.default.createUnhandledException(new Error(stackTrace.message || (options || {}).status || 'Script error'), 'onerror');
builder.pluginContextData['@@_TraceKit.StackTrace'] = stackTrace;
builder.submit();
}
Configuration.prototype.useLocalStorage = function () {
if (BrowserStorage.isAvailable()) {
this.storage = new BrowserStorageProvider();
SettingsManager.applySavedServerSettings(this);
this.changed();
}
};
var defaults = Configuration.defaults;
var settings = getDefaultsSettingsFromScriptTag();
if (settings && (settings.apiKey || settings.serverUrl)) {
defaults.apiKey = settings.apiKey;
defaults.serverUrl = settings.serverUrl;
}
defaults.errorParser = new DefaultErrorParser();
defaults.moduleCollector = new DefaultModuleCollector();
defaults.requestInfoCollector = new DefaultRequestInfoCollector();
defaults.submissionAdapter = new DefaultSubmissionAdapter();
TraceKit.report.subscribe(processUnhandledException);
TraceKit.extendToAsynchronousCallbacks();
Error.stackTraceLimit = Infinity;
return exports;
}));
//# sourceMappingURL=exceptionless.js.map