@@ -129,30 +129,27 @@ export class CDPSession {
129
129
} else {
130
130
responder . resolve ( msg . result ) ;
131
131
}
132
- } else {
133
- if ( msg . method === "Console.messageAdded" ) {
132
+
133
+ return ;
134
+ }
135
+
136
+ switch ( msg . method ) {
137
+ case "Console.messageAdded" : {
134
138
const text = msg . params . message . text ;
135
139
if ( text . startsWith ( "#status" ) ) {
136
140
this . #exit( parseInt ( text . split ( "=" ) . pop ( ) ) ) ;
137
141
}
138
142
console . log ( text ) ;
139
143
//console.log(msg.params.message.text, `${ msg.params.message.url }:${ msg.params.message.line }`);
144
+ break ;
145
+ }
140
146
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 ;
152
150
153
- } else if ( msg . method === "Runtime.exceptionThrown" ) {
151
+ case "Runtime.exceptionThrown" : {
154
152
console . log ( "Runtime Exception" ) ;
155
- console . log ( "PARAMS:" , msg . params ) ;
156
153
157
154
let url = "" ;
158
155
try {
@@ -167,12 +164,37 @@ export class CDPSession {
167
164
}
168
165
console . log ( ` - ${ frame . functionName } (${ loc } )` ) ;
169
166
}
167
+
170
168
} catch ( error ) {
171
- console . log ( "ERROR" , msg , error ) ;
169
+ console . log ( "ERROR:" , error ) ;
170
+ console . log ( "MESSAGE:" , msg ) ;
171
+ console . log ( "PARAMS:" , msg . params ) ;
172
172
}
173
- } else {
174
- console . log ( `WARN: Unhandled event - ${ JSON . stringify ( msg ) } ` ) ;
173
+ break ;
175
174
}
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 ) } ` ) ;
176
198
}
177
199
} ;
178
200
@@ -267,7 +289,6 @@ export function start(_root: string, options: Options): Promise<Server> {
267
289
268
290
const server = createServer ( ( req , resp ) => {
269
291
const url = ( req . url || "" ) . split ( "?" ) [ 0 ] ;
270
- console . log ( `Request: ${ url } ` ) ;
271
292
272
293
let transform = false ;
273
294
@@ -409,7 +430,6 @@ export function start(_root: string, options: Options): Promise<Server> {
409
430
await session . send ( "Debugger.enable" , { } ) ;
410
431
await session . send ( "Page.enable" , { } ) ;
411
432
await session . send ( "Runtime.enable" , { } ) ;
412
- await session . send ( "Security.enable" , { } ) ;
413
433
await session . navigate ( "http:/\/localhost:8000" ) ;
414
434
415
435
const status = await session . done ;
0 commit comments