Skip to content

Commit 4e49f70

Browse files
committed
Only look at first request
1 parent cc84914 commit 4e49f70

File tree

1 file changed

+25
-27
lines changed

1 file changed

+25
-27
lines changed

dist/performance.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//[performance]
1+
[performance]
22

33
const response_bodies = $WPT_BODIES;
44
const script_response_bodies = $WPT_BODIES.filter(body => body.type === 'Script');
@@ -345,33 +345,31 @@ async function getSpeculationRules() {
345345
});
346346

347347
// Get rules from Speculation-Rules HTTP Header on the document
348-
const documentRequests = [$WPT_REQUESTS.find( req => req.url === document.location.href)] || [];
349-
const httpRules = await Promise.all(documentRequests.map(async request => {
350-
try {
351-
const speculationRulesHeaders = getParameterCaseInsensitive(request.response_headers, 'Speculation-Rules');
352-
if (speculationRulesHeaders) {
353-
return await Promise.all(speculationRulesHeaders.split(',').map(async (speculationRuleLocation) => {
354-
try {
355-
let url = decodeURI(speculationRuleLocation).slice(1, -1);
356-
if (url.startsWith('/')) {
357-
url = document.location.origin + url;
358-
} else if (!url.startsWith('http')) {
359-
url = document.location.href + url;
360-
}
361-
const response = await fetchWithTimeout(url);
362-
const body = await response.text();
363-
return {url: speculationRuleLocation, rule: JSON.parse(body)};
364-
} catch(error) {
365-
return {error};
348+
let httpRules = [];
349+
350+
const documentRequest = $WPT_REQUESTS.find( req => req.url === document.location.href);
351+
if (documentRequest) {
352+
353+
const speculationRulesHeaders = getParameterCaseInsensitive(documentRequest.response_headers, 'Speculation-Rules');
354+
if (speculationRulesHeaders) {
355+
356+
await Promise.all(speculationRulesHeaders.split(',').map(async (speculationRuleLocation) => {
357+
try {
358+
let url = decodeURI(speculationRuleLocation).slice(1, -1);
359+
if (url.startsWith('/')) {
360+
url = document.location.origin + url;
361+
} else if (!url.startsWith('http')) {
362+
url = document.location.href + url;
366363
}
367-
}));
368-
} else {
369-
return [];
370-
}
371-
} catch(error) {
372-
return {error};
364+
const response = await fetchWithTimeout(url);
365+
const body = await response.text();
366+
httpRules.push({url: speculationRuleLocation, rule: JSON.parse(body)});
367+
} catch(error) {
368+
httpRules.push({errorName: error.name, errorMessage: error.message});
369+
}
370+
}));
373371
}
374-
}));
372+
}
375373

376374
return {htmlRules: htmlRules, httpHeaderRules: httpRules};
377375
}
@@ -411,5 +409,5 @@ return Promise.all([getLcpElement(), getSpeculationRules()]).then(([lcp_elem_sta
411409
speculation_rules: speculation_rules,
412410
};
413411
}).catch(error => {
414-
return {error};
412+
return {errorName: error.name, errorMessage: error.message};
415413
});

0 commit comments

Comments
 (0)