From 123256f7a01df1eaf217db5ba3bab396d400cee1 Mon Sep 17 00:00:00 2001 From: David Newell Date: Wed, 13 Mar 2024 15:57:05 +0000 Subject: [PATCH 1/5] update default rrweb in array.full.js --- src/loader-globals-full.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loader-globals-full.ts b/src/loader-globals-full.ts index 563f2cad8..3515240a2 100644 --- a/src/loader-globals-full.ts +++ b/src/loader-globals-full.ts @@ -1,6 +1,6 @@ // Same as loader-globals.ts except includes rrweb scripts. -import './loader-recorder' +import './loader-recorder-v2' import { init_from_snippet } from './posthog-core' init_from_snippet() From 9720cdf4d2ad3825a42fbe8afcb17f03b4c55c58 Mon Sep 17 00:00:00 2001 From: David Newell Date: Wed, 13 Mar 2024 16:10:32 +0000 Subject: [PATCH 2/5] chore: remove rrweb v1 switcher --- package.json | 1 - pnpm-lock.yaml | 22 ----------- rollup.config.js | 12 ------ .../replay/sessionrecording.test.ts | 39 ------------------- src/constants.ts | 1 - src/extensions/replay/sessionrecording.ts | 16 ++------ src/loader-recorder.ts | 18 --------- src/types.ts | 2 - 8 files changed, 3 insertions(+), 108 deletions(-) delete mode 100644 src/loader-recorder.ts diff --git a/package.json b/package.json index 5545b7dcf..1d97f4213 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,6 @@ "rollup-plugin-visualizer": "^5.12.0", "rrweb": "2.0.0-alpha.11", "rrweb-snapshot": "2.0.0-alpha.11", - "rrweb-v1": "npm:rrweb@1.1.3", "sinon": "9.0.2", "testcafe": "1.19.0", "testcafe-browser-provider-browserstack": "1.14.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 752169882..7b0604df1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -174,9 +174,6 @@ devDependencies: rrweb-snapshot: specifier: 2.0.0-alpha.11 version: 2.0.0-alpha.11 - rrweb-v1: - specifier: npm:rrweb@1.1.3 - version: /rrweb@1.1.3 sinon: specifier: 9.0.2 version: 9.0.2 @@ -7946,10 +7943,6 @@ packages: resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} dev: true - /mitt@1.2.0: - resolution: {integrity: sha512-r6lj77KlwqLhIUku9UWYes7KJtsczvolZkzp8hbaDPPaE24OmWl5s539Mytlj22siEQKosZ26qCBgda2PKwoJw==} - dev: true - /mitt@3.0.0: resolution: {integrity: sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==} dev: true @@ -9197,25 +9190,10 @@ packages: rrweb-snapshot: 2.0.0-alpha.11 dev: true - /rrweb-snapshot@1.1.14: - resolution: {integrity: sha512-eP5pirNjP5+GewQfcOQY4uBiDnpqxNRc65yKPW0eSoU1XamDfc4M8oqpXGMyUyvLyxFDB0q0+DChuxxiU2FXBQ==} - dev: true - /rrweb-snapshot@2.0.0-alpha.11: resolution: {integrity: sha512-N0dzeJA2VhrlSOadkKwCVmV/DuNOwBH+Lhx89hAf9PQK4lCS8AP4AaylhqUdZOYHqwVjqsYel/uZ4hN79vuLhw==} dev: true - /rrweb@1.1.3: - resolution: {integrity: sha512-F2qp8LteJLyycsv+lCVJqtVpery63L3U+/ogqMA0da8R7Jx57o6gT+HpjrzdeeGMIBZR7kKNaKyJwDupTTu5KA==} - dependencies: - '@types/css-font-loading-module': 0.0.7 - '@xstate/fsm': 1.5.2 - base64-arraybuffer: 1.0.2 - fflate: 0.4.8 - mitt: 1.2.0 - rrweb-snapshot: 1.1.14 - dev: true - /rrweb@2.0.0-alpha.11(patch_hash=tjoktulcrliiekxagfypcvjnr4): resolution: {integrity: sha512-vJ2gNvF+pUG9C2aaau7iSNqhWBSc4BwtUO4FpegOtDObuH4PIaxNJOlgHz82+WxKr9XPm93ER0LqmNpy0KYdKg==} dependencies: diff --git a/rollup.config.js b/rollup.config.js index ea4905a89..6a26352f8 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -22,18 +22,6 @@ const plugins = [ /** @type {import('rollup').RollupOptions[]} */ export default [ - { - input: 'src/loader-recorder.ts', - output: [ - { - file: 'dist/recorder.js', - sourcemap: true, - format: 'iife', - name: 'posthog', - }, - ], - plugins: [...plugins], - }, { input: 'src/loader-recorder-v2.ts', output: [ diff --git a/src/__tests__/extensions/replay/sessionrecording.test.ts b/src/__tests__/extensions/replay/sessionrecording.test.ts index 5f5578a88..1a5ea0977 100644 --- a/src/__tests__/extensions/replay/sessionrecording.test.ts +++ b/src/__tests__/extensions/replay/sessionrecording.test.ts @@ -7,7 +7,6 @@ import { SESSION_RECORDING_CANVAS_RECORDING, SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_RECORDING_IS_SAMPLED, - SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE, } from '../../../constants' import { SessionIdManager } from '../../../sessionid' import { @@ -145,7 +144,6 @@ describe('SessionRecording', () => { // defaults posthog.persistence?.register({ [SESSION_RECORDING_ENABLED_SERVER_SIDE]: true, - [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v2', [CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE]: false, [SESSION_RECORDING_IS_SAMPLED]: undefined, }) @@ -193,33 +191,6 @@ describe('SessionRecording', () => { }) }) - describe('getRecordingVersion', () => { - it('uses client side setting v2 over server side', () => { - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v1' }) - posthog.config.session_recording.recorderVersion = 'v2' - expect(sessionRecording['recordingVersion']).toBe('v2') - }) - - it('uses client side setting v1 over server side', () => { - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v2' }) - posthog.config.session_recording.recorderVersion = 'v1' - expect(sessionRecording['recordingVersion']).toBe('v1') - }) - - it('uses server side setting if client side setting is not set', () => { - posthog.config.session_recording.recorderVersion = undefined - - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v1' }) - expect(sessionRecording['recordingVersion']).toBe('v1') - - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v2' }) - expect(sessionRecording['recordingVersion']).toBe('v2') - - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: undefined }) - expect(sessionRecording['recordingVersion']).toBe('v1') - }) - }) - describe('startRecordingIfEnabled', () => { beforeEach(() => { // need to cast as any to mock private methods @@ -719,16 +690,7 @@ describe('SessionRecording', () => { expect(loadScript).not.toHaveBeenCalled() }) - it('loads recording v1 script from right place', () => { - posthog.config.session_recording.recorderVersion = 'v1' - - sessionRecording.startRecordingIfEnabled() - - expect(loadScript).toHaveBeenCalledWith('https://test.com/static/recorder.js?v=v0.0.1', expect.anything()) - }) - it('loads recording v2 script from right place', () => { - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v2' }) sessionRecording.startRecordingIfEnabled() expect(loadScript).toHaveBeenCalledWith( @@ -739,7 +701,6 @@ describe('SessionRecording', () => { it('load correct recording version if there is a cached mismatch', () => { posthog.__loaded_recorder_version = 'v1' - posthog.persistence?.register({ [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: 'v2' }) sessionRecording.startRecordingIfEnabled() expect(loadScript).toHaveBeenCalledWith( diff --git a/src/constants.ts b/src/constants.ts index 8423864c3..9dc632a0e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -13,7 +13,6 @@ export const EVENT_TIMERS_KEY = '__timers' export const AUTOCAPTURE_DISABLED_SERVER_SIDE = '$autocapture_disabled_server_side' export const SESSION_RECORDING_ENABLED_SERVER_SIDE = '$session_recording_enabled_server_side' export const CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE = '$console_log_recording_enabled_server_side' -export const SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE = '$session_recording_recorder_version_server_side' // follows rrweb versioning export const SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE = '$session_recording_network_payload_capture' export const SESSION_RECORDING_CANVAS_RECORDING = '$session_recording_canvas_recording' export const SESSION_ID = '$sesid' diff --git a/src/extensions/replay/sessionrecording.ts b/src/extensions/replay/sessionrecording.ts index 7d10e0a59..46047a017 100644 --- a/src/extensions/replay/sessionrecording.ts +++ b/src/extensions/replay/sessionrecording.ts @@ -4,7 +4,6 @@ import { SESSION_RECORDING_ENABLED_SERVER_SIDE, SESSION_RECORDING_IS_SAMPLED, SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE, - SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE, } from '../../constants' import { FULL_SNAPSHOT_EVENT_TYPE, @@ -192,12 +191,6 @@ export class SessionRecording { : undefined } - private get recordingVersion() { - const recordingVersion_server_side = this.instance.get_property(SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE) - const recordingVersion_client_side = this.instance.config.session_recording?.recorderVersion - return recordingVersion_client_side || recordingVersion_server_side || 'v1' - } - // network payload capture config has three parts // each can be configured server side or client side private get networkPayloadCapture(): @@ -341,7 +334,6 @@ export class SessionRecording { this.instance.persistence.register({ [SESSION_RECORDING_ENABLED_SERVER_SIDE]: !!response['sessionRecording'], [CONSOLE_LOG_RECORDING_ENABLED_SERVER_SIDE]: response.sessionRecording?.consoleLogRecordingEnabled, - [SESSION_RECORDING_RECORDER_VERSION_SERVER_SIDE]: response.sessionRecording?.recorderVersion, [SESSION_RECORDING_NETWORK_PAYLOAD_CAPTURE]: { capturePerformance: response.capturePerformance, ...response.sessionRecording?.networkPayloadCapture, @@ -429,17 +421,15 @@ export class SessionRecording { // We want to ensure the sessionManager is reset if necessary on load of the recorder this.sessionManager.checkAndGetSessionAndWindowId() - const recorderJS = this.recordingVersion === 'v2' ? 'recorder-v2.js' : 'recorder.js' - // If recorder.js is already loaded (if array.full.js snippet is used or posthog-js/dist/recorder is // imported) or matches the requested recorder version, don't load script. Otherwise, remotely import // recorder.js from cdn since it hasn't been loaded. - if (this.instance.__loaded_recorder_version !== this.recordingVersion) { + if (this.instance.__loaded_recorder_version !== 'v2') { loadScript( - this.instance.requestRouter.endpointFor('assets', `/static/${recorderJS}?v=${Config.LIB_VERSION}`), + this.instance.requestRouter.endpointFor('assets', `/static/recorder-v2.js?v=${Config.LIB_VERSION}`), (err) => { if (err) { - return logger.error(LOGGER_PREFIX + ` could not load ${recorderJS}`, err) + return logger.error(LOGGER_PREFIX + ` could not load recorder-v2.js`, err) } this._onScriptLoaded() diff --git a/src/loader-recorder.ts b/src/loader-recorder.ts deleted file mode 100644 index 2680a5358..000000000 --- a/src/loader-recorder.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { version } from 'rrweb-v1/package.json' - -// Same as loader-globals.ts except includes rrweb scripts. -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -import rrwebRecord from 'rrweb-v1/es/rrweb/packages/rrweb/src/record' -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -import { getRecordConsolePlugin } from 'rrweb-v1/es/rrweb/packages/rrweb/src/plugins/console/record' - -import { window } from './utils/globals' - -if (window) { - ;(window as any).rrweb = { record: rrwebRecord, version: 'v1', rrwebVersion: version } - ;(window as any).rrwebConsoleRecord = { getRecordConsolePlugin } -} - -export default rrwebRecord diff --git a/src/types.ts b/src/types.ts index ff5032b41..2ed1420e5 100644 --- a/src/types.ts +++ b/src/types.ts @@ -175,7 +175,6 @@ export interface SessionRecordingOptions { slimDOMOptions?: SlimDOMOptions | 'all' | true collectFonts?: boolean inlineStylesheet?: boolean - recorderVersion?: 'v1' | 'v2' recordCrossOriginIframes?: boolean /** @deprecated - use maskCapturedNetworkRequestFn instead */ maskNetworkRequestFn?: ((data: NetworkRequest) => NetworkRequest | null | undefined) | null @@ -267,7 +266,6 @@ export interface DecideResponse { sessionRecording?: { endpoint?: string consoleLogRecordingEnabled?: boolean - recorderVersion?: 'v1' | 'v2' // the API returns a decimal between 0 and 1 as a string sampleRate?: string | null minimumDurationMilliseconds?: number From 818d43376ac3deb55c00ff4e26e3c5b240bfc68a Mon Sep 17 00:00:00 2001 From: David Newell Date: Wed, 13 Mar 2024 16:41:47 +0000 Subject: [PATCH 3/5] keep recorder.js file --- rollup.config.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/rollup.config.js b/rollup.config.js index 6a26352f8..7b5e1eacc 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -22,6 +22,18 @@ const plugins = [ /** @type {import('rollup').RollupOptions[]} */ export default [ + { + input: 'src/loader-recorder-v2.ts', + output: [ + { + file: 'dist/recorder.js', + sourcemap: true, + format: 'iife', + name: 'posthog', + }, + ], + plugins: [...plugins], + }, { input: 'src/loader-recorder-v2.ts', output: [ From 66d3c56acab20e40cdd067bd81ae5a0ba1917e99 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 14 Mar 2024 09:10:37 +0100 Subject: [PATCH 4/5] Fixes --- rollup.config.js | 9 ++------- src/loader-globals-full.ts | 2 +- src/{loader-recorder-v2.ts => loader-recorder.ts} | 0 3 files changed, 3 insertions(+), 8 deletions(-) rename src/{loader-recorder-v2.ts => loader-recorder.ts} (100%) diff --git a/rollup.config.js b/rollup.config.js index 7b5e1eacc..3d0585456 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -23,7 +23,7 @@ const plugins = [ /** @type {import('rollup').RollupOptions[]} */ export default [ { - input: 'src/loader-recorder-v2.ts', + input: 'src/loader-recorder.ts', output: [ { file: 'dist/recorder.js', @@ -31,13 +31,8 @@ export default [ format: 'iife', name: 'posthog', }, - ], - plugins: [...plugins], - }, - { - input: 'src/loader-recorder-v2.ts', - output: [ { + // Backwards compatibility for older SDK versions file: 'dist/recorder-v2.js', sourcemap: true, format: 'iife', diff --git a/src/loader-globals-full.ts b/src/loader-globals-full.ts index 3515240a2..563f2cad8 100644 --- a/src/loader-globals-full.ts +++ b/src/loader-globals-full.ts @@ -1,6 +1,6 @@ // Same as loader-globals.ts except includes rrweb scripts. -import './loader-recorder-v2' +import './loader-recorder' import { init_from_snippet } from './posthog-core' init_from_snippet() diff --git a/src/loader-recorder-v2.ts b/src/loader-recorder.ts similarity index 100% rename from src/loader-recorder-v2.ts rename to src/loader-recorder.ts From d3118dfb2fa7630c7ae84c516b5e6758f3099e39 Mon Sep 17 00:00:00 2001 From: Ben White Date: Thu, 14 Mar 2024 09:14:31 +0100 Subject: [PATCH 5/5] Fix cypress --- cypress/support/e2e.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/cypress/support/e2e.ts b/cypress/support/e2e.ts index 82ddd8156..2a4c1f641 100644 --- a/cypress/support/e2e.ts +++ b/cypress/support/e2e.ts @@ -24,6 +24,7 @@ beforeEach(() => { cy.readFile('dist/recorder.js').then((body) => { cy.intercept('**/static/recorder.js*', { body }).as('recorder') + cy.intercept('**/static/recorder-v2.js*', { body }).as('recorder') }) cy.readFile('dist/surveys.js').then((body) => {