@@ -42,11 +42,18 @@ const BLOCKED_PATTERNS = [
4242 / w s s : \/ \/ / ,
4343 / \/ s o c k e t \. i o \/ / ,
4444 / \/ s o c k j s - n o d e \/ / ,
45- / \/ h u b \? / , // SignalR
45+ / \/ h u b \? / ,
4646 / e v e n t s o u r c e / i,
4747 / l i v e r e l o a d / ,
4848] ;
4949
50+ // Patterns for requests that should be ignored in requestsInFlight count
51+ // (they bypass Fetch interception and hang forever)
52+ const IGNORE_INFLIGHT_PATTERNS = [
53+ / ^ b l o b : / ,
54+ / ^ d a t a : / ,
55+ ] ;
56+
5057server . use ( {
5158 tabCreated : ( req , res , next ) => {
5259 const tab = req . prerender . tab ;
@@ -57,7 +64,7 @@ server.use({
5764
5865 const pendingRequests = new Map ( ) ;
5966
60- // Use Fetch domain for request interception (replaces deprecated Network.setRequestInterception)
67+ // Use Fetch domain to block unwanted network requests
6168 tab . Fetch . enable ( { patterns : [ { requestStage : 'Request' } ] } ) ;
6269 tab . Fetch . requestPaused ( ( params ) => {
6370 const url = params . request . url ;
@@ -74,10 +81,18 @@ server.use({
7481 } ) ;
7582
7683 tab . Network . requestWillBeSent ( ( params ) => {
77- pendingRequests . set ( params . requestId , {
78- url : params . request . url ,
79- time : Date . now ( )
80- } ) ;
84+ const url = params . request . url ;
85+
86+ // blob: URLs bypass Fetch interception and hang forever.
87+ // Prerender already incremented numRequestsInFlight before our handler,
88+ // so we decrement it back and skip tracking.
89+ if ( IGNORE_INFLIGHT_PATTERNS . some ( p => p . test ( url ) ) ) {
90+ tab . prerender . numRequestsInFlight -- ;
91+ console . log ( '⏭️ Ignored from inflight:' , url ) ;
92+ return ;
93+ }
94+
95+ pendingRequests . set ( params . requestId , { url, time : Date . now ( ) } ) ;
8196 } ) ;
8297
8398 tab . Network . loadingFinished ( ( params ) => {
@@ -101,18 +116,19 @@ server.use({
101116 console . log ( '💥 JS Exception:' , exception . exceptionDetails . text ) ;
102117 } ) ;
103118
104- // Log pending requests every 3s to identify what's hanging
105119 const interval = setInterval ( ( ) => {
106120 if ( pendingRequests . size > 0 ) {
107121 const now = Date . now ( ) ;
108- console . log ( `⏳ Pending requests (${ pendingRequests . size } ):` ) ;
122+ console . log ( `⏳ Pending requests (${ pendingRequests . size } ), inflight= ${ tab . prerender . numRequestsInFlight } :` ) ;
109123 pendingRequests . forEach ( ( { url, time } ) => {
110124 console . log ( ` - ${ ( ( now - time ) / 1000 ) . toFixed ( 1 ) } s ${ url } ` ) ;
111125 } ) ;
112126 }
113127 } , 3000 ) ;
114128
115- req . prerender . on ( 'tabNavigated' , ( ) => clearInterval ( interval ) ) ;
129+ const cleanup = ( ) => clearInterval ( interval ) ;
130+ req . prerender . on ( 'tabNavigated' , cleanup ) ;
131+ req . prerender . on ( 'beforeSend' , cleanup ) ;
116132 }
117133
118134 next ( ) ;
0 commit comments