-
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
Merged
new_audit: bf-cache #14465
Changes from all commits
Commits
Show all changes
63 commits
Select commit
Hold shift + click to select a range
69b34b6
WIP: bfcache audit
adamraine 648f72e
ope
adamraine c25b196
smoke fix
adamraine 29352f2
ope
adamraine b89df49
comments
adamraine 111abd4
tree
adamraine d2db291
organize results in artifact
adamraine 7a669a0
all types
adamraine 795593f
passive flow
adamraine 4e4138a
Merge branch 'main' into bf-cache
adamraine e4aa601
semi
adamraine 8aac07f
Merge branch 'main' into bf-cache
adamraine 892eb53
Merge branch 'main' into bf-cache
adamraine 14dfafe
update
adamraine eacc071
nit
adamraine c74bcad
strings
adamraine 71bd779
smoke test
adamraine f1dd41a
ope
adamraine fc67719
ope
adamraine c866560
sample
adamraine 005eabd
snap
adamraine b36a3d4
fix
adamraine 209995c
ope
adamraine c959bd5
Merge branch 'main' into bf-cache
adamraine 92b9c99
Merge branch 'main' into bf-cache
adamraine 3afa9c2
artifacts
adamraine f320249
unit
adamraine cf751ef
strings
adamraine d74cb5e
test
adamraine 3bc53b1
Merge branch 'main' into bf-cache
adamraine 47f8a46
sort
adamraine eb2f032
bfcache
adamraine 442c231
comments
adamraine b6aba19
types
adamraine 27b096e
- and sample
adamraine f1122e3
dedupe
adamraine 6a58cbd
Update core/audits/bf-cache.js
adamraine c245ee6
hidden thing
adamraine 1e453a7
smoke
adamraine 919e51f
Merge branch 'main' into bf-cache
adamraine be1cb7c
sample
adamraine a2c428a
stable check
adamraine fe5eacc
Merge branch 'main' into bf-cache
adamraine 9f7c944
rm old
adamraine 99902fd
dt e2e
adamraine 5354cbe
test
adamraine 922bf49
fail on any failure
adamraine 99aa1bc
reorder
adamraine 3e489dc
dt
adamraine 5168bcf
Merge branch 'main' into bf-cache
adamraine 80f5672
expectation
adamraine c011ba0
Merge branch 'main' into bf-cache
adamraine e528638
use passive
adamraine 4caf208
tests
adamraine b389d38
ensure event emitted
adamraine 21b2347
test
adamraine 59d2aa5
bump cache
adamraine 224e675
test
adamraine 9f88317
simpler
adamraine 76a16d8
e2e debug
adamraine 8677704
comment
adamraine 9b130b9
longer timeout
adamraine 50fcdba
fix
adamraine File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,120 @@ | ||||||
/** | ||||||
* @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/bf-cache-strings.js'; | ||||||
|
||||||
/* eslint-disable max-len */ | ||||||
const UIStrings = { | ||||||
/** Title of a diagnostic Lighthouse audit that identifies when the back/forward cache is being used. "back/forward" refers to the back and forward buttons found in modern browsers. This title is shown to users if the back/forward cache was used, or if the there was no attempt to restore the page from the back/forward cache. */ | ||||||
title: `Page didn't prevent back/forward cache restoration`, | ||||||
connorjclark marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
/** Title of a diagnostic Lighthouse audit that identifies when the back/forward cache is being used. "back/forward" refers to the back and forward buttons found in modern browsers. This title is shown to users if the page attempted to restore from the back/forward cache but the back/forward cache was not used. */ | ||||||
failureTitle: 'Page prevented back/forward cache restoration', | ||||||
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.
Suggested change
|
||||||
/** Description of a diagnostic Lighthouse audit that identifies when the back/forward cache is being used. "back/forward" refers to the back and forward buttons found in modern browsers. */ | ||||||
description: 'Many navigations are performed by going back to a previous page, or forwards again. The back/forward cache (bfcache) can speed up these return navigations. [Learn more about the bfcache](https://web.dev/bfcache/)', | ||||||
/** Failure type for an error that the user should be able to address themselves. Shown in a table column with other failure types. */ | ||||||
actionableFailureType: 'Actionable', | ||||||
/** Failure type for an error that the user cannot address in the page's code. Shown in a table column with other failure types. */ | ||||||
notActionableFailureType: 'Not actionable', | ||||||
/** Failure type for an error caused by missing browser support. Shown in a table column with other failure types. */ | ||||||
supportPendingFailureType: 'Pending browser support', | ||||||
/** Label for a column in a data table; entries in the column will be a string explaining why a failure occurred. */ | ||||||
failureReasonColumn: 'Failure reason', | ||||||
/** Label for a column in a data table; entries in the column will be a string representing the type of failure preventing the back/forward cache from being used. */ | ||||||
failureTypeColumn: 'Failure type', | ||||||
/** | ||||||
* @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 failure reason} | ||||||
other {# failure reasons} | ||||||
}`, | ||||||
}; | ||||||
/* eslint-enable max-len */ | ||||||
|
||||||
const str_ = i18n.createIcuMessageFn(import.meta.url, UIStrings); | ||||||
|
||||||
/** @type {LH.Crdp.Page.BackForwardCacheNotRestoredReasonType[]} */ | ||||||
const ORDERED_FAILURE_TYPES = ['PageSupportNeeded', 'SupportPending', 'Circumstantial']; | ||||||
|
||||||
/** @type {Record<LH.Crdp.Page.BackForwardCacheNotRestoredReasonType, string | LH.IcuMessage>} */ | ||||||
const FAILURE_TYPE_TO_STRING = { | ||||||
PageSupportNeeded: str_(UIStrings.actionableFailureType), | ||||||
Circumstantial: str_(UIStrings.notActionableFailureType), | ||||||
SupportPending: str_(UIStrings.supportPendingFailureType), | ||||||
}; | ||||||
|
||||||
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: ['BFCacheFailures'], | ||||||
}; | ||||||
} | ||||||
|
||||||
/** | ||||||
* @param {LH.Artifacts} artifacts | ||||||
* @return {Promise<LH.Audit.Product>} | ||||||
*/ | ||||||
static async audit(artifacts) { | ||||||
const failures = artifacts.BFCacheFailures; | ||||||
if (!failures.length) return {score: 1}; | ||||||
|
||||||
// TODO: Analyze more than one bf cache failure. | ||||||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
const {notRestoredReasonsTree} = failures[0]; | ||||||
|
||||||
/** @type {LH.Audit.Details.TableItem[]} */ | ||||||
const results = []; | ||||||
|
||||||
for (const failureType of ORDERED_FAILURE_TYPES) { | ||||||
const reasonsMap = notRestoredReasonsTree[failureType]; | ||||||
|
||||||
for (const [reason, frameUrls] of Object.entries(reasonsMap)) { | ||||||
results.push({ | ||||||
reason: NotRestoredReasonDescription[reason]?.name ?? reason, | ||||||
failureType: FAILURE_TYPE_TO_STRING[failureType], | ||||||
subItems: { | ||||||
type: 'subitems', | ||||||
items: frameUrls.map(frameUrl => ({frameUrl})), | ||||||
}, | ||||||
adamraine marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
// Include hidden protocol reason code for debugging. | ||||||
protocolReason: reason, | ||||||
}); | ||||||
} | ||||||
} | ||||||
|
||||||
/** @type {LH.Audit.Details.Table['headings']} */ | ||||||
const headings = [ | ||||||
/* eslint-disable max-len */ | ||||||
{key: 'reason', valueType: 'text', subItemsHeading: {key: 'frameUrl', valueType: 'url'}, label: str_(UIStrings.failureReasonColumn)}, | ||||||
{key: 'failureType', valueType: 'text', label: str_(UIStrings.failureTypeColumn)}, | ||||||
/* eslint-enable max-len */ | ||||||
]; | ||||||
|
||||||
const details = Audit.makeTableDetails(headings, results); | ||||||
|
||||||
const displayValue = results.length ? | ||||||
str_(UIStrings.displayValue, {itemCount: results.length}) : | ||||||
undefined; | ||||||
|
||||||
return { | ||||||
score: results.length ? 0 : 1, | ||||||
displayValue, | ||||||
details, | ||||||
}; | ||||||
} | ||||||
} | ||||||
|
||||||
export default BFCache; | ||||||
export {UIStrings}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,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.BFCacheFailures, gatherer: 'bf-cache-failures'}, | ||
], | ||
audits: [ | ||
'is-on-https', | ||
|
@@ -374,6 +377,7 @@ const defaultConfig = { | |
'seo/canonical', | ||
'seo/manual/structured-data', | ||
'work-during-interaction', | ||
'bf-cache', | ||
], | ||
groups: { | ||
'metrics': { | ||
|
@@ -516,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'}, | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.