日本語

Core Web Vitals LCP Stops Recording When the User Scrolls

​​Core Web Vitals​Chrome,JavaScript,Playwright,web-vitals

The Largest Contentful Paint (LCP) in Core Web Vitals stops recording once the user scrolls. In my test environment, I opened a page and scrolled with the mouse wheel about 1 second later. The hero image, which appeared at about 2 seconds, was not counted as LCP. Instead, LCP became 56ms, the value of an earlier paragraph (median of 5 runs). Without scrolling, LCP is the image's 2028ms. This article is for cases where the LCP collected with web-vitals is much smaller than the value measured by just waiting on the page, or where a slow-loading hero image never shows up as LCP, so you can check the cause.

Note

The test environment was Ubuntu 24.04, Node.js 22, web-vitals 6.2.3, and Chromium 157 (headless) from Playwright 1.63.0. The page was served from a server I ran at localhost:8080, with a 412px by 823px viewport, and each operation was measured 5 times. Wheel and keyboard input used Playwright's page.mouse and page.keyboard. For finger-swipe scrolling, I sent Chrome DevTools Protocol touch events to a viewport with touch enabled. I did not test real phones, scrollbar dragging, navigation with in-page links, Lighthouse, real-user data (CrUX, PageSpeed Insights field data), or browsers other than Chrome.

The official explanation and the page used for the test

The web.dev LCP article says that once the user interacts with the page (tap, scroll, or key press), the browser stops emitting new LCP entries. It recommends that analysis use only the last entry that was emitted.

To verify this, I prepared a page with a heading, a hero image, a description paragraph, and 40 paragraphs. The server delays the image by 2000ms, so the paragraphs appear first and the image appears later.

html
<h1>今週のおすすめ</h1>
<img id="hero" src="hero.png" alt="おすすめの商品" width="800" height="600">
<p>商品の説明が入る段落です。</p>
<div id="filler"></div><!-- Add 40 paragraphs here with a script so the page is long enough to scroll. -->

On the page, I collected largest-contentful-paint entries with PerformanceObserver. I also loaded the web-vitals attribution build and sent each onLCP report (the value and attribution.target, which identifies the element that became LCP) to the server with navigator.sendBeacon. I performed the operation about 1000ms after the page opened, waited until 4000ms, then read the entries. After that, I navigated to a different page (about:blank) and received the web-vitals reports on the server. The command output below shows only the first of the 5 runs.

When scrolling with the wheel, the image that appeared later was not counted

First, the case with no action. In all 5 runs, there were two entries: the paragraph (about 50ms) and the hero image (2024ms to 2036ms). The web-vitals LCP was the image's value.

console
$ node measure.cjs none 5
none run1: 操作した時刻=— 届いた入力=なし scrollY=0 画像の読み込み=済み
  LCPのエントリ: p(52ms,size=3570) #hero(2032ms,size=108300)
  web-vitals の報告: LCP=2032 target=#hero 報告の時刻=4013ms

Next, at about 1000ms, I scrolled 100px with the wheel. The image finished loading afterward (complete was true), but in all 5 runs no image entry arrived, and LCP was the paragraph's value (28ms to 60ms, median 56ms).

console
$ node measure.cjs wheel 5
wheel run1: 操作した時刻=1013ms 届いた入力=mousemove,wheel,scroll scrollY=100 画像の読み込み=済み
  LCPのエントリ: p(60ms,size=3570)
  web-vitals の報告: LCP=60 target=html>body>p 報告の時刻=4023ms

size is the on-screen visible area of the element. As the next section shows, most of the image was still visible after the same 100px scroll. Even so, it was not counted.

Scrolling with scrollTo() alone did not stop recording

I moved the page by the same 100px using the script's window.scrollTo(0, 100) instead of the wheel. A scroll event arrived and scrollY became 100. Recording still did not stop: in all 5 runs, the image entry arrived, and LCP was the image's value (median 2028ms).

console
$ node measure.cjs script-scroll 5
script-scroll run1: 操作した時刻=1004ms 届いた入力=scroll scrollY=100 画像の読み込み=済み
  LCPのエントリ: p(60ms,size=3570) #hero(2032ms,size=91200)
  web-vitals の報告: LCP=2032 target=#hero 報告の時刻=4021ms

The image's size was 91200, smaller than the 108300 in the no-action case. The part that moved off the top of the screen is not included in the area. These results show that what stopped recording was not the change in scroll position but the user's wheel input.

Stopped with a wheel even without scrolling, but not by moving the mouse alone

I also tried turning the wheel on a page too short to scroll. scrollY stayed at 0 and no scroll event fired. Still, in all 5 runs no image entry arrived, and LCP was the paragraph's value (median 52ms).

console
$ node measure.cjs wheel-short 5
wheel-short run1: 操作した時刻=1010ms 届いた入力=mousemove,wheel scrollY=0 画像の読み込み=済み
  LCPのエントリ: p(64ms,size=3570)
  web-vitals の報告: LCP=64 target=html>body>p 報告の時刻=4017ms

On the other hand, moving the mouse over the screen alone (an operation where only mousemove arrived) did not stop recording. In all 5 runs the image entry arrived, and LCP was the image's value (median 2028ms).

Finger-swipe scrolling and scrolling with the PageDown key also did not count the image in all 5 runs. LCP was the paragraph's value in both cases: median 56ms for finger swipes and median 48ms for PageDown.

Horizontal bar chart comparing LCP for each operation. No action, mouse movement only, and scrollTo() scrolling show the image at 2028ms. Wheel scrolling and finger-swipe scrolling show 56ms, PageDown shows 48ms, and wheel on a non-scrollable page shows 52ms, all still the paragraph
LCP for each operation (median of 5 runs). Images that appeared after wheel, finger, or key input were not counted as LCP

The time web-vitals reports differed between keys and scrolling

Apart from the LCP value, there was also a difference in when web-vitals called the onLCP callback. With PageDown, the report arrived right after the operation (1008ms to 1021ms). With wheel or finger scrolling, the report did not arrive until the page was left (4010ms to 4023ms), even though recording had already stopped.

console
$ node measure.cjs pagedown 5
pagedown run1: 操作した時刻=1013ms 届いた入力=keydown,scroll scrollY=720 画像の読み込み=済み
  LCPのエントリ: p(48ms,size=3570)
  web-vitals の報告: LCP=48 target=html>body>p 報告の時刻=1021ms

In the web-vitals 6.2.3 source code (src/onLCP.ts), the events that finalize the report are keydown, click, and visibilitychange. scroll is not among them. A comment in the code says scrolling can also be triggered by scripts, so it is not reliable. The background is in web-vitals issue #75, which explains that because there is no reliable way to tell scrolls caused by the user apart from others, scrolling was not chosen to finalize the report.

Delayed reporting does not change the value. In the scroll cases, the paragraph's value was still reported when the page was left. The web-vitals README also says that the last reported value is the same whether or not reportAllChanges is used.

Point

For users who scroll with the wheel, finger, or keys right after the page opens, LCP is decided by the elements shown before the scroll. In this test, even with a 2-second image, the reported LCP for scrolling was 56ms. If you look only at LCP collected with web-vitals, you cannot see how slow the large image that appears later is.

​Posted by 86