From def23f6b380c6daeef8582351d0f3798d3f9e5f1 Mon Sep 17 00:00:00 2001 From: Xiaobo Date: Mon, 16 Nov 2026 21:29:55 +0800 Subject: [PATCH] fix(extension): accept object-shaped response headers from CDP Network.responseReceived hands back response.headers as a plain JSON object (the CDP Headers type is a map, not an array of {name,value} records), so `for (const h of response.headers)` throws "object is not iterable" on every single response. queueExchange() rejects, the .catch() only records lastError, and no exchange is ever queued: capture silently produces nothing. Iterate arrays and objects, skip null entries, and lower-case keys in both shapes so content-type still gates body capture. --- extension/background.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/extension/background.js b/extension/background.js index 4514b30..f6d0312 100644 --- a/extension/background.js +++ b/extension/background.js @@ -92,7 +92,17 @@ function truncate(s) { async function queueExchange(info, response) { const respHeaders = {}; - for (const h of response.headers || []) respHeaders[h.name.toLowerCase()] = h.value; + // CDP hands back response.headers as a plain object (dict), not an array of + // {name,value} records; iterating it with for...of throws "object is not + // iterable" and no exchange is ever queued. Accept both shapes. + const rawHeaders = response.headers || {}; + if (Array.isArray(rawHeaders)) { + for (const h of rawHeaders) { + if (h && h.name != null) respHeaders[String(h.name).toLowerCase()] = h.value; + } + } else { + for (const [k, v] of Object.entries(rawHeaders)) respHeaders[String(k).toLowerCase()] = v; + } const mime = respHeaders["content-type"] || ""; let reqBody = info.postData || "";