@@ -11,11 +11,21 @@ const server = prerender({
1111 '--hide-scrollbars' ,
1212 '--disable-dev-shm-usage' ,
1313 '--ignore-certificate-errors' ,
14- '--allow-insecure-localhost'
14+ '--allow-insecure-localhost' ,
15+ '--disable-background-networking' ,
16+ '--disable-default-apps' ,
17+ '--disable-extensions' ,
18+ '--disable-sync' ,
19+ '--disable-translate' ,
20+ '--disable-software-rasterizer' ,
21+ '--metrics-recording-only' ,
22+ '--no-first-run' ,
23+ '--safebrowsing-disable-auto-update'
1524 ] ,
1625 pageLoadTimeout : 20000 ,
17- waitAfterLastRequest : 500 ,
18- pageDoneCheckInterval : 300
26+ waitAfterLastRequest : 1500 ,
27+ pageDoneCheckInterval : 300 ,
28+ chromeRefreshRate : 100
1929} ) ;
2030
2131process . env . CACHE_MAXSIZE = process . env . CACHE_MAXSIZE || 1000 ;
@@ -118,16 +128,18 @@ server.use({
118128 console . log ( '💥 JS Exception:' , exception . exceptionDetails . text ) ;
119129 } ) ;
120130
131+ const intervalStart = Date . now ( ) ;
121132 const interval = setInterval ( ( ) => {
122- if ( pendingRequests . size > 0 ) {
123- const now = Date . now ( ) ;
124- console . log ( `⏳ Pending requests (${ pendingRequests . size } ), inflight=${ tab . prerender . numRequestsInFlight } :` ) ;
125- pendingRequests . forEach ( ( { url, time } ) => {
126- console . log ( ` - ${ ( ( now - time ) / 1000 ) . toFixed ( 1 ) } s ${ url } ` ) ;
127- } ) ;
128- } else {
133+ // Safety: kill interval after 30s max to prevent leaks
134+ if ( Date . now ( ) - intervalStart > 20000 || pendingRequests . size === 0 ) {
129135 clearInterval ( interval ) ;
136+ return ;
130137 }
138+ const now = Date . now ( ) ;
139+ console . log ( `⏳ Pending requests (${ pendingRequests . size } ), inflight=${ tab . prerender . numRequestsInFlight } :` ) ;
140+ pendingRequests . forEach ( ( { url, time } ) => {
141+ console . log ( ` - ${ ( ( now - time ) / 1000 ) . toFixed ( 1 ) } s ${ url } ` ) ;
142+ } ) ;
131143 } , 3000 ) ;
132144 }
133145
@@ -151,5 +163,20 @@ server.use({
151163server . use ( prerender . removeScriptTags ( ) ) ;
152164server . use ( memoryCache ) ;
153165
166+ const RESTART_INTERVAL = 24 * 60 * 60 * 1000 ;
167+ const startedAt = Date . now ( ) ;
168+
169+ setTimeout ( ( ) => {
170+ console . log ( '♻️ Scheduled restart after 24 hours' ) ;
171+ process . exit ( 0 ) ;
172+ } , RESTART_INTERVAL ) ;
173+
174+ setInterval ( ( ) => {
175+ const remaining = RESTART_INTERVAL - ( Date . now ( ) - startedAt ) ;
176+ const hours = Math . floor ( remaining / 3600000 ) ;
177+ const minutes = Math . floor ( ( remaining % 3600000 ) / 60000 ) ;
178+ console . log ( `🕐 Restart in ${ hours } h ${ minutes } m` ) ;
179+ } , 60 * 60 * 1000 ) ;
180+
154181console . log ( 'Prerender on Node 24 is starting...' ) ;
155182server . start ( ) ;
0 commit comments