lighthouse 9.5.0-dev.20220508 → 9.5.0-dev.20220509
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/report/bundle.esm.js +2 -0
- package/dist/report/flow.js +1 -1
- package/dist/report/standalone.js +1 -1
- package/lighthouse-core/audits/metrics/experimental-interaction-to-next-paint.js +3 -3
- package/lighthouse-core/computed/metrics/responsiveness.js +94 -5
- package/lighthouse-core/gather/gatherers/css-usage.js +59 -34
- package/package.json +1 -1
- package/report/renderer/performance-category-renderer.js +2 -0
- package/report/test/renderer/performance-category-renderer-test.js +20 -0
- package/types/artifacts.d.ts +18 -0
|
@@ -4060,6 +4060,8 @@ class PerformanceCategoryRenderer extends CategoryRenderer {
|
|
|
4060
4060
|
valueEl.textContent = 'Error!';
|
|
4061
4061
|
const tooltip = this.dom.createChildOf(descriptionEl, 'span');
|
|
4062
4062
|
tooltip.textContent = audit.result.errorMessage || 'Report error: no metric information';
|
|
4063
|
+
} else if (audit.result.scoreDisplayMode === 'notApplicable') {
|
|
4064
|
+
valueEl.textContent = '--';
|
|
4063
4065
|
}
|
|
4064
4066
|
|
|
4065
4067
|
return element;
|
package/dist/report/flow.js
CHANGED
|
@@ -127,7 +127,7 @@ class Ma{constructor(e,a){this._document=e,this._lighthouseChannel="unknown",thi
|
|
|
127
127
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
128
128
|
* See the License for the specific language governing permissions and
|
|
129
129
|
* limitations under the License.
|
|
130
|
-
*/class on extends Fa{_renderMetric(e){const a=this.dom.createComponent("metric"),n=this.dom.find(".lh-metric",a);n.id=e.result.id;const t=de.calculateRating(e.result.score,e.result.scoreDisplayMode);n.classList.add(`lh-metric--${t}`);this.dom.find(".lh-metric__title",a).textContent=e.result.title;const i=this.dom.find(".lh-metric__value",a);i.textContent=e.result.displayValue||"";const o=this.dom.find(".lh-metric__description",a);if(o.appendChild(this.dom.convertMarkdownLinkSnippets(e.result.description)),"error"===e.result.scoreDisplayMode){o.textContent="",i.textContent="Error!";this.dom.createChildOf(o,"span").textContent=e.result.errorMessage||"Report error: no metric information"}return n}_renderOpportunity(e,a){const n=this.dom.createComponent("opportunity"),t=this.populateAuditValues(e,n);if(t.id=e.result.id,!e.result.details||"error"===e.result.scoreDisplayMode)return t;const i=e.result.details;if("opportunity"!==i.type)return t;const o=this.dom.find("span.lh-audit__display-text, div.lh-audit__display-text",t),r=i.overallSavingsMs/a*100+"%";if(this.dom.find("div.lh-sparkline__bar",t).style.width=r,o.textContent=de.i18n.formatSeconds(i.overallSavingsMs,.01),e.result.displayValue){const a=e.result.displayValue;this.dom.find("div.lh-load-opportunity__sparkline",t).title=a,o.title=a}return t}_getWastedMs(e){if(e.result.details&&"opportunity"===e.result.details.type){const a=e.result.details;if("number"!=typeof a.overallSavingsMs)throw new Error("non-opportunity details passed to _getWastedMs");return a.overallSavingsMs}return Number.MIN_VALUE}_getScoringCalculatorHref(e){const a=e.filter((e=>"metrics"===e.group)),n=e.find((e=>"first-cpu-idle"===e.id)),t=e.find((e=>"first-meaningful-paint"===e.id));n&&a.push(n),t&&a.push(t);const i=[...a.map((e=>{let a;var n;return"number"==typeof e.result.numericValue?(a="cumulative-layout-shift"===e.id?(n=e.result.numericValue,Math.round(100*n)/100):Math.round(e.result.numericValue),a=a.toString()):a="null",[e.acronym||e.id,a]}))];de.reportJson&&(i.push(["device",de.reportJson.configSettings.formFactor]),i.push(["version",de.reportJson.lighthouseVersion]));const o=new URLSearchParams(i),r=new URL("https://googlechrome.github.io/lighthouse/scorecalc/");return r.hash=o.toString(),r.href}_classifyPerformanceAudit(e){return e.group?null:e.result.details&&"opportunity"===e.result.details.type?"load-opportunity":"diagnostic"}render(e,a,n){const t=de.i18n.strings,i=this.dom.createElement("div","lh-category");i.id=e.id,i.appendChild(this.renderCategoryHeader(e,a,n));const o=e.auditRefs.filter((e=>"metrics"===e.group));if(o.length){const[n,r]=this.renderAuditGroup(a.metrics),s=this.dom.createElement("input","lh-metrics-toggle__input"),l=`lh-metrics-toggle${de.getUniqueSuffix()}`;s.setAttribute("aria-label","Toggle the display of metric descriptions"),s.type="checkbox",s.id=l,n.prepend(s);const p=this.dom.find(".lh-audit-group__header",n),u=this.dom.createChildOf(p,"label","lh-metrics-toggle__label");u.htmlFor=l;const c=this.dom.createChildOf(u,"span","lh-metrics-toggle__labeltext--show"),d=this.dom.createChildOf(u,"span","lh-metrics-toggle__labeltext--hide");c.textContent=de.i18n.strings.expandView,d.textContent=de.i18n.strings.collapseView;const m=this.dom.createElement("div","lh-metrics-container");if(n.insertBefore(m,r),o.forEach((e=>{m.appendChild(this._renderMetric(e))})),i.querySelector(".lh-gauge__wrapper")){const a=this.dom.find(".lh-category-header__description",i),n=this.dom.createChildOf(a,"div","lh-metrics__disclaimer"),o=this.dom.convertMarkdownLinkSnippets(t.varianceDisclaimer);n.appendChild(o);const r=this.dom.createChildOf(n,"a","lh-calclink");r.target="_blank",r.textContent=t.calculatorLink,this.dom.safelySetHref(r,this._getScoringCalculatorHref(e.auditRefs))}n.classList.add("lh-audit-group--metrics"),i.appendChild(n)}const r=this.dom.createChildOf(i,"div","lh-filmstrip-container"),s=e.auditRefs.find((e=>"screenshot-thumbnails"===e.id))?.result;if(s?.details){r.id=s.id;const e=this.detailsRenderer.render(s.details);e&&r.appendChild(e)}const l=e.auditRefs.filter((e=>"load-opportunity"===this._classifyPerformanceAudit(e))).filter((e=>!de.showAsPassed(e.result))).sort(((e,a)=>this._getWastedMs(a)-this._getWastedMs(e))),p=o.filter((e=>!!e.relevantAudits));if(p.length&&this.renderMetricAuditFilter(p,i),l.length){const e=2e3,n=l.map((e=>this._getWastedMs(e))),o=Math.max(...n),r=Math.max(1e3*Math.ceil(o/1e3),e),[s,p]=this.renderAuditGroup(a["load-opportunities"]),u=this.dom.createComponent("opportunityHeader");this.dom.find(".lh-load-opportunity__col--one",u).textContent=t.opportunityResourceColumnLabel,this.dom.find(".lh-load-opportunity__col--two",u).textContent=t.opportunitySavingsColumnLabel;const c=this.dom.find(".lh-load-opportunity__header",u);s.insertBefore(c,p),l.forEach((e=>s.insertBefore(this._renderOpportunity(e,r),p))),s.classList.add("lh-audit-group--load-opportunities"),i.appendChild(s)}const u=e.auditRefs.filter((e=>"diagnostic"===this._classifyPerformanceAudit(e))).filter((e=>!de.showAsPassed(e.result))).sort(((e,a)=>("informative"===e.result.scoreDisplayMode?100:Number(e.result.score))-("informative"===a.result.scoreDisplayMode?100:Number(a.result.score))));if(u.length){const[e,n]=this.renderAuditGroup(a.diagnostics);u.forEach((a=>e.insertBefore(this.renderAudit(a),n))),e.classList.add("lh-audit-group--diagnostics"),i.appendChild(e)}const c=e.auditRefs.filter((e=>this._classifyPerformanceAudit(e)&&de.showAsPassed(e.result)));if(!c.length)return i;const d={auditRefs:c,groupDefinitions:a},m=this.renderClump("passed",d);i.appendChild(m);const h=[];if(["performance-budget","timing-budget"].forEach((a=>{const n=e.auditRefs.find((e=>e.id===a));if(n?.result.details){const e=this.detailsRenderer.render(n.result.details);e&&(e.id=a,e.classList.add("lh-details","lh-details--budget","lh-audit"),h.push(e))}})),h.length>0){const[e,n]=this.renderAuditGroup(a.budgets);h.forEach((a=>e.insertBefore(a,n))),e.classList.add("lh-audit-group--budgets"),i.appendChild(e)}return i}renderMetricAuditFilter(e,a){const n=this.dom.createElement("div","lh-metricfilter");this.dom.createChildOf(n,"span","lh-metricfilter__text").textContent=de.i18n.strings.showRelevantAudits;const t=[{acronym:"All"},...e],i=de.getUniqueSuffix();for(const e of t){const t=`metric-${e.acronym}-${i}`,o=this.dom.createChildOf(n,"input","lh-metricfilter__radio");o.type="radio",o.name=`metricsfilter-${i}`,o.id=t;const r=this.dom.createChildOf(n,"label","lh-metricfilter__label");r.htmlFor=t,r.title=e.result?.title,r.textContent=e.acronym||e.id,"All"===e.acronym&&(o.checked=!0,r.classList.add("lh-metricfilter__label--active")),a.append(n),o.addEventListener("input",(n=>{for(const e of a.querySelectorAll("label.lh-metricfilter__label"))e.classList.toggle("lh-metricfilter__label--active",e.htmlFor===t);a.classList.toggle("lh-category--filtered","All"!==e.acronym);for(const n of a.querySelectorAll("div.lh-audit"))"All"!==e.acronym?(n.hidden=!0,e.relevantAudits&&e.relevantAudits.includes(n.id)&&(n.hidden=!1)):n.hidden=!1;const i=a.querySelectorAll("div.lh-audit-group, details.lh-audit-group");for(const e of i){e.hidden=!1;const a=Array.from(e.querySelectorAll("div.lh-audit")),n=!!a.length&&a.every((e=>e.hidden));e.hidden=n}}))}}}
|
|
130
|
+
*/class on extends Fa{_renderMetric(e){const a=this.dom.createComponent("metric"),n=this.dom.find(".lh-metric",a);n.id=e.result.id;const t=de.calculateRating(e.result.score,e.result.scoreDisplayMode);n.classList.add(`lh-metric--${t}`);this.dom.find(".lh-metric__title",a).textContent=e.result.title;const i=this.dom.find(".lh-metric__value",a);i.textContent=e.result.displayValue||"";const o=this.dom.find(".lh-metric__description",a);if(o.appendChild(this.dom.convertMarkdownLinkSnippets(e.result.description)),"error"===e.result.scoreDisplayMode){o.textContent="",i.textContent="Error!";this.dom.createChildOf(o,"span").textContent=e.result.errorMessage||"Report error: no metric information"}else"notApplicable"===e.result.scoreDisplayMode&&(i.textContent="--");return n}_renderOpportunity(e,a){const n=this.dom.createComponent("opportunity"),t=this.populateAuditValues(e,n);if(t.id=e.result.id,!e.result.details||"error"===e.result.scoreDisplayMode)return t;const i=e.result.details;if("opportunity"!==i.type)return t;const o=this.dom.find("span.lh-audit__display-text, div.lh-audit__display-text",t),r=i.overallSavingsMs/a*100+"%";if(this.dom.find("div.lh-sparkline__bar",t).style.width=r,o.textContent=de.i18n.formatSeconds(i.overallSavingsMs,.01),e.result.displayValue){const a=e.result.displayValue;this.dom.find("div.lh-load-opportunity__sparkline",t).title=a,o.title=a}return t}_getWastedMs(e){if(e.result.details&&"opportunity"===e.result.details.type){const a=e.result.details;if("number"!=typeof a.overallSavingsMs)throw new Error("non-opportunity details passed to _getWastedMs");return a.overallSavingsMs}return Number.MIN_VALUE}_getScoringCalculatorHref(e){const a=e.filter((e=>"metrics"===e.group)),n=e.find((e=>"first-cpu-idle"===e.id)),t=e.find((e=>"first-meaningful-paint"===e.id));n&&a.push(n),t&&a.push(t);const i=[...a.map((e=>{let a;var n;return"number"==typeof e.result.numericValue?(a="cumulative-layout-shift"===e.id?(n=e.result.numericValue,Math.round(100*n)/100):Math.round(e.result.numericValue),a=a.toString()):a="null",[e.acronym||e.id,a]}))];de.reportJson&&(i.push(["device",de.reportJson.configSettings.formFactor]),i.push(["version",de.reportJson.lighthouseVersion]));const o=new URLSearchParams(i),r=new URL("https://googlechrome.github.io/lighthouse/scorecalc/");return r.hash=o.toString(),r.href}_classifyPerformanceAudit(e){return e.group?null:e.result.details&&"opportunity"===e.result.details.type?"load-opportunity":"diagnostic"}render(e,a,n){const t=de.i18n.strings,i=this.dom.createElement("div","lh-category");i.id=e.id,i.appendChild(this.renderCategoryHeader(e,a,n));const o=e.auditRefs.filter((e=>"metrics"===e.group));if(o.length){const[n,r]=this.renderAuditGroup(a.metrics),s=this.dom.createElement("input","lh-metrics-toggle__input"),l=`lh-metrics-toggle${de.getUniqueSuffix()}`;s.setAttribute("aria-label","Toggle the display of metric descriptions"),s.type="checkbox",s.id=l,n.prepend(s);const p=this.dom.find(".lh-audit-group__header",n),u=this.dom.createChildOf(p,"label","lh-metrics-toggle__label");u.htmlFor=l;const c=this.dom.createChildOf(u,"span","lh-metrics-toggle__labeltext--show"),d=this.dom.createChildOf(u,"span","lh-metrics-toggle__labeltext--hide");c.textContent=de.i18n.strings.expandView,d.textContent=de.i18n.strings.collapseView;const m=this.dom.createElement("div","lh-metrics-container");if(n.insertBefore(m,r),o.forEach((e=>{m.appendChild(this._renderMetric(e))})),i.querySelector(".lh-gauge__wrapper")){const a=this.dom.find(".lh-category-header__description",i),n=this.dom.createChildOf(a,"div","lh-metrics__disclaimer"),o=this.dom.convertMarkdownLinkSnippets(t.varianceDisclaimer);n.appendChild(o);const r=this.dom.createChildOf(n,"a","lh-calclink");r.target="_blank",r.textContent=t.calculatorLink,this.dom.safelySetHref(r,this._getScoringCalculatorHref(e.auditRefs))}n.classList.add("lh-audit-group--metrics"),i.appendChild(n)}const r=this.dom.createChildOf(i,"div","lh-filmstrip-container"),s=e.auditRefs.find((e=>"screenshot-thumbnails"===e.id))?.result;if(s?.details){r.id=s.id;const e=this.detailsRenderer.render(s.details);e&&r.appendChild(e)}const l=e.auditRefs.filter((e=>"load-opportunity"===this._classifyPerformanceAudit(e))).filter((e=>!de.showAsPassed(e.result))).sort(((e,a)=>this._getWastedMs(a)-this._getWastedMs(e))),p=o.filter((e=>!!e.relevantAudits));if(p.length&&this.renderMetricAuditFilter(p,i),l.length){const e=2e3,n=l.map((e=>this._getWastedMs(e))),o=Math.max(...n),r=Math.max(1e3*Math.ceil(o/1e3),e),[s,p]=this.renderAuditGroup(a["load-opportunities"]),u=this.dom.createComponent("opportunityHeader");this.dom.find(".lh-load-opportunity__col--one",u).textContent=t.opportunityResourceColumnLabel,this.dom.find(".lh-load-opportunity__col--two",u).textContent=t.opportunitySavingsColumnLabel;const c=this.dom.find(".lh-load-opportunity__header",u);s.insertBefore(c,p),l.forEach((e=>s.insertBefore(this._renderOpportunity(e,r),p))),s.classList.add("lh-audit-group--load-opportunities"),i.appendChild(s)}const u=e.auditRefs.filter((e=>"diagnostic"===this._classifyPerformanceAudit(e))).filter((e=>!de.showAsPassed(e.result))).sort(((e,a)=>("informative"===e.result.scoreDisplayMode?100:Number(e.result.score))-("informative"===a.result.scoreDisplayMode?100:Number(a.result.score))));if(u.length){const[e,n]=this.renderAuditGroup(a.diagnostics);u.forEach((a=>e.insertBefore(this.renderAudit(a),n))),e.classList.add("lh-audit-group--diagnostics"),i.appendChild(e)}const c=e.auditRefs.filter((e=>this._classifyPerformanceAudit(e)&&de.showAsPassed(e.result)));if(!c.length)return i;const d={auditRefs:c,groupDefinitions:a},m=this.renderClump("passed",d);i.appendChild(m);const h=[];if(["performance-budget","timing-budget"].forEach((a=>{const n=e.auditRefs.find((e=>e.id===a));if(n?.result.details){const e=this.detailsRenderer.render(n.result.details);e&&(e.id=a,e.classList.add("lh-details","lh-details--budget","lh-audit"),h.push(e))}})),h.length>0){const[e,n]=this.renderAuditGroup(a.budgets);h.forEach((a=>e.insertBefore(a,n))),e.classList.add("lh-audit-group--budgets"),i.appendChild(e)}return i}renderMetricAuditFilter(e,a){const n=this.dom.createElement("div","lh-metricfilter");this.dom.createChildOf(n,"span","lh-metricfilter__text").textContent=de.i18n.strings.showRelevantAudits;const t=[{acronym:"All"},...e],i=de.getUniqueSuffix();for(const e of t){const t=`metric-${e.acronym}-${i}`,o=this.dom.createChildOf(n,"input","lh-metricfilter__radio");o.type="radio",o.name=`metricsfilter-${i}`,o.id=t;const r=this.dom.createChildOf(n,"label","lh-metricfilter__label");r.htmlFor=t,r.title=e.result?.title,r.textContent=e.acronym||e.id,"All"===e.acronym&&(o.checked=!0,r.classList.add("lh-metricfilter__label--active")),a.append(n),o.addEventListener("input",(n=>{for(const e of a.querySelectorAll("label.lh-metricfilter__label"))e.classList.toggle("lh-metricfilter__label--active",e.htmlFor===t);a.classList.toggle("lh-category--filtered","All"!==e.acronym);for(const n of a.querySelectorAll("div.lh-audit"))"All"!==e.acronym?(n.hidden=!0,e.relevantAudits&&e.relevantAudits.includes(n.id)&&(n.hidden=!1)):n.hidden=!1;const i=a.querySelectorAll("div.lh-audit-group, details.lh-audit-group");for(const e of i){e.hidden=!1;const a=Array.from(e.querySelectorAll("div.lh-audit")),n=!!a.length&&a.every((e=>e.hidden));e.hidden=n}}))}}}
|
|
131
131
|
/**
|
|
132
132
|
* @license
|
|
133
133
|
* Copyright 2018 The Lighthouse Authors. All Rights Reserved.
|
|
@@ -110,7 +110,7 @@ class s{constructor(e,t){this._document=e,this._lighthouseChannel="unknown",this
|
|
|
110
110
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
111
111
|
* See the License for the specific language governing permissions and
|
|
112
112
|
* limitations under the License.
|
|
113
|
-
*/class F extends c{_renderMetric(e){const t=this.dom.createComponent("metric"),n=this.dom.find(".lh-metric",t);n.id=e.result.id;const r=l.calculateRating(e.result.score,e.result.scoreDisplayMode);n.classList.add(`lh-metric--${r}`);this.dom.find(".lh-metric__title",t).textContent=e.result.title;const o=this.dom.find(".lh-metric__value",t);o.textContent=e.result.displayValue||"";const i=this.dom.find(".lh-metric__description",t);if(i.appendChild(this.dom.convertMarkdownLinkSnippets(e.result.description)),"error"===e.result.scoreDisplayMode){i.textContent="",o.textContent="Error!";this.dom.createChildOf(i,"span").textContent=e.result.errorMessage||"Report error: no metric information"}return n}_renderOpportunity(e,t){const n=this.dom.createComponent("opportunity"),r=this.populateAuditValues(e,n);if(r.id=e.result.id,!e.result.details||"error"===e.result.scoreDisplayMode)return r;const o=e.result.details;if("opportunity"!==o.type)return r;const i=this.dom.find("span.lh-audit__display-text, div.lh-audit__display-text",r),a=o.overallSavingsMs/t*100+"%";if(this.dom.find("div.lh-sparkline__bar",r).style.width=a,i.textContent=l.i18n.formatSeconds(o.overallSavingsMs,.01),e.result.displayValue){const t=e.result.displayValue;this.dom.find("div.lh-load-opportunity__sparkline",r).title=t,i.title=t}return r}_getWastedMs(e){if(e.result.details&&"opportunity"===e.result.details.type){const t=e.result.details;if("number"!=typeof t.overallSavingsMs)throw new Error("non-opportunity details passed to _getWastedMs");return t.overallSavingsMs}return Number.MIN_VALUE}_getScoringCalculatorHref(e){const t=e.filter((e=>"metrics"===e.group)),n=e.find((e=>"first-cpu-idle"===e.id)),r=e.find((e=>"first-meaningful-paint"===e.id));n&&t.push(n),r&&t.push(r);const o=[...t.map((e=>{let t;var n;return"number"==typeof e.result.numericValue?(t="cumulative-layout-shift"===e.id?(n=e.result.numericValue,Math.round(100*n)/100):Math.round(e.result.numericValue),t=t.toString()):t="null",[e.acronym||e.id,t]}))];l.reportJson&&(o.push(["device",l.reportJson.configSettings.formFactor]),o.push(["version",l.reportJson.lighthouseVersion]));const i=new URLSearchParams(o),a=new URL("https://googlechrome.github.io/lighthouse/scorecalc/");return a.hash=i.toString(),a.href}_classifyPerformanceAudit(e){return e.group?null:e.result.details&&"opportunity"===e.result.details.type?"load-opportunity":"diagnostic"}render(e,t,n){const r=l.i18n.strings,o=this.dom.createElement("div","lh-category");o.id=e.id,o.appendChild(this.renderCategoryHeader(e,t,n));const i=e.auditRefs.filter((e=>"metrics"===e.group));if(i.length){const[n,a]=this.renderAuditGroup(t.metrics),s=this.dom.createElement("input","lh-metrics-toggle__input"),c=`lh-metrics-toggle${l.getUniqueSuffix()}`;s.setAttribute("aria-label","Toggle the display of metric descriptions"),s.type="checkbox",s.id=c,n.prepend(s);const d=this.dom.find(".lh-audit-group__header",n),h=this.dom.createChildOf(d,"label","lh-metrics-toggle__label");h.htmlFor=c;const p=this.dom.createChildOf(h,"span","lh-metrics-toggle__labeltext--show"),u=this.dom.createChildOf(h,"span","lh-metrics-toggle__labeltext--hide");p.textContent=l.i18n.strings.expandView,u.textContent=l.i18n.strings.collapseView;const g=this.dom.createElement("div","lh-metrics-container");if(n.insertBefore(g,a),i.forEach((e=>{g.appendChild(this._renderMetric(e))})),o.querySelector(".lh-gauge__wrapper")){const t=this.dom.find(".lh-category-header__description",o),n=this.dom.createChildOf(t,"div","lh-metrics__disclaimer"),i=this.dom.convertMarkdownLinkSnippets(r.varianceDisclaimer);n.appendChild(i);const a=this.dom.createChildOf(n,"a","lh-calclink");a.target="_blank",a.textContent=r.calculatorLink,this.dom.safelySetHref(a,this._getScoringCalculatorHref(e.auditRefs))}n.classList.add("lh-audit-group--metrics"),o.appendChild(n)}const a=this.dom.createChildOf(o,"div","lh-filmstrip-container"),s=e.auditRefs.find((e=>"screenshot-thumbnails"===e.id))?.result;if(s?.details){a.id=s.id;const e=this.detailsRenderer.render(s.details);e&&a.appendChild(e)}const c=e.auditRefs.filter((e=>"load-opportunity"===this._classifyPerformanceAudit(e))).filter((e=>!l.showAsPassed(e.result))).sort(((e,t)=>this._getWastedMs(t)-this._getWastedMs(e))),d=i.filter((e=>!!e.relevantAudits));if(d.length&&this.renderMetricAuditFilter(d,o),c.length){const e=2e3,n=c.map((e=>this._getWastedMs(e))),i=Math.max(...n),a=Math.max(1e3*Math.ceil(i/1e3),e),[l,s]=this.renderAuditGroup(t["load-opportunities"]),d=this.dom.createComponent("opportunityHeader");this.dom.find(".lh-load-opportunity__col--one",d).textContent=r.opportunityResourceColumnLabel,this.dom.find(".lh-load-opportunity__col--two",d).textContent=r.opportunitySavingsColumnLabel;const h=this.dom.find(".lh-load-opportunity__header",d);l.insertBefore(h,s),c.forEach((e=>l.insertBefore(this._renderOpportunity(e,a),s))),l.classList.add("lh-audit-group--load-opportunities"),o.appendChild(l)}const h=e.auditRefs.filter((e=>"diagnostic"===this._classifyPerformanceAudit(e))).filter((e=>!l.showAsPassed(e.result))).sort(((e,t)=>("informative"===e.result.scoreDisplayMode?100:Number(e.result.score))-("informative"===t.result.scoreDisplayMode?100:Number(t.result.score))));if(h.length){const[e,n]=this.renderAuditGroup(t.diagnostics);h.forEach((t=>e.insertBefore(this.renderAudit(t),n))),e.classList.add("lh-audit-group--diagnostics"),o.appendChild(e)}const p=e.auditRefs.filter((e=>this._classifyPerformanceAudit(e)&&l.showAsPassed(e.result)));if(!p.length)return o;const u={auditRefs:p,groupDefinitions:t},g=this.renderClump("passed",u);o.appendChild(g);const m=[];if(["performance-budget","timing-budget"].forEach((t=>{const n=e.auditRefs.find((e=>e.id===t));if(n?.result.details){const e=this.detailsRenderer.render(n.result.details);e&&(e.id=t,e.classList.add("lh-details","lh-details--budget","lh-audit"),m.push(e))}})),m.length>0){const[e,n]=this.renderAuditGroup(t.budgets);m.forEach((t=>e.insertBefore(t,n))),e.classList.add("lh-audit-group--budgets"),o.appendChild(e)}return o}renderMetricAuditFilter(e,t){const n=this.dom.createElement("div","lh-metricfilter");this.dom.createChildOf(n,"span","lh-metricfilter__text").textContent=l.i18n.strings.showRelevantAudits;const r=[{acronym:"All"},...e],o=l.getUniqueSuffix();for(const e of r){const r=`metric-${e.acronym}-${o}`,i=this.dom.createChildOf(n,"input","lh-metricfilter__radio");i.type="radio",i.name=`metricsfilter-${o}`,i.id=r;const a=this.dom.createChildOf(n,"label","lh-metricfilter__label");a.htmlFor=r,a.title=e.result?.title,a.textContent=e.acronym||e.id,"All"===e.acronym&&(i.checked=!0,a.classList.add("lh-metricfilter__label--active")),t.append(n),i.addEventListener("input",(n=>{for(const e of t.querySelectorAll("label.lh-metricfilter__label"))e.classList.toggle("lh-metricfilter__label--active",e.htmlFor===r);t.classList.toggle("lh-category--filtered","All"!==e.acronym);for(const n of t.querySelectorAll("div.lh-audit"))"All"!==e.acronym?(n.hidden=!0,e.relevantAudits&&e.relevantAudits.includes(n.id)&&(n.hidden=!1)):n.hidden=!1;const o=t.querySelectorAll("div.lh-audit-group, details.lh-audit-group");for(const e of o){e.hidden=!1;const t=Array.from(e.querySelectorAll("div.lh-audit")),n=!!t.length&&t.every((e=>e.hidden));e.hidden=n}}))}}}
|
|
113
|
+
*/class F extends c{_renderMetric(e){const t=this.dom.createComponent("metric"),n=this.dom.find(".lh-metric",t);n.id=e.result.id;const r=l.calculateRating(e.result.score,e.result.scoreDisplayMode);n.classList.add(`lh-metric--${r}`);this.dom.find(".lh-metric__title",t).textContent=e.result.title;const o=this.dom.find(".lh-metric__value",t);o.textContent=e.result.displayValue||"";const i=this.dom.find(".lh-metric__description",t);if(i.appendChild(this.dom.convertMarkdownLinkSnippets(e.result.description)),"error"===e.result.scoreDisplayMode){i.textContent="",o.textContent="Error!";this.dom.createChildOf(i,"span").textContent=e.result.errorMessage||"Report error: no metric information"}else"notApplicable"===e.result.scoreDisplayMode&&(o.textContent="--");return n}_renderOpportunity(e,t){const n=this.dom.createComponent("opportunity"),r=this.populateAuditValues(e,n);if(r.id=e.result.id,!e.result.details||"error"===e.result.scoreDisplayMode)return r;const o=e.result.details;if("opportunity"!==o.type)return r;const i=this.dom.find("span.lh-audit__display-text, div.lh-audit__display-text",r),a=o.overallSavingsMs/t*100+"%";if(this.dom.find("div.lh-sparkline__bar",r).style.width=a,i.textContent=l.i18n.formatSeconds(o.overallSavingsMs,.01),e.result.displayValue){const t=e.result.displayValue;this.dom.find("div.lh-load-opportunity__sparkline",r).title=t,i.title=t}return r}_getWastedMs(e){if(e.result.details&&"opportunity"===e.result.details.type){const t=e.result.details;if("number"!=typeof t.overallSavingsMs)throw new Error("non-opportunity details passed to _getWastedMs");return t.overallSavingsMs}return Number.MIN_VALUE}_getScoringCalculatorHref(e){const t=e.filter((e=>"metrics"===e.group)),n=e.find((e=>"first-cpu-idle"===e.id)),r=e.find((e=>"first-meaningful-paint"===e.id));n&&t.push(n),r&&t.push(r);const o=[...t.map((e=>{let t;var n;return"number"==typeof e.result.numericValue?(t="cumulative-layout-shift"===e.id?(n=e.result.numericValue,Math.round(100*n)/100):Math.round(e.result.numericValue),t=t.toString()):t="null",[e.acronym||e.id,t]}))];l.reportJson&&(o.push(["device",l.reportJson.configSettings.formFactor]),o.push(["version",l.reportJson.lighthouseVersion]));const i=new URLSearchParams(o),a=new URL("https://googlechrome.github.io/lighthouse/scorecalc/");return a.hash=i.toString(),a.href}_classifyPerformanceAudit(e){return e.group?null:e.result.details&&"opportunity"===e.result.details.type?"load-opportunity":"diagnostic"}render(e,t,n){const r=l.i18n.strings,o=this.dom.createElement("div","lh-category");o.id=e.id,o.appendChild(this.renderCategoryHeader(e,t,n));const i=e.auditRefs.filter((e=>"metrics"===e.group));if(i.length){const[n,a]=this.renderAuditGroup(t.metrics),s=this.dom.createElement("input","lh-metrics-toggle__input"),c=`lh-metrics-toggle${l.getUniqueSuffix()}`;s.setAttribute("aria-label","Toggle the display of metric descriptions"),s.type="checkbox",s.id=c,n.prepend(s);const d=this.dom.find(".lh-audit-group__header",n),h=this.dom.createChildOf(d,"label","lh-metrics-toggle__label");h.htmlFor=c;const p=this.dom.createChildOf(h,"span","lh-metrics-toggle__labeltext--show"),u=this.dom.createChildOf(h,"span","lh-metrics-toggle__labeltext--hide");p.textContent=l.i18n.strings.expandView,u.textContent=l.i18n.strings.collapseView;const g=this.dom.createElement("div","lh-metrics-container");if(n.insertBefore(g,a),i.forEach((e=>{g.appendChild(this._renderMetric(e))})),o.querySelector(".lh-gauge__wrapper")){const t=this.dom.find(".lh-category-header__description",o),n=this.dom.createChildOf(t,"div","lh-metrics__disclaimer"),i=this.dom.convertMarkdownLinkSnippets(r.varianceDisclaimer);n.appendChild(i);const a=this.dom.createChildOf(n,"a","lh-calclink");a.target="_blank",a.textContent=r.calculatorLink,this.dom.safelySetHref(a,this._getScoringCalculatorHref(e.auditRefs))}n.classList.add("lh-audit-group--metrics"),o.appendChild(n)}const a=this.dom.createChildOf(o,"div","lh-filmstrip-container"),s=e.auditRefs.find((e=>"screenshot-thumbnails"===e.id))?.result;if(s?.details){a.id=s.id;const e=this.detailsRenderer.render(s.details);e&&a.appendChild(e)}const c=e.auditRefs.filter((e=>"load-opportunity"===this._classifyPerformanceAudit(e))).filter((e=>!l.showAsPassed(e.result))).sort(((e,t)=>this._getWastedMs(t)-this._getWastedMs(e))),d=i.filter((e=>!!e.relevantAudits));if(d.length&&this.renderMetricAuditFilter(d,o),c.length){const e=2e3,n=c.map((e=>this._getWastedMs(e))),i=Math.max(...n),a=Math.max(1e3*Math.ceil(i/1e3),e),[l,s]=this.renderAuditGroup(t["load-opportunities"]),d=this.dom.createComponent("opportunityHeader");this.dom.find(".lh-load-opportunity__col--one",d).textContent=r.opportunityResourceColumnLabel,this.dom.find(".lh-load-opportunity__col--two",d).textContent=r.opportunitySavingsColumnLabel;const h=this.dom.find(".lh-load-opportunity__header",d);l.insertBefore(h,s),c.forEach((e=>l.insertBefore(this._renderOpportunity(e,a),s))),l.classList.add("lh-audit-group--load-opportunities"),o.appendChild(l)}const h=e.auditRefs.filter((e=>"diagnostic"===this._classifyPerformanceAudit(e))).filter((e=>!l.showAsPassed(e.result))).sort(((e,t)=>("informative"===e.result.scoreDisplayMode?100:Number(e.result.score))-("informative"===t.result.scoreDisplayMode?100:Number(t.result.score))));if(h.length){const[e,n]=this.renderAuditGroup(t.diagnostics);h.forEach((t=>e.insertBefore(this.renderAudit(t),n))),e.classList.add("lh-audit-group--diagnostics"),o.appendChild(e)}const p=e.auditRefs.filter((e=>this._classifyPerformanceAudit(e)&&l.showAsPassed(e.result)));if(!p.length)return o;const u={auditRefs:p,groupDefinitions:t},g=this.renderClump("passed",u);o.appendChild(g);const m=[];if(["performance-budget","timing-budget"].forEach((t=>{const n=e.auditRefs.find((e=>e.id===t));if(n?.result.details){const e=this.detailsRenderer.render(n.result.details);e&&(e.id=t,e.classList.add("lh-details","lh-details--budget","lh-audit"),m.push(e))}})),m.length>0){const[e,n]=this.renderAuditGroup(t.budgets);m.forEach((t=>e.insertBefore(t,n))),e.classList.add("lh-audit-group--budgets"),o.appendChild(e)}return o}renderMetricAuditFilter(e,t){const n=this.dom.createElement("div","lh-metricfilter");this.dom.createChildOf(n,"span","lh-metricfilter__text").textContent=l.i18n.strings.showRelevantAudits;const r=[{acronym:"All"},...e],o=l.getUniqueSuffix();for(const e of r){const r=`metric-${e.acronym}-${o}`,i=this.dom.createChildOf(n,"input","lh-metricfilter__radio");i.type="radio",i.name=`metricsfilter-${o}`,i.id=r;const a=this.dom.createChildOf(n,"label","lh-metricfilter__label");a.htmlFor=r,a.title=e.result?.title,a.textContent=e.acronym||e.id,"All"===e.acronym&&(i.checked=!0,a.classList.add("lh-metricfilter__label--active")),t.append(n),i.addEventListener("input",(n=>{for(const e of t.querySelectorAll("label.lh-metricfilter__label"))e.classList.toggle("lh-metricfilter__label--active",e.htmlFor===r);t.classList.toggle("lh-category--filtered","All"!==e.acronym);for(const n of t.querySelectorAll("div.lh-audit"))"All"!==e.acronym?(n.hidden=!0,e.relevantAudits&&e.relevantAudits.includes(n.id)&&(n.hidden=!1)):n.hidden=!1;const o=t.querySelectorAll("div.lh-audit-group, details.lh-audit-group");for(const e of o){e.hidden=!1;const t=Array.from(e.querySelectorAll("div.lh-audit")),n=!!t.length&&t.every((e=>e.hidden));e.hidden=n}}))}}}
|
|
114
114
|
/**
|
|
115
115
|
* @license
|
|
116
116
|
* Copyright 2018 The Lighthouse Authors. All Rights Reserved.
|
|
@@ -63,14 +63,14 @@ class ExperimentalInteractionToNextPaint extends Audit {
|
|
|
63
63
|
|
|
64
64
|
const trace = artifacts.traces[Audit.DEFAULT_PASS];
|
|
65
65
|
const metricData = {trace, settings};
|
|
66
|
-
const
|
|
66
|
+
const interactionEvent = await ComputedResponsivenes.request(metricData, context);
|
|
67
67
|
|
|
68
68
|
// TODO: include the no-interaction state in the report instead of using n/a.
|
|
69
|
-
if (
|
|
69
|
+
if (interactionEvent === null) {
|
|
70
70
|
return {score: null, notApplicable: true};
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
const timing =
|
|
73
|
+
const timing = interactionEvent.args.data.duration;
|
|
74
74
|
|
|
75
75
|
return {
|
|
76
76
|
score: Audit.computeLogNormalScore({p10: context.options.p10, median: context.options.median},
|
|
@@ -12,9 +12,34 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
/** @typedef {LH.Trace.CompleteEvent & {name: 'Responsiveness.Renderer.UserInteraction', args: {frame: string, data: {interactionType: 'drag'|'keyboard'|'tapOrClick', maxDuration: number}}}} ResponsivenessEvent */
|
|
15
|
+
/** @typedef {'keydown'|'keypress'|'keyup'|'mousedown'|'mouseup'|'pointerdown'|'pointerup'|'click'} EventTimingType */
|
|
16
|
+
/**
|
|
17
|
+
* @typedef EventTimingData
|
|
18
|
+
* @property {string} frame
|
|
19
|
+
* @property {number} timeStamp The time of user interaction (in ms from navStart).
|
|
20
|
+
* @property {number} processingStart The start of interaction handling (in ms from navStart).
|
|
21
|
+
* @property {number} processingEnd The end of interaction handling (in ms from navStart).
|
|
22
|
+
* @property {number} duration The time from user interaction to browser paint (in ms).
|
|
23
|
+
* @property {EventTimingType} type
|
|
24
|
+
* @property {number} nodeId
|
|
25
|
+
* @property {number} interactionId
|
|
26
|
+
*/
|
|
27
|
+
/** @typedef {LH.Trace.AsyncEvent & {name: 'EventTiming', args: {data: EventTimingData}}} EventTimingEvent */
|
|
28
|
+
|
|
15
29
|
|
|
16
30
|
const makeComputedArtifact = require('../computed-artifact.js');
|
|
17
31
|
const ProcessedTrace = require('../processed-trace.js');
|
|
32
|
+
const LHError = require('../../lib/lh-error.js');
|
|
33
|
+
|
|
34
|
+
const KEYBOARD_EVENTS = new Set(['keydown', 'keypress', 'keyup']);
|
|
35
|
+
const CLICK_TAP_DRAG_EVENTS = new Set([
|
|
36
|
+
'mousedown', 'mouseup', 'pointerdown', 'pointerup', 'click']);
|
|
37
|
+
/** A map of Responsiveness `interactionType` to matching EventTiming `type`s. */
|
|
38
|
+
const interactionTypeToType = {
|
|
39
|
+
keyboard: KEYBOARD_EVENTS,
|
|
40
|
+
tapOrClick: CLICK_TAP_DRAG_EVENTS,
|
|
41
|
+
drag: CLICK_TAP_DRAG_EVENTS,
|
|
42
|
+
};
|
|
18
43
|
|
|
19
44
|
class Responsiveness {
|
|
20
45
|
/**
|
|
@@ -42,20 +67,84 @@ class Responsiveness {
|
|
|
42
67
|
return responsivenessEvents[index];
|
|
43
68
|
}
|
|
44
69
|
|
|
70
|
+
/**
|
|
71
|
+
* Finds the interaction event that was probably the responsivenessEvent.maxDuration
|
|
72
|
+
* source.
|
|
73
|
+
* Note that (presumably due to rounding to ms), the interaction duration may not
|
|
74
|
+
* be the same value as `maxDuration`, just the closest value. Function will throw
|
|
75
|
+
* if the closest match is off by more than 4ms.
|
|
76
|
+
* TODO: this doesn't try to match inputs to interactions and break ties if more than
|
|
77
|
+
* one interaction had this duration by returning the first found.
|
|
78
|
+
* @param {ResponsivenessEvent} responsivenessEvent
|
|
79
|
+
* @param {LH.Trace} trace
|
|
80
|
+
* @return {EventTimingEvent}
|
|
81
|
+
*/
|
|
82
|
+
static findInteractionEvent(responsivenessEvent, {traceEvents}) {
|
|
83
|
+
const candidates = traceEvents.filter(/** @return {evt is EventTimingEvent} */ evt => {
|
|
84
|
+
// Examine only beginning/instant EventTiming events.
|
|
85
|
+
return evt.name === 'EventTiming' && evt.ph !== 'e';
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (candidates.length && !candidates[0].args.data.frame) {
|
|
89
|
+
// Full EventTiming data added in https://crrev.com/c/3632661
|
|
90
|
+
throw new LHError(
|
|
91
|
+
LHError.errors.UNSUPPORTED_OLD_CHROME,
|
|
92
|
+
{featureName: 'detailed EventTiming trace events'}
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const {maxDuration, interactionType} = responsivenessEvent.args.data;
|
|
97
|
+
let bestMatchEvent;
|
|
98
|
+
let minDurationDiff = Number.POSITIVE_INFINITY;
|
|
99
|
+
for (const candidate of candidates) {
|
|
100
|
+
// Must be from same frame.
|
|
101
|
+
if (candidate.args.data.frame !== responsivenessEvent.args.frame) continue;
|
|
102
|
+
|
|
103
|
+
// TODO(bckenny): must be in same navigation as well.
|
|
104
|
+
|
|
105
|
+
const {type, duration} = candidate.args.data;
|
|
106
|
+
// Discard if type is incompatible with responsiveness interactionType.
|
|
107
|
+
const matchingTypes = interactionTypeToType[interactionType];
|
|
108
|
+
if (!matchingTypes) {
|
|
109
|
+
throw new Error(`unexpected responsiveness interactionType '${interactionType}'`);
|
|
110
|
+
}
|
|
111
|
+
if (!matchingTypes.has(type)) continue;
|
|
112
|
+
|
|
113
|
+
const durationDiff = Math.abs(duration - maxDuration);
|
|
114
|
+
if (durationDiff < minDurationDiff) {
|
|
115
|
+
bestMatchEvent = candidate;
|
|
116
|
+
minDurationDiff = durationDiff;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!bestMatchEvent) {
|
|
121
|
+
throw new Error(`no interaction event found for responsiveness type '${interactionType}'`);
|
|
122
|
+
}
|
|
123
|
+
// TODO: seems to regularly happen up to 3ms and as high as 4. Allow for up to 5ms to be sure.
|
|
124
|
+
if (minDurationDiff > 5) {
|
|
125
|
+
throw new Error(`no interaction event found within 5ms of responsiveness maxDuration (max: ${maxDuration}, closest ${bestMatchEvent.args.data.duration})`); // eslint-disable-line max-len
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return bestMatchEvent;
|
|
129
|
+
}
|
|
130
|
+
|
|
45
131
|
/**
|
|
46
132
|
* @param {{trace: LH.Trace, settings: Immutable<LH.Config.Settings>}} data
|
|
47
133
|
* @param {LH.Artifacts.ComputedContext} context
|
|
48
|
-
* @return {Promise<
|
|
134
|
+
* @return {Promise<EventTimingEvent|null>}
|
|
49
135
|
*/
|
|
50
136
|
static async compute_(data, context) {
|
|
51
|
-
|
|
137
|
+
const {settings, trace} = data;
|
|
138
|
+
if (settings.throttlingMethod === 'simulate') {
|
|
52
139
|
throw new Error('Responsiveness currently unsupported by simulated throttling');
|
|
53
140
|
}
|
|
54
141
|
|
|
55
|
-
const processedTrace = await ProcessedTrace.request(
|
|
56
|
-
const
|
|
142
|
+
const processedTrace = await ProcessedTrace.request(trace, context);
|
|
143
|
+
const responsivenessEvent = Responsiveness.getHighPercentileResponsiveness(processedTrace);
|
|
144
|
+
if (!responsivenessEvent) return null;
|
|
57
145
|
|
|
58
|
-
|
|
146
|
+
const interactionEvent = Responsiveness.findInteractionEvent(responsivenessEvent, trace);
|
|
147
|
+
return JSON.parse(JSON.stringify(interactionEvent));
|
|
59
148
|
}
|
|
60
149
|
}
|
|
61
150
|
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*/
|
|
6
6
|
'use strict';
|
|
7
7
|
|
|
8
|
+
const log = require('lighthouse-logger');
|
|
8
9
|
const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js');
|
|
10
|
+
const Sentry = require('../../lib/sentry.js');
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
13
|
* @fileoverview Tracks unused CSS rules.
|
|
@@ -13,21 +15,16 @@ const FRGatherer = require('../../fraggle-rock/gather/base-gatherer.js');
|
|
|
13
15
|
class CSSUsage extends FRGatherer {
|
|
14
16
|
constructor() {
|
|
15
17
|
super();
|
|
16
|
-
/** @type {
|
|
17
|
-
this.
|
|
18
|
-
/** @
|
|
19
|
-
this.
|
|
20
|
-
/** @param {LH.Crdp.CSS.StyleSheetRemovedEvent} sheet */
|
|
21
|
-
this._onStylesheetRemoved = sheet => {
|
|
22
|
-
// We can't fetch the content of removed stylesheets, so we ignore them completely.
|
|
23
|
-
const styleSheetId = sheet.styleSheetId;
|
|
24
|
-
this._stylesheets = this._stylesheets.filter(s => s.header.styleSheetId !== styleSheetId);
|
|
25
|
-
};
|
|
18
|
+
/** @type {LH.Gatherer.FRProtocolSession|undefined} */
|
|
19
|
+
this._session = undefined;
|
|
20
|
+
/** @type {Map<string, Promise<LH.Artifacts.CSSStyleSheetInfo|Error>>} */
|
|
21
|
+
this._sheetPromises = new Map();
|
|
26
22
|
/**
|
|
27
23
|
* Initialize as undefined so we can assert results are fetched.
|
|
28
24
|
* @type {LH.Crdp.CSS.RuleUsage[]|undefined}
|
|
29
25
|
*/
|
|
30
26
|
this._ruleUsage = undefined;
|
|
27
|
+
this._onStylesheetAdded = this._onStylesheetAdded.bind(this);
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
/** @type {LH.Gatherer.GathererMeta} */
|
|
@@ -35,26 +32,49 @@ class CSSUsage extends FRGatherer {
|
|
|
35
32
|
supportedModes: ['snapshot', 'timespan', 'navigation'],
|
|
36
33
|
};
|
|
37
34
|
|
|
35
|
+
/**
|
|
36
|
+
* @param {LH.Crdp.CSS.StyleSheetAddedEvent} event
|
|
37
|
+
*/
|
|
38
|
+
async _onStylesheetAdded(event) {
|
|
39
|
+
if (!this._session) throw new Error('Session not initialized');
|
|
40
|
+
const styleSheetId = event.header.styleSheetId;
|
|
41
|
+
const sheetPromise = this._session.sendCommand('CSS.getStyleSheetText', {styleSheetId})
|
|
42
|
+
.then(content => ({
|
|
43
|
+
header: event.header,
|
|
44
|
+
content: content.text,
|
|
45
|
+
}))
|
|
46
|
+
.catch(/** @param {Error} err */ (err) => {
|
|
47
|
+
log.warn(
|
|
48
|
+
'CSSUsage',
|
|
49
|
+
`Error fetching content of stylesheet with URL "${event.header.sourceURL}"`
|
|
50
|
+
);
|
|
51
|
+
Sentry.captureException(err, {
|
|
52
|
+
tags: {
|
|
53
|
+
gatherer: this.name,
|
|
54
|
+
},
|
|
55
|
+
extra: {
|
|
56
|
+
url: event.header.sourceURL,
|
|
57
|
+
},
|
|
58
|
+
level: 'error',
|
|
59
|
+
});
|
|
60
|
+
return err;
|
|
61
|
+
});
|
|
62
|
+
this._sheetPromises.set(styleSheetId, sheetPromise);
|
|
63
|
+
}
|
|
64
|
+
|
|
38
65
|
/**
|
|
39
66
|
* @param {LH.Gatherer.FRTransitionalContext} context
|
|
40
67
|
*/
|
|
41
68
|
async startCSSUsageTracking(context) {
|
|
42
69
|
const session = context.driver.defaultSession;
|
|
70
|
+
this._session = session;
|
|
43
71
|
session.on('CSS.styleSheetAdded', this._onStylesheetAdded);
|
|
44
|
-
session.on('CSS.styleSheetRemoved', this._onStylesheetRemoved);
|
|
45
72
|
|
|
46
73
|
await session.sendCommand('DOM.enable');
|
|
47
74
|
await session.sendCommand('CSS.enable');
|
|
48
75
|
await session.sendCommand('CSS.startRuleUsageTracking');
|
|
49
76
|
}
|
|
50
77
|
|
|
51
|
-
/**
|
|
52
|
-
* @param {LH.Gatherer.FRTransitionalContext} context
|
|
53
|
-
*/
|
|
54
|
-
async startInstrumentation(context) {
|
|
55
|
-
if (context.gatherMode !== 'timespan') return;
|
|
56
|
-
await this.startCSSUsageTracking(context);
|
|
57
|
-
}
|
|
58
78
|
|
|
59
79
|
/**
|
|
60
80
|
* @param {LH.Gatherer.FRTransitionalContext} context
|
|
@@ -64,7 +84,14 @@ class CSSUsage extends FRGatherer {
|
|
|
64
84
|
const coverageResponse = await session.sendCommand('CSS.stopRuleUsageTracking');
|
|
65
85
|
this._ruleUsage = coverageResponse.ruleUsage;
|
|
66
86
|
session.off('CSS.styleSheetAdded', this._onStylesheetAdded);
|
|
67
|
-
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @param {LH.Gatherer.FRTransitionalContext} context
|
|
91
|
+
*/
|
|
92
|
+
async startInstrumentation(context) {
|
|
93
|
+
if (context.gatherMode !== 'timespan') return;
|
|
94
|
+
await this.startCSSUsageTracking(context);
|
|
68
95
|
}
|
|
69
96
|
|
|
70
97
|
/**
|
|
@@ -93,25 +120,23 @@ class CSSUsage extends FRGatherer {
|
|
|
93
120
|
await this.stopCSSUsageTracking(context);
|
|
94
121
|
}
|
|
95
122
|
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
/** @type {Map<string, LH.Artifacts.CSSStyleSheetInfo>} */
|
|
124
|
+
const dedupedStylesheets = new Map();
|
|
125
|
+
const sheets = await Promise.all(this._sheetPromises.values());
|
|
126
|
+
|
|
127
|
+
for (const sheet of sheets) {
|
|
128
|
+
// Erroneous sheets will be reported via sentry and the log.
|
|
129
|
+
// We can ignore them here without throwing a fatal error.
|
|
130
|
+
if (sheet instanceof Error) {
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
dedupedStylesheets.set(sheet.content, sheet);
|
|
135
|
+
}
|
|
107
136
|
|
|
108
137
|
await session.sendCommand('CSS.disable');
|
|
109
138
|
await session.sendCommand('DOM.disable');
|
|
110
139
|
|
|
111
|
-
const dedupedStylesheets = new Map(styleSheetInfo.map(sheet => {
|
|
112
|
-
return [sheet.content, sheet];
|
|
113
|
-
}));
|
|
114
|
-
|
|
115
140
|
if (!this._ruleUsage) throw new Error('Issue collecting rule usages');
|
|
116
141
|
|
|
117
142
|
return {
|
package/package.json
CHANGED
|
@@ -46,6 +46,8 @@ export class PerformanceCategoryRenderer extends CategoryRenderer {
|
|
|
46
46
|
valueEl.textContent = 'Error!';
|
|
47
47
|
const tooltip = this.dom.createChildOf(descriptionEl, 'span');
|
|
48
48
|
tooltip.textContent = audit.result.errorMessage || 'Report error: no metric information';
|
|
49
|
+
} else if (audit.result.scoreDisplayMode === 'notApplicable') {
|
|
50
|
+
valueEl.textContent = '--';
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
return element;
|
|
@@ -77,6 +77,26 @@ describe('PerfCategoryRenderer', () => {
|
|
|
77
77
|
);
|
|
78
78
|
});
|
|
79
79
|
|
|
80
|
+
it('renders notApplicable metrics with n/a text', () => {
|
|
81
|
+
const perfWithNaMetric = JSON.parse(JSON.stringify(category));
|
|
82
|
+
const tbt = perfWithNaMetric.auditRefs.find(audit => audit.id === 'total-blocking-time');
|
|
83
|
+
assert(tbt);
|
|
84
|
+
const {id, title, description} = tbt.result;
|
|
85
|
+
tbt.result = {
|
|
86
|
+
id,
|
|
87
|
+
title,
|
|
88
|
+
description,
|
|
89
|
+
scoreDisplayMode: 'notApplicable',
|
|
90
|
+
score: null,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const perfDom = renderer.render(perfWithNaMetric, sampleResults.categoryGroups);
|
|
94
|
+
const tbtElement = perfDom.querySelector('.lh-metric#total-blocking-time');
|
|
95
|
+
assert(tbtElement);
|
|
96
|
+
assert.equal(tbtElement.querySelector('.lh-metric__title').textContent, 'Total Blocking Time');
|
|
97
|
+
assert.equal(tbtElement.querySelector('.lh-metric__value').textContent, '--');
|
|
98
|
+
});
|
|
99
|
+
|
|
80
100
|
it('does not render metrics section if no metric group audits', () => {
|
|
81
101
|
// Remove metrics from category
|
|
82
102
|
const newCategory = JSON.parse(JSON.stringify(category));
|
package/types/artifacts.d.ts
CHANGED
|
@@ -1002,6 +1002,7 @@ export interface TraceEvent {
|
|
|
1002
1002
|
/** Responsiveness data. */
|
|
1003
1003
|
interactionType?: 'drag'|'keyboard'|'tapOrClick';
|
|
1004
1004
|
maxDuration?: number;
|
|
1005
|
+
type?: string;
|
|
1005
1006
|
};
|
|
1006
1007
|
frame?: string;
|
|
1007
1008
|
name?: string;
|
|
@@ -1035,6 +1036,23 @@ declare module Trace {
|
|
|
1035
1036
|
tdur: number;
|
|
1036
1037
|
tts: number;
|
|
1037
1038
|
}
|
|
1039
|
+
|
|
1040
|
+
/**
|
|
1041
|
+
* Base event of a `ph: 'b'|'e'|'n'` async event. Extend with `name`, `args`, and
|
|
1042
|
+
* more specific `ph` (if needed).
|
|
1043
|
+
*/
|
|
1044
|
+
interface AsyncEvent {
|
|
1045
|
+
ph: 'b'|'e'|'n';
|
|
1046
|
+
cat: string;
|
|
1047
|
+
pid: number;
|
|
1048
|
+
tid: number;
|
|
1049
|
+
ts: number;
|
|
1050
|
+
id: string;
|
|
1051
|
+
scope?: string;
|
|
1052
|
+
// TODO(bckenny): No dur on these. Sort out optional `dur` on trace events.
|
|
1053
|
+
/** @deprecated there is no `dur` on async events. */
|
|
1054
|
+
dur: number;
|
|
1055
|
+
}
|
|
1038
1056
|
}
|
|
1039
1057
|
|
|
1040
1058
|
/**
|