📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Fix replay byte limit normalization
Blue Mouse5299e9aa3ab7
diff --git a/packages/tracker-js/src/Lib.ts b/packages/tracker-js/src/Lib.tsindex f3319ef75..b745bc8f0 100644--- a/packages/tracker-js/src/Lib.ts+++ b/packages/tracker-js/src/Lib.ts@@ -885,15 +885,21 @@ export class Lib {options.maxEventsPerChunk > 0? Math.floor(options.maxEventsPerChunk): DEFAULT_SESSION_REPLAY_MAX_EVENTS- const maxBytesPerChunk =- typeof options.maxBytesPerChunk === 'number' &&- options.maxBytesPerChunk > 0+ const maxBytesPerChunkCandidate =+ typeof options.maxBytesPerChunk === 'number'? Math.floor(options.maxBytesPerChunk)+ : Number.NaN+ const maxBytesPerChunk =+ maxBytesPerChunkCandidate >= 1+ ? maxBytesPerChunkCandidate: DEFAULT_SESSION_REPLAY_MAX_CHUNK_BYTES- const maxBytesPerEvent =- typeof options.maxBytesPerEvent === 'number' &&- options.maxBytesPerEvent > 0+ const maxBytesPerEventCandidate =+ typeof options.maxBytesPerEvent === 'number'? Math.floor(options.maxBytesPerEvent)+ : Number.NaN+ const maxBytesPerEvent =+ maxBytesPerEventCandidate >= 1+ ? maxBytesPerEventCandidate: DEFAULT_SESSION_REPLAY_MAX_EVENT_BYTESconst maxDurationMs =typeof options.maxDurationMs === 'number' && options.maxDurationMs > 0diff --git a/packages/tracker-js/tests/sessionReplay.test.ts b/packages/tracker-js/tests/sessionReplay.test.tsindex 03236b39a..ae04a9b85 100644--- a/packages/tracker-js/tests/sessionReplay.test.ts+++ b/packages/tracker-js/tests/sessionReplay.test.ts@@ -398,6 +398,39 @@ describe('Session replay tracking', () => {await actions.stop()})+ test('fractional byte limits below one fall back to defaults', async () => {+ const { recordOptions } = usePackageRrweb()+ const { init, startSessionReplay } = await loadTracker()++ init(PROJECT_ID, { devMode: true })+ const actions = await startSessionReplay({+ flushIntervalMs: 60_000,+ maxBytesPerChunk: 0.5,+ maxBytesPerEvent: 0.5,+ })++ recordOptions().emit({ type: 3, timestamp: 500 })+ await Promise.resolve()+ await Promise.resolve()++ expect(+ fetchMock.mock.calls.filter(([url]) =>+ String(url).includes('/session-replay/chunk'),+ ),+ ).toHaveLength(0)++ await actions.flush()++ expect(fetchMock).toHaveBeenCalledWith(+ 'https://api.swetrix.com/log/session-replay/chunk',+ expect.objectContaining({+ body: expect.stringContaining('"timestamp":500'),+ }),+ )++ await actions.stop()+ })+test('script rrweb loader clears failed loads so startSessionReplay can retry', async () => {const record = jest.fn(() => jest.fn())const trackerScript = document.createElement('script')