Skip to content

feat(plugin-autocapture-browser): add Min Page Y to viewport content updated - #2023

Open
jxiwang wants to merge 6 commits into
mainfrom
cursor/viewport-min-page-y-53bb
Open

jxiwang wants to merge 6 commits into
mainfrom
cursor/viewport-min-page-y-53bb

Conversation

@jxiwang

@jxiwang jxiwang commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Adds [Amplitude] Min Page Y to [Amplitude] Viewport Content Updated so we can see where viewport tracking started. Linear: ZON-101.

[Amplitude] Max Page Y is the bottom of the furthest viewport (max scrollY + viewport height). Min Page Y is the top of the highest viewport seen since tracking began for the current page view: the smallest window.scrollY, including the offset at the moment the scroll tracker attaches. A non-zero value on the first event of a page view means the SDK started below the top of the page (late script injection, consent gating, scroll restoration, or a hash navigation).

The tracker also seeds max scroll from that same initial sample. Previously max stayed 0 until the next scroll event, so a late load under-reported [Amplitude] Max Page Y as only the viewport height.

On a new page view the range resets, then re-seeds once history has been applied (pushState / replaceState) or after popstate. Navigation API traversals wait for navigatesuccess, which runs after the browser restores scroll. Sampling inside the navigate handler copied the previous page's offset into the new page's Min and Max Page Y. An exposure snapshot that finishes before navigatesuccess waits for that sample, so a long intercept does not flush Min and Max Page Y as 0. If the navigation fails or is cancelled, navigateerror or the navigate event's abort signal releases that wait and samples the offset the page is still at. A change in the minimum flushes on the next Viewport Content Updated trigger, including page end.

The viewport exposure harness (test-server/autocapture/viewport-exposure.html) can defer SDK startup with ?deferInit=1. The Playwright spec scrolls before start(), then down and back up, and checks the sent Min Page Y and Max Page Y against those scroll positions. The same range is shown on the page.

Later checks lock the late-load cases the first spec did not:

  • No scroll after attach: the first event's Min Page Y and the scroll component of Max Page Y are the offset where the SDK attached.
  • Scrolling only upward after attach keeps Max Page Y at that offset.
  • Movement from before the SDK attached is not reconstructed. A peak the visitor reached and left before init is absent, and a zone that was on screen then scrolled above the viewport is not backfilled into [Amplitude] Element Exposed.
  • popstate re-seeds from the scroll position the browser has already restored, instead of carrying the previous page's max forward.
  • A Navigation API traversal re-seeds from the scroll position restored before navigatesuccess. A scroll event that arrives before that success is the new page's baseline, not an extension of the previous page's max. A snapshot that finishes first waits for that success instead of sending 0. A failed or aborted navigation releases the same wait.

Checklist

  • Does your PR title have the correct title format?
  • Does your PR have a breaking change?: No
Open in Web Open in Cursor 

…updated

Record the highest viewport top seen since tracking started, including the
scroll offset at attach time, so a late SDK load is visible on
[Amplitude] Viewport Content Updated.
@linear-code

linear-code Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

SDK-355

@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
packages/analytics-browser/lib/scripts/amplitude-min.js.gz 66.96 KB (+0.57% 🔺)
packages/session-replay-browser/lib/scripts/session-replay-browser-min.js.gz 135.88 KB (0%)
packages/unified/lib/scripts/amplitude-min.umd.js.gz 221.34 KB (+0.17% 🔺)
@amplitude/element-selector (gzipped esm) 3.48 KB (0%)

… harness

Scroll the viewport exposure page before the SDK starts, then check that
the sent Min and Max Page Y match the scroll range the browser actually reached.
…ontent updated

The Min Page Y checks scrolled again after the SDK attached, so a tracker
that ignored the position at attach still passed. Lock the late-load cases:
the attach offset is the range when nothing moves afterward, movement from
before init is not reconstructed, and popstate re-seeds from the restored
scroll position.
@jxiwang
jxiwang marked this pull request as ready for review October 1, 2026 23:03
@jxiwang
jxiwang requested a review from a team as a code owner October 1, 2026 23:03

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/plugin-autocapture-browser/src/autocapture-plugin.ts Outdated
…toration

The navigate event fires before a back/forward traversal restores scroll.
Sampling there copied the previous page's offset into the new page's Min
and Max Page Y. Sample on navigatesuccess, after that restoration.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread packages/plugin-autocapture-browser/src/autocapture-plugin.ts Outdated
…ion scroll is restored

An exposure snapshot that finishes during an intercepted navigation waits
for navigatesuccess, so Min and Max Page Y use the restored offset.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit caa6f69. Configure here.

Comment thread packages/plugin-autocapture-browser/src/autocapture-plugin.ts
…ion fails

navigateerror and an aborted navigate signal sample the current offset and
send a snapshot that was waiting on navigatesuccess.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants