Skip to content

Commit

Permalink
[soft navigations] Add PerfObserver option for softnav triggered entries
Browse files Browse the repository at this point in the history
FP, FCP and LCP entries that are triggered by soft navigations could
confuse existing RUM scripts that may not be aware of them.
See WICG/soft-navigations#11

This CL adds and opt-in option to only report these entries when the
observer explicitly asks for them.

Bug: 1413691
Change-Id: I6809973b88ed987f6ca08fbb9546d4a8f654c3fc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4230572
Reviewed-by: Ian Clelland <[email protected]>
Commit-Queue: Yoav Weiss <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1103256}
  • Loading branch information
Yoav Weiss authored and chromium-wpt-export-bot committed Feb 9, 2023
1 parent c16c26f commit 98a96d4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
extraValidations: async (entries, options)=>{
const paint_entries = await new Promise(resolve => {
new PerformanceObserver(list => resolve(list.getEntries())).observe(
{type: 'paint', buffered: true});
{type: 'paint', buffered: true,
includeSoftNavigationObservations: true});
});
assert_equals(paint_entries.length, 10);
},
Expand Down
24 changes: 23 additions & 1 deletion soft-navigation-heuristics/resources/soft-navigation-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ const runEntryValidations = async preClickLcp => {
validatePaintEntries('first-contentful-paint');
validatePaintEntries('first-paint');
const postClickLcp = await getLcpEntries();
const postClickLcpWithoutSoftNavs = await getLcpEntriesWithoutSoftNavs();
assert_greater_than(
postClickLcp.length, preClickLcp.length,
'Soft navigation should have triggered at least an LCP entry');
assert_equals(
postClickLcpWithoutSoftNavs.length, preClickLcp.length,
'Soft navigation should not have triggered an LCP entry when the ' +
'observer did not opt in');
assert_not_equals(
postClickLcp[postClickLcp.length - 1].size,
preClickLcp[preClickLcp.length - 1].size,
Expand Down Expand Up @@ -172,6 +177,11 @@ const validateSoftNavigationEntry = async (clicks, extraValidations,

const validatePaintEntries = async (type, entries_number = 2) => {
const entries = await new Promise(resolve => {
(new PerformanceObserver(list => resolve(
list.getEntriesByName(type)))).observe(
{type: 'paint', buffered: true, includeSoftNavigationObservations: true});
});
const entries_without_softnavs = await new Promise(resolve => {
(new PerformanceObserver(list => resolve(
list.getEntriesByName(type)))).observe(
{type: 'paint', buffered: true});
Expand All @@ -181,13 +191,25 @@ const validatePaintEntries = async (type, entries_number = 2) => {
// required clicks, instead of counting on double rAF.
assert_equals(entries.length, entries_number,
`There are ${entries_number} entries for ${type}`);
assert_equals(entries_without_softnavs.length, 1,
`There is one non-softnav entry for ${type}`);
if (entries_number > 1) {
assert_not_equals(entries[0].startTime, entries[1].startTime,
"Entries have different timestamps for " + type);
}
};

const getLcpEntries = async () => {
const entries = await new Promise(resolve => {
(new PerformanceObserver(list => resolve(
list.getEntries()))).observe(
{type: 'largest-contentful-paint', buffered: true,
includeSoftNavigationObservations: true});
});
return entries;
};

const getLcpEntriesWithoutSoftNavs = async () => {
const entries = await new Promise(resolve => {
(new PerformanceObserver(list => resolve(
list.getEntries()))).observe(
Expand Down Expand Up @@ -229,6 +251,6 @@ const waitOnPaintEntriesPromise = () => {
} else if (paint_entries.length > 2) {
reject();
}
}).observe({type: 'paint'});
}).observe({type: 'paint', includeSoftNavigationObservations: true});
});
};

0 comments on commit 98a96d4

Please sign in to comment.