From 1571fa8de946ba2fa27febd522a9da66eca73f09 Mon Sep 17 00:00:00 2001 From: Lyon <88232613+pikasTech@users.noreply.github.com> Date: Mon, 22 Jun 2026 14:35:58 +0800 Subject: [PATCH] fix: capture resource timing phases in web probe (#658) Co-authored-by: Codex --- .../hwlab-node-web-observe-runner-source.ts | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/scripts/src/hwlab-node-web-observe-runner-source.ts b/scripts/src/hwlab-node-web-observe-runner-source.ts index 761eb652..9f6f9b88 100644 --- a/scripts/src/hwlab-node-web-observe-runner-source.ts +++ b/scripts/src/hwlab-node-web-observe-runner-source.ts @@ -1026,6 +1026,29 @@ async function samplePage(reason) { rect: { x: Math.round(rect.x), y: Math.round(rect.y), width: Math.round(rect.width), height: Math.round(rect.height) }, }; }); + const resourceTimingSample = (entry) => ({ + name: entry.name.split(/[?#]/u)[0].slice(0, 240), + initiatorType: entry.initiatorType, + startTime: Math.round(entry.startTime), + duration: Math.round(entry.duration), + workerStart: Math.round(entry.workerStart || 0), + redirectStart: Math.round(entry.redirectStart || 0), + redirectEnd: Math.round(entry.redirectEnd || 0), + fetchStart: Math.round(entry.fetchStart || 0), + domainLookupStart: Math.round(entry.domainLookupStart || 0), + domainLookupEnd: Math.round(entry.domainLookupEnd || 0), + connectStart: Math.round(entry.connectStart || 0), + connectEnd: Math.round(entry.connectEnd || 0), + secureConnectionStart: Math.round(entry.secureConnectionStart || 0), + requestStart: Math.round(entry.requestStart || 0), + responseStart: Math.round(entry.responseStart || 0), + responseEnd: Math.round(entry.responseEnd || 0), + transferSize: Number.isFinite(Number(entry.transferSize)) ? Number(entry.transferSize) : null, + encodedBodySize: Number.isFinite(Number(entry.encodedBodySize)) ? Number(entry.encodedBodySize) : null, + decodedBodySize: Number.isFinite(Number(entry.decodedBodySize)) ? Number(entry.decodedBodySize) : null, + nextHopProtocol: entry.nextHopProtocol || null, + responseStatus: Number.isFinite(Number(entry.responseStatus)) ? Number(entry.responseStatus) : null, + }); const url = location.href; const routeSessionMatch = url.match(/\/workbench\/sessions\/([^/?#]+)/u); const activeSession = document.querySelector('[data-active="true"][data-session-id], [aria-selected="true"][data-session-id], .active[data-session-id]'); @@ -1133,7 +1156,7 @@ async function samplePage(reason) { content: String(element.getAttribute("content") || "").slice(0, 200), })).filter((item) => item.key).sort((a, b) => a.key.localeCompare(b.key)), }, - performance: performance.getEntriesByType("resource").slice(-30).map((entry) => ({ name: entry.name.split(/[?#]/u)[0].slice(0, 240), initiatorType: entry.initiatorType, startTime: Math.round(entry.startTime), duration: Math.round(entry.duration) })), + performance: performance.getEntriesByType("resource").slice(-80).map(resourceTimingSample), }; }).catch((error) => ({ error: errorSummary(error), url: currentPageUrl() })); const sample = {