@@ -81,9 +81,55 @@ async function attachToTarget(Target, targetId, targetType) {
8181
8282 try {
8383 await Network . enable ( ) ;
84- Network . responseReceived && Network . responseReceived ( ( { response} ) => {
85- if ( response . status >= 400 && ! response . url . includes ( 'favicon' ) ) {
86- outputLog ( 'NET' , String ( response . status ) , response . url ) ;
84+
85+ const pendingRequests = new Map ( ) ;
86+
87+ // Track requests
88+ Network . requestWillBeSent && Network . requestWillBeSent ( ( { requestId, request, type} ) => {
89+ const { url} = request ;
90+ if ( url . includes ( 'favicon' ) || url . startsWith ( 'data:' ) ) return ;
91+ if ( url . endsWith ( '.js' ) || url . endsWith ( '.wasm' ) || type === 'Script' ) {
92+ pendingRequests . set ( requestId , { url, type} ) ;
93+ }
94+ } ) ;
95+
96+ // When response received, note the mime type
97+ Network . responseReceived && Network . responseReceived ( ( { requestId, response} ) => {
98+ const pending = pendingRequests . get ( requestId ) ;
99+ if ( pending ) {
100+ pending . mimeType = response . mimeType ;
101+ pending . status = response . status ;
102+ }
103+ } ) ;
104+
105+ // When loading finishes, fetch and log the body
106+ Network . loadingFinished && Network . loadingFinished ( async ( { requestId} ) => {
107+ const pending = pendingRequests . get ( requestId ) ;
108+ if ( ! pending ) return ;
109+ pendingRequests . delete ( requestId ) ;
110+
111+ // Skip binary WASM files - just note they were loaded
112+ if ( pending . url . endsWith ( '.wasm' ) || pending . mimeType === 'application/wasm' ) {
113+ outputLog ( 'RESOURCE' , 'LOADED' , `${ pending . url } (binary wasm, not dumped)` ) ;
114+ return ;
115+ }
116+
117+ try {
118+ const { body, base64Encoded} = await Network . getResponseBody ( { requestId} ) ;
119+ const content = base64Encoded ? Buffer . from ( body , 'base64' ) . toString ( 'utf8' ) : body ;
120+
121+ outputLog ( 'RESOURCE' , 'START' , `=== ${ pending . url } (${ pending . mimeType } ) ===` ) ;
122+ // Print content, limit to 100000 chars for JS files
123+ const lines = content . substring ( 0 , 100000 ) . split ( '\n' ) ;
124+ for ( const line of lines ) {
125+ console . log ( `WASM:RESOURCE:CONTENT: ${ line } ` ) ;
126+ }
127+ if ( content . length > 100000 ) {
128+ console . log ( `WASM:RESOURCE:CONTENT: ... truncated (${ content . length } total chars)` ) ;
129+ }
130+ outputLog ( 'RESOURCE' , 'END' , `=== ${ pending . url } ===` ) ;
131+ } catch ( e ) {
132+ logVerbose ( `Could not get body for ${ pending . url } : ${ e . message } ` ) ;
87133 }
88134 } ) ;
89135 } catch ( e ) { }
0 commit comments