File size: 1,374 Bytes
5115c57
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* _settle_worker.js -- the network keep-alive half of _chart_settle.js (see that file).
 *
 * Fetches a 1-byte file every 200ms so the page never goes network-idle while its flagship
 * chart is still mounting/animating. Runs on a Worker thread so it keeps ticking while the
 * main thread is blocked parsing the 10MB app bundle. Stops on the parent's "stop" message,
 * or after its own hard cap, whichever comes first -- so it can never wedge a capture.
 */
var PING_MS = 200;
var MAX_PINGS = 90;          // 18s ceiling; goto(networkidle) itself gives up at 30s
var n = 0;

function shutdown() {
  // Always let any in-flight ping settle before closing (see onmessage below).
  clearInterval(id);
  setTimeout(function () { self.close(); }, 1000);
}

var id = setInterval(function () {
  if (n >= MAX_PINGS) { shutdown(); return; }
  try {
    fetch('/_settle.txt?s=' + (n++), { cache: 'no-store' }).catch(function () {});
  } catch (e) {
    shutdown();
  }
}, PING_MS);

// Stop pinging, but do NOT close immediately: killing the worker while a ping is still in
// flight leaves that request without a finished/failed event, and Playwright's networkidle
// counter then never returns to zero -- the navigation hangs until goto()'s 30s timeout and
// falls back to `domcontentloaded`, which is the very failure mode this shim exists to stop.
self.onmessage = shutdown;