From ac0f4044963170ae3932272dc4e5886f3c5198ae Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Tue, 22 Apr 2025 23:26:48 +0200 Subject: [PATCH 1/2] Fix for iframes https://github.com/sitespeedio/sitespeed.io/issues/4124 --- index.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 647d722..10f3a4f 100644 --- a/index.js +++ b/index.js @@ -77,13 +77,21 @@ export function harFromMessages(messages, options) { responsesWithoutPage = [], paramsWithoutPage = [], responseReceivedExtraInfos = [], + mainFrameId, currentPageId; for (const message of messages) { - const params = message.params; + const params = message.params; const method = message.method; + if (method === 'Network.requestWillBeSent' && params.type === 'Document') { + if (!mainFrameId) { + mainFrameId = params.frameId; + } + } + + if (!/^(Page|Network)\..+/.test(method)) { continue; } @@ -94,7 +102,13 @@ export function harFromMessages(messages, options) { case 'Page.navigatedWithinDocument': { { const frameId = params.frameId; - const rootFrame = rootFrameMappings.get(frameId) || frameId; + const rootFrame = rootFrameMappings.get(frameId) ?? frameId; + + // Skip any iframe + if (mainFrameId && rootFrame !== mainFrameId) { + break; + } + if (pages.some(page => page.__frameId === rootFrame)) { continue; } From 59731a4713d286440649606e91667c502fd71f56 Mon Sep 17 00:00:00 2001 From: Peter Hedenskog Date: Tue, 22 Apr 2025 23:29:28 +0200 Subject: [PATCH 2/2] lint --- index.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 10f3a4f..2f1d761 100644 --- a/index.js +++ b/index.js @@ -81,17 +81,17 @@ export function harFromMessages(messages, options) { currentPageId; for (const message of messages) { - const params = message.params; const method = message.method; - if (method === 'Network.requestWillBeSent' && params.type === 'Document') { - if (!mainFrameId) { - mainFrameId = params.frameId; - } + if ( + method === 'Network.requestWillBeSent' && + params.type === 'Document' && + !mainFrameId + ) { + mainFrameId = params.frameId; } - if (!/^(Page|Network)\..+/.test(method)) { continue; } @@ -103,12 +103,12 @@ export function harFromMessages(messages, options) { { const frameId = params.frameId; const rootFrame = rootFrameMappings.get(frameId) ?? frameId; - + // Skip any iframe if (mainFrameId && rootFrame !== mainFrameId) { break; } - + if (pages.some(page => page.__frameId === rootFrame)) { continue; }