Skip to content

LCP is never reported when a page is opened in a background tab #1926

@westonruter

Description

@westonruter

Bug Description

I just noticed in Chrome that when I open a link in a new tab (in the background), the callback passed to onLCP() in web-vitals.js is never invoked, this causes the detection logic to await indefinitely at:

// Obtain at least one LCP candidate. More may be reported before the page finishes loading.
await new Promise( ( resolve ) => {
onLCP(
/**
* Handles an LCP metric being reported.
*
* @param {LCPMetric|LCPMetricWithAttribution} metric
*/
( metric ) => {
lcpMetricCandidates.push( metric );
resolve();
},
{
// This avoids needing to click to finalize LCP candidate. While this is helpful for testing, it also
// ensures that we always get an LCP candidate reported. Otherwise, the callback may never fire if the
// user never does a click or keydown, per <https://github.com/GoogleChrome/web-vitals/blob/07f6f96/src/onLCP.ts#L99-L107>.
reportAllChanges: true,
}
);
} );

I wonder if this is an intentional behavior for browsers to not report LCP in this situation.

Steps to reproduce

  1. Enable WP_DEBUG
  2. Click a link to open a page in a new tab (in the backgroind)
  3. Open the tab
  4. See that the last log entry is "Proceeding with detection", whereas it is expected last log entry after the page load is "Current URL Metric".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    Status

    Done 😃

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions