Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<a href="/page2.html" id="link">Link</a>
<button id="noopButton">Do nothing</button>
<script>
window.addEventListener('pageshow', e => {
window.restoredFromBfcache = e.persisted;
});
</script>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
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'] },
});

// 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 }) => {
const url = await getLocalTestUrl({ testDir: __dirname });
await page.route('**/page2.html', route =>
route.fulfill({ contentType: 'text/html', body: '<!doctype html><html><body>Page 2</body></html>' }),
);

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);
Comment thread
andreiborza marked this conversation as resolved.
Resolved

// 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']);
},
);
11 changes: 11 additions & 0 deletions packages/replay-internal/src/coreHandlers/handleClick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading