From 24e3489ae72b71a3c67a962cf925405d3105e64c Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 20 Nov 2026 15:42:09 +0100 Subject: [PATCH 1/2] fix(replay): Do not report dead clicks after a bfcache restore Co-Authored-By: Claude Opus 5.5 --- .../replay/slowClick/bfcache/template.html | 15 ++++++ .../suites/replay/slowClick/bfcache/test.ts | 49 +++++++++++++++++++ .../src/coreHandlers/handleClick.ts | 11 +++++ 3 files changed, 75 insertions(+) create mode 100644 dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/template.html create mode 100644 dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts diff --git a/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/template.html b/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/template.html new file mode 100644 index 000000000000..63643282b174 --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/template.html @@ -0,0 +1,15 @@ + + + + + + + Link + + + + diff --git a/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts b/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts new file mode 100644 index 000000000000..9b7884ae052b --- /dev/null +++ b/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts @@ -0,0 +1,49 @@ +import { expect } from '@playwright/test'; +import { sentryTest } from '../../../../utils/fixtures'; +import { collectReplayRequests, getReplayBreadcrumbs, shouldSkipReplayTest } from '../../../../utils/replayHelpers'; + +// Playwright turns the bfcache off, and chrome-headless-shell does not support it +sentryTest.use({ + channel: 'chromium', + launchOptions: { ignoreDefaultArgs: ['--disable-back-forward-cache'] }, +}); + +sentryTest( + 'link click that leaves the page is not a slow click after a bfcache restore', + async ({ getLocalTestUrl, page, browserName }) => { + if (shouldSkipReplayTest() || browserName !== 'chromium') { + sentryTest.skip(); + } + + const url = await getLocalTestUrl({ testDir: __dirname }); + await page.route('**/page2.html', route => + route.fulfill({ contentType: 'text/html', body: 'Page 2' }), + ); + + await page.goto(url); + await page.waitForFunction(() => (window as any).Sentry?.getReplay()?.getReplayId()); + + const replayRequestsPromise = collectReplayRequests(page, recordingEvents => + getReplayBreadcrumbs(recordingEvents, 'ui.slowClickDetected').some( + breadcrumb => breadcrumb.message === 'body > button#noopButton', + ), + ); + + await page.locator('#link').click(); + await page.waitForURL('**/page2.html'); + // A bfcache restore fires no `load` event + await page.goBack({ waitUntil: 'commit' }); + + expect( + await page.waitForFunction(() => (window as any).restoredFromBfcache !== undefined).then(h => h.jsonValue()), + ).toBe(true); + + // A slow click that happens after the restore, so we know when the detector has had time to report + await page.locator('#noopButton').click(); + + const { replayRecordingSnapshots } = await replayRequestsPromise; + const slowClicks = getReplayBreadcrumbs(replayRecordingSnapshots, 'ui.slowClickDetected'); + + expect(slowClicks.map(breadcrumb => breadcrumb.message)).toEqual(['body > button#noopButton']); + }, +); diff --git a/packages/replay-internal/src/coreHandlers/handleClick.ts b/packages/replay-internal/src/coreHandlers/handleClick.ts index c61278494646..1b0b127acab6 100644 --- a/packages/replay-internal/src/coreHandlers/handleClick.ts +++ b/packages/replay-internal/src/coreHandlers/handleClick.ts @@ -99,8 +99,19 @@ export class ClickDetector implements ReplayClickDetector { this._lastMutation = nowInSeconds(); }); + // A click that leaves the page is not a dead click. Without this, a page restored from the + // bfcache resumes the pending check and reports the click as one. + const onPageHide = (): void => { + this._clicks = []; + if (this._checkClickTimeout) { + clearTimeout(this._checkClickTimeout); + } + }; + WINDOW.addEventListener('pagehide', onPageHide); + this._teardown = () => { cleanupWindowOpen(); + WINDOW.removeEventListener('pagehide', onPageHide); this._clicks = []; this._lastMutation = 0; From e05991419318fca43acecce1744333ffe6b60e12 Mon Sep 17 00:00:00 2001 From: Andrei Borza Date: Fri, 20 Nov 2026 16:08:51 +0100 Subject: [PATCH 2/2] Skip the bfcache test before the browser starts on WebKit and Firefox --- .../suites/replay/slowClick/bfcache/test.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts b/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts index 9b7884ae052b..9eb41a5541cd 100644 --- a/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts +++ b/dev-packages/browser-integration-tests/suites/replay/slowClick/bfcache/test.ts @@ -8,13 +8,12 @@ sentryTest.use({ launchOptions: { ignoreDefaultArgs: ['--disable-back-forward-cache'] }, }); +// Skip at file level, before the browser starts: other browsers do not accept the `chromium` channel +sentryTest.skip(({ browserName }) => browserName !== 'chromium' || shouldSkipReplayTest()); + sentryTest( 'link click that leaves the page is not a slow click after a bfcache restore', - async ({ getLocalTestUrl, page, browserName }) => { - if (shouldSkipReplayTest() || browserName !== 'chromium') { - sentryTest.skip(); - } - + async ({ getLocalTestUrl, page }) => { const url = await getLocalTestUrl({ testDir: __dirname }); await page.route('**/page2.html', route => route.fulfill({ contentType: 'text/html', body: 'Page 2' }),