From c160b1d629fc8f69523a46a8dd16720ae3976c34 Mon Sep 17 00:00:00 2001 From: Gary Wilber Date: Thu, 13 Jul 2023 17:12:49 -0700 Subject: [PATCH 1/2] fix: fetch resource timing performance entry names should be strings --- lib/fetch/index.js | 2 +- test/fetch/resource-timing.js | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index f69371a941d..02acd3d3800 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -320,7 +320,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') { // https://w3c.github.io/resource-timing/#dfn-mark-resource-timing function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) { if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) { - performance.markResourceTiming(timingInfo, originalURL, initiatorType, globalThis, cacheState) + performance.markResourceTiming(timingInfo, originalURL.toString(), initiatorType, globalThis, cacheState) } } diff --git a/test/fetch/resource-timing.js b/test/fetch/resource-timing.js index 353f07f685b..25b3bcaafbb 100644 --- a/test/fetch/resource-timing.js +++ b/test/fetch/resource-timing.js @@ -13,22 +13,24 @@ const { const skip = nodeMajor < 18 || (nodeMajor === 18 && nodeMinor < 2) test('should create a PerformanceResourceTiming after each fetch request', { skip }, (t) => { - t.plan(6) + t.plan(8) const obs = new PerformanceObserver(list => { + const expectedResourceEntryName = `http://localhost:${server.address().port}/` + const entries = list.getEntries() t.equal(entries.length, 1) const [entry] = entries - t.same(entry.name, { - href: `http://localhost:${server.address().port}/`, - origin: `http://localhost:${server.address().port}`, - protocol: 'http' - }) + t.same(entry.name, expectedResourceEntryName) t.strictSame(entry.entryType, 'resource') t.ok(entry.duration >= 0) t.ok(entry.startTime >= 0) + const entriesByName = list.getEntriesByName(expectedResourceEntryName) + t.equal(entriesByName.length, 1) + t.strictSame(entriesByName[0], entry) + obs.disconnect() performance.clearResourceTimings() }) From 91a61f1a685c1d1b28484bc5f05f1632e8924a5d Mon Sep 17 00:00:00 2001 From: Gary Wilber Date: Fri, 14 Jul 2023 09:20:39 -0700 Subject: [PATCH 2/2] change .toString() to .href --- lib/fetch/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/fetch/index.js b/lib/fetch/index.js index 02acd3d3800..2b7fe3632ea 100644 --- a/lib/fetch/index.js +++ b/lib/fetch/index.js @@ -320,7 +320,7 @@ function finalizeAndReportTiming (response, initiatorType = 'other') { // https://w3c.github.io/resource-timing/#dfn-mark-resource-timing function markResourceTiming (timingInfo, originalURL, initiatorType, globalThis, cacheState) { if (nodeMajor > 18 || (nodeMajor === 18 && nodeMinor >= 2)) { - performance.markResourceTiming(timingInfo, originalURL.toString(), initiatorType, globalThis, cacheState) + performance.markResourceTiming(timingInfo, originalURL.href, initiatorType, globalThis, cacheState) } }