|
1 | | -//[performance] |
| 1 | +[performance] |
2 | 2 |
|
3 | 3 | const response_bodies = $WPT_BODIES; |
4 | 4 | const script_response_bodies = $WPT_BODIES.filter(body => body.type === 'Script'); |
@@ -345,33 +345,31 @@ async function getSpeculationRules() { |
345 | 345 | }); |
346 | 346 |
|
347 | 347 | // 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; |
366 | 363 | } |
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 | + })); |
373 | 371 | } |
374 | | - })); |
| 372 | + } |
375 | 373 |
|
376 | 374 | return {htmlRules: htmlRules, httpHeaderRules: httpRules}; |
377 | 375 | } |
@@ -411,5 +409,5 @@ return Promise.all([getLcpElement(), getSpeculationRules()]).then(([lcp_elem_sta |
411 | 409 | speculation_rules: speculation_rules, |
412 | 410 | }; |
413 | 411 | }).catch(error => { |
414 | | - return {error}; |
| 412 | + return {errorName: error.name, errorMessage: error.message}; |
415 | 413 | }); |
0 commit comments