@@ -19,9 +19,11 @@ const createConsoleCatcher = (): {
1919 const formatConsoleArgs = (
2020 args : unknown [ ]
2121 ) : { message : string ; styles : string [ ] } => {
22+
2223 if ( args . length === 0 ) return { message : '' , styles : [ ] } ;
2324
2425 const firstArg = args [ 0 ] ;
26+
2527 if ( typeof firstArg !== 'string' || ! firstArg . includes ( '%c' ) ) {
2628 return {
2729 message : args
@@ -60,6 +62,7 @@ const createConsoleCatcher = (): {
6062 } ;
6163
6264 const addToConsoleOutput = ( logEvent : ConsoleLogEvent ) : void => {
65+
6366 if ( consoleOutput . length >= MAX_LOGS ) {
6467 consoleOutput . shift ( ) ;
6568 }
@@ -69,6 +72,7 @@ const createConsoleCatcher = (): {
6972 const createConsoleEventFromError = (
7073 event : ErrorEvent | PromiseRejectionEvent
7174 ) : ConsoleLogEvent => {
75+
7276 if ( event instanceof ErrorEvent ) {
7377 return {
7478 method : 'error' ,
@@ -94,6 +98,7 @@ const createConsoleCatcher = (): {
9498
9599 return {
96100 initConsoleCatcher ( ) : void {
101+
97102 if ( isInitialized ) {
98103 return ;
99104 }
@@ -108,6 +113,7 @@ const createConsoleCatcher = (): {
108113 ] ;
109114
110115 consoleMethods . forEach ( ( method ) => {
116+
111117 if ( typeof window . console [ method ] !== 'function' ) {
112118 return ;
113119 }
@@ -116,7 +122,8 @@ const createConsoleCatcher = (): {
116122
117123 window . console [ method ] = function ( ...args : unknown [ ] ) : void {
118124 const stack =
119- new Error ( ) . stack ?. split ( '\n' ) . slice ( 2 ) . join ( '\n' ) || '' ;
125+ new Error ( ) . stack ?. split ( '\n' ) . slice ( 2 )
126+ . join ( '\n' ) || '' ;
120127 const { message, styles } = formatConsoleArgs ( args ) ;
121128
122129 const logEvent : ConsoleLogEvent = {
@@ -142,7 +149,7 @@ const createConsoleCatcher = (): {
142149 } ,
143150
144151 getConsoleLogStack ( ) : ConsoleLogEvent [ ] {
145- return [ ...consoleOutput ] ;
152+ return [ ...consoleOutput ] ;
146153 } ,
147154 } ;
148155} ;
0 commit comments