@@ -129,30 +129,27 @@ export class CDPSession {
129129 } else {
130130 responder . resolve ( msg . result ) ;
131131 }
132- } else {
133- if ( msg . method === "Console.messageAdded" ) {
132+
133+ return ;
134+ }
135+
136+ switch ( msg . method ) {
137+ case "Console.messageAdded" : {
134138 const text = msg . params . message . text ;
135139 if ( text . startsWith ( "#status" ) ) {
136140 this . #exit( parseInt ( text . split ( "=" ) . pop ( ) ) ) ;
137141 }
138142 console . log ( text ) ;
139143 //console.log(msg.params.message.text, `${ msg.params.message.url }:${ msg.params.message.line }`);
144+ break ;
145+ }
140146
141- } else if ( msg . method === "Target.attachedToTarget" ) {
142- // Ignore
143-
144- } else if ( msg . method === "Debugger.scriptParsed" ) {
145- // Ignore
146-
147- } else if ( msg . method === "Runtime.consoleAPICalled" ) {
148- // Ignore; handled by Console.messageAdded above
149-
150- } else if ( msg . method === "Debugger.scriptFailedToParse" ) {
151- // @TODO : Is this important? It happens a LOT.
147+ case "Page.frameNavigated" :
148+ console . log ( "Visit:" , msg . params . frame . url ) ;
149+ break ;
152150
153- } else if ( msg . method === "Runtime.exceptionThrown" ) {
151+ case "Runtime.exceptionThrown" : {
154152 console . log ( "Runtime Exception" ) ;
155- console . log ( "PARAMS:" , msg . params ) ;
156153
157154 let url = "" ;
158155 try {
@@ -167,12 +164,37 @@ export class CDPSession {
167164 }
168165 console . log ( ` - ${ frame . functionName } (${ loc } )` ) ;
169166 }
167+
170168 } catch ( error ) {
171- console . log ( "ERROR" , msg , error ) ;
169+ console . log ( "ERROR:" , error ) ;
170+ console . log ( "MESSAGE:" , msg ) ;
171+ console . log ( "PARAMS:" , msg . params ) ;
172172 }
173- } else {
174- console . log ( `WARN: Unhandled event - ${ JSON . stringify ( msg ) } ` ) ;
173+ break ;
175174 }
175+
176+ case "Debugger.scriptFailedToParse" :
177+ // @TODO : Is this important? It can happens a LOT
178+ // when there is a runtime error complaining
179+ // "from" is a bad function; maybe when trying
180+ // to interpret ESM as legacy JavaScript?
181+ break ;
182+
183+ case "Debugger.scriptParsed" :
184+ case "Page.frameResized" :
185+ case "Page.frameStoppedLoading" :
186+ case "Page.loadEventFired" :
187+ case "Page.domContentEventFired" :
188+ case "Page.frameStartedLoading" :
189+ case "Target.attachedToTarget" :
190+ case "Runtime.consoleAPICalled" : // Handled above
191+ case "Runtime.executionContextsCleared" :
192+ case "Runtime.executionContextCreated" :
193+ // Ignore
194+ break ;
195+
196+ default :
197+ console . log ( `WARN: Unhandled event - ${ JSON . stringify ( msg ) } ` ) ;
176198 }
177199 } ;
178200
@@ -267,7 +289,6 @@ export function start(_root: string, options: Options): Promise<Server> {
267289
268290 const server = createServer ( ( req , resp ) => {
269291 const url = ( req . url || "" ) . split ( "?" ) [ 0 ] ;
270- console . log ( `Request: ${ url } ` ) ;
271292
272293 let transform = false ;
273294
@@ -409,7 +430,6 @@ export function start(_root: string, options: Options): Promise<Server> {
409430 await session . send ( "Debugger.enable" , { } ) ;
410431 await session . send ( "Page.enable" , { } ) ;
411432 await session . send ( "Runtime.enable" , { } ) ;
412- await session . send ( "Security.enable" , { } ) ;
413433 await session . navigate ( "http:/\/localhost:8000" ) ;
414434
415435 const status = await session . done ;
0 commit comments