-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new_audit: bf-cache #14465
new_audit: bf-cache #14465
Changes from 10 commits
69b34b6
648f72e
c25b196
29352f2
b89df49
111abd4
d2db291
7a669a0
795593f
4e4138a
e4aa601
8aac07f
892eb53
14dfafe
eacc071
c74bcad
71bd779
f1dd41a
fc67719
c866560
005eabd
b36a3d4
209995c
c959bd5
92b9c99
3afa9c2
f320249
cf751ef
d74cb5e
3bc53b1
47f8a46
eb2f032
442c231
b6aba19
27b096e
f1122e3
6a58cbd
c245ee6
1e453a7
919e51f
be1cb7c
a2c428a
fe5eacc
9f7c944
99902fd
5354cbe
922bf49
99aa1bc
3e489dc
5168bcf
80f5672
c011ba0
e528638
4caf208
b389d38
21b2347
59d2aa5
224e675
9f88317
76a16d8
8677704
9b130b9
50fcdba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/** | ||
* @license Copyright 2022 The Lighthouse Authors. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
import {Audit} from './audit.js'; | ||
import * as i18n from '../lib/i18n/i18n.js'; | ||
import {NotRestoredReasonDescription} from '../lib/bfcache-strings.js'; | ||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* eslint-disable max-len */ | ||
const UIStrings = { | ||
/** TODO */ | ||
title: 'Back/forward cache is used', | ||
/** TODO */ | ||
failureTitle: 'Back/forward cache is not used', | ||
/** TODO */ | ||
description: 'The back/forward cache can speed up the page load after navigating away.', | ||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** TODO */ | ||
actionableColumn: 'Actionable failure', | ||
/** TODO */ | ||
notActionableColumn: 'Not actionable failure', | ||
/** TODO */ | ||
supportPendingColumn: 'Pending browser support', | ||
/** | ||
* @description [ICU Syntax] Label for an audit identifying the number of back/forward cache failure reasons found in the page. | ||
*/ | ||
displayValue: `{itemCount, plural, | ||
=1 {1 actionable failure reason} | ||
other {# actionable failure reasons} | ||
}`, | ||
}; | ||
/* eslint-enable max-len */ | ||
|
||
const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings); | ||
|
||
class BFCache extends Audit { | ||
/** | ||
* @return {LH.Audit.Meta} | ||
*/ | ||
static get meta() { | ||
return { | ||
id: 'bf-cache', | ||
title: str_(UIStrings.title), | ||
failureTitle: str_(UIStrings.failureTitle), | ||
description: str_(UIStrings.description), | ||
supportedModes: ['navigation', 'timespan'], | ||
requiredArtifacts: ['BFCacheErrors'], | ||
}; | ||
} | ||
|
||
/** | ||
* @param {LH.Crdp.Page.BackForwardCacheNotRestoredReason} reason | ||
*/ | ||
static getDescriptionForReason(reason) { | ||
const matchingString = NotRestoredReasonDescription[reason]; | ||
|
||
if (matchingString === undefined) { | ||
return reason; | ||
} | ||
|
||
return matchingString.name; | ||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* @param {LH.Artifacts.BFCacheErrorMap} errors | ||
* @param {LH.IcuMessage | string} label | ||
* @return {LH.Audit.Details.Table} | ||
*/ | ||
static makeTableForFailureType(errors, label) { | ||
/** @type {LH.Audit.Details.TableItem[]} */ | ||
const results = []; | ||
|
||
// https://github.com/Microsoft/TypeScript/issues/12870 | ||
const reasons = /** @type {LH.Crdp.Page.BackForwardCacheNotRestoredReason[]} */ | ||
(Object.keys(errors)); | ||
|
||
for (const reason of reasons) { | ||
const frameUrls = errors[reason] || []; | ||
results.push({ | ||
reason: this.getDescriptionForReason(reason), | ||
subItems: { | ||
type: 'subitems', | ||
items: frameUrls.map(frameUrl => ({frameUrl})), | ||
}, | ||
}); | ||
} | ||
|
||
/** @type {LH.Audit.Details.Table['headings']} */ | ||
const headings = [ | ||
/* eslint-disable max-len */ | ||
{key: 'reason', valueType: 'text', subItemsHeading: {key: 'frameUrl', valueType: 'url'}, label}, | ||
/* eslint-enable max-len */ | ||
]; | ||
|
||
return Audit.makeTableDetails(headings, results); | ||
} | ||
|
||
/** | ||
* @param {LH.Artifacts} artifacts | ||
* @return {Promise<LH.Audit.Product>} | ||
*/ | ||
static async audit(artifacts) { | ||
const {PageSupportNeeded, SupportPending, Circumstantial} = artifacts.BFCacheErrors; | ||
|
||
const actionableTable = | ||
this.makeTableForFailureType(PageSupportNeeded, str_(UIStrings.actionableColumn)); | ||
const notActionableTable = | ||
this.makeTableForFailureType(Circumstantial, str_(UIStrings.notActionableColumn)); | ||
const supportPendingTable = | ||
this.makeTableForFailureType(SupportPending, str_(UIStrings.supportPendingColumn)); | ||
|
||
const items = [ | ||
actionableTable, | ||
notActionableTable, | ||
supportPendingTable, | ||
]; | ||
|
||
if (actionableTable.items.length === 0) { | ||
return { | ||
score: 1, | ||
details: { | ||
type: 'list', | ||
items, | ||
}, | ||
}; | ||
} | ||
|
||
return { | ||
score: 0, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may want to mark n/a if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there are still actionable failures I think it's worth surfacing them |
||
displayValue: str_(UIStrings.displayValue, {itemCount: actionableTable.items.length}), | ||
details: { | ||
type: 'list', | ||
items, | ||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
}; | ||
} | ||
} | ||
|
||
export default BFCache; | ||
export {UIStrings}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,6 +128,7 @@ const artifacts = { | |
Trace: '', | ||
Accessibility: '', | ||
AnchorElements: '', | ||
BFCacheErrors: '', | ||
CacheContents: '', | ||
ConsoleMessages: '', | ||
CSSUsage: '', | ||
|
@@ -216,8 +217,11 @@ const defaultConfig = { | |
{id: artifacts.devtoolsLogs, gatherer: 'devtools-log-compat'}, | ||
{id: artifacts.traces, gatherer: 'trace-compat'}, | ||
|
||
// FullPageScreenshot comes at the very end so all other node analysis is captured. | ||
// FullPageScreenshot comes at the end so all other node analysis is captured. | ||
{id: artifacts.FullPageScreenshot, gatherer: 'full-page-screenshot'}, | ||
|
||
// BFCacheErrors comes at the very end because it can perform a page navigation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you didn't like "very very end"? :P |
||
{id: artifacts.BFCacheErrors, gatherer: 'bf-cache-errors'}, | ||
], | ||
audits: [ | ||
'is-on-https', | ||
|
@@ -373,6 +377,7 @@ const defaultConfig = { | |
'seo/canonical', | ||
'seo/manual/structured-data', | ||
'work-during-interaction', | ||
'bf-cache', | ||
], | ||
groups: { | ||
'metrics': { | ||
|
@@ -515,6 +520,7 @@ const defaultConfig = { | |
{id: 'no-unload-listeners', weight: 0}, | ||
{id: 'uses-responsive-images-snapshot', weight: 0}, | ||
{id: 'work-during-interaction', weight: 0}, | ||
{id: 'bf-cache', weight: 0}, | ||
|
||
// Budget audits. | ||
{id: 'performance-budget', weight: 0, group: 'budgets'}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should have a test-definition base config we extend from? we could also specify
only-categories: []
in it, forcing smoke configs that extend it to be more specific (I assume that works...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like overkill plus it would be confusing when writing a test to bounce between the smokehouse base config and the test specific config.
This issue is only present on a handful of tests.