@@ -12,11 +12,6 @@ import { breadcrumbEventHandler, keypressEventHandler, wrap } from './helpers';
1212const global = getGlobalObject ( ) as Window ;
1313let lastHref : string | undefined ;
1414
15- /** JSDoc */
16- interface ExtensibleConsole extends Console {
17- [ key : string ] : any ;
18- }
19-
2015/** JSDoc */
2116export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
2217 [ key : string ] : any ;
@@ -27,50 +22,6 @@ export interface SentryWrappedXMLHttpRequest extends XMLHttpRequest {
2722 } ;
2823}
2924
30- /**
31- * Wrapper function that'll be used for every console level
32- */
33- function consoleWrapper ( originalConsole : ExtensibleConsole ) : any {
34- return function ( level : string ) : any {
35- if ( ! ( level in global . console ) ) {
36- return ;
37- }
38-
39- fill ( originalConsole , level , function ( originalConsoleLevel : ( ) => any ) : any {
40- return function ( ...args : any [ ] ) : any {
41- const breadcrumbData = {
42- category : 'console' ,
43- data : {
44- extra : {
45- arguments : args . slice ( 1 ) ,
46- } ,
47- logger : 'console' ,
48- } ,
49- level : Severity . fromString ( level ) ,
50- message : safeJoin ( args , ' ' ) ,
51- } ;
52-
53- if ( level === 'assert' ) {
54- if ( args [ 0 ] === false ) {
55- breadcrumbData . message = `Assertion failed: ${ safeJoin ( args . slice ( 1 ) , ' ' ) || 'console.assert' } ` ;
56- breadcrumbData . data . extra . arguments = args . slice ( 1 ) ;
57- }
58- }
59-
60- getCurrentHub ( ) . addBreadcrumb ( breadcrumbData , {
61- input : args ,
62- level,
63- } ) ;
64-
65- // this fails for some browsers. :(
66- if ( originalConsoleLevel ) {
67- originalConsoleLevel . apply ( originalConsole , args ) ;
68- }
69- } ;
70- } ) ;
71- } ;
72- }
73-
7425/** JSDoc */
7526function addSentryBreadcrumb ( serializedData : string ) : void {
7627 // There's always something that can go wrong with deserialization...
@@ -174,8 +125,44 @@ export class Breadcrumbs implements Integration {
174125 if ( ! ( 'console' in global ) ) {
175126 return ;
176127 }
177- const originalConsole = global . console as ExtensibleConsole ;
178- [ 'debug' , 'info' , 'warn' , 'error' , 'log' ] . forEach ( consoleWrapper ( originalConsole ) ) ;
128+ [ 'debug' , 'info' , 'warn' , 'error' , 'log' ] . forEach ( function ( level : string ) : void {
129+ if ( ! ( level in global . console ) ) {
130+ return ;
131+ }
132+
133+ fill ( global . console , level , function ( originalConsoleLevel : ( ) => any ) : any {
134+ return function ( ...args : any [ ] ) : any {
135+ const breadcrumbData = {
136+ category : 'console' ,
137+ data : {
138+ extra : {
139+ arguments : args . slice ( 1 ) ,
140+ } ,
141+ logger : 'console' ,
142+ } ,
143+ level : Severity . fromString ( level ) ,
144+ message : safeJoin ( args , ' ' ) ,
145+ } ;
146+
147+ if ( level === 'assert' ) {
148+ if ( args [ 0 ] === false ) {
149+ breadcrumbData . message = `Assertion failed: ${ safeJoin ( args . slice ( 1 ) , ' ' ) || 'console.assert' } ` ;
150+ breadcrumbData . data . extra . arguments = args . slice ( 1 ) ;
151+ }
152+ }
153+
154+ getCurrentHub ( ) . addBreadcrumb ( breadcrumbData , {
155+ input : args ,
156+ level,
157+ } ) ;
158+
159+ // this fails for some browsers. :(
160+ if ( originalConsoleLevel ) {
161+ originalConsoleLevel . apply ( global . console , args ) ;
162+ }
163+ } ;
164+ } ) ;
165+ } ) ;
179166 }
180167
181168 /** JSDoc */
0 commit comments