Fix runner.js - even safer property access

This commit is contained in:
2025-12-29 10:56:57 +11:00
parent 8838a7af07
commit f21308cfae

View File

@@ -154,13 +154,13 @@ async function _executeTest(url, options) {
// Safe property access // Safe property access
const getScore = (cat) => (lhr.categories[cat] && lhr.categories[cat].score) ? lhr.categories[cat].score * 100 : 0; const getScore = (cat) => (lhr.categories && lhr.categories[cat] && lhr.categories[cat].score) ? lhr.categories[cat].score * 100 : 0;
const getMetric = (aud) => (lhr.audits[aud] && lhr.audits[aud].numericValue) ? lhr.audits[aud].numericValue : 0; const getMetric = (aud) => (lhr.audits && lhr.audits[aud] && lhr.audits[aud].numericValue) ? lhr.audits[aud].numericValue : 0;
const summary = { const summary = {
id: testId, id: testId,
url: lhr.finalUrl, url: lhr.finalUrl || url,
timestamp: lhr.fetchTime, timestamp: lhr.fetchTime || new Date().toISOString(),
scores: { scores: {
performance: getScore('performance'), performance: getScore('performance'),
accessibility: getScore('accessibility'), accessibility: getScore('accessibility'),
@@ -225,8 +225,8 @@ async function _executeTest(url, options) {
const summary = { const summary = {
id: testId, id: testId,
url: lhr.finalUrl, url: lhr.finalUrl || url,
timestamp: lhr.fetchTime, timestamp: lhr.fetchTime || new Date().toISOString(),
scores: { scores: {
performance: getScore('performance'), performance: getScore('performance'),
accessibility: getScore('accessibility'), accessibility: getScore('accessibility'),