Skip to content

Commit d0711dc

Browse files
Kim DuganKim Dugan
authored andcommitted
replay: wait for new config before recording decision
1 parent 755c2d7 commit d0711dc

19 files changed

+191
-176
lines changed

.changeset/tiny-glasses-pump.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'posthog-js': patch
3+
---
4+
5+
wait for fresh config before recording start decision, add new recorder status, output recording started event

packages/browser/playwright/mocked/session-recording/lazy-session-recording-sampling.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33

44
const startOptions = {
55
options: {
@@ -34,6 +34,7 @@ test.describe('Session recording - sampling', () => {
3434
await start(startOptions, page, context)
3535
},
3636
})
37+
await waitForSessionRecordingToStart(page)
3738

3839
await page.expectCapturedEventsToBe(['$pageview'])
3940
await page.resetCapturedEvents()

packages/browser/playwright/mocked/session-recording/lazy-session-recording.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33
import { Page } from '@playwright/test'
44
import { isUndefined } from '@posthog/core'
55

@@ -99,6 +99,7 @@ test.describe('Session recording - array.js', () => {
9999
await start(startOptions, page, context)
100100
},
101101
})
102+
await waitForSessionRecordingToStart(page)
102103
await page.expectCapturedEventsToBe(['$pageview'])
103104
await page.resetCapturedEvents()
104105
})

packages/browser/playwright/mocked/session-recording/session-linking.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33

44
const startOptions = {
55
options: {
@@ -25,6 +25,7 @@ test.describe('Session Recording - Session Linking', () => {
2525
await start(startOptions, page, context)
2626
},
2727
})
28+
await waitForSessionRecordingToStart(page)
2829
await page.expectCapturedEventsToBe(['$pageview'])
2930
await page.resetCapturedEvents()
3031
})

packages/browser/playwright/mocked/session-recording/session-recording-array-full.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33

44
const startOptions = {
55
options: {
@@ -21,6 +21,7 @@ const startOptions = {
2121
test.describe('session recording in array.full.js', () => {
2222
test('captures session events', async ({ page, context }) => {
2323
await start(startOptions, page, context)
24+
await waitForSessionRecordingToStart(page)
2425

2526
await page.waitingForNetworkCausedBy({
2627
urlPatternsToWaitFor: ['**/ses/*'],

packages/browser/playwright/mocked/session-recording/session-recording-idle-timeout.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33
import { Page } from '@playwright/test'
44

55
async function ensureRecordingIsStopped(page: Page) {
@@ -88,6 +88,7 @@ test.describe('Session recording - idle timeout behavior', () => {
8888
await start(startOptions, page, context)
8989
},
9090
})
91+
await waitForSessionRecordingToStart(page)
9192
await page.expectCapturedEventsToBe(['$pageview'])
9293
await page.resetCapturedEvents()
9394
})

packages/browser/playwright/mocked/session-recording/session-recording-linked-flags.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start, StartOptions } from '../utils/setup'
2+
import { start, StartOptions, waitForRemoteConfig } from '../utils/setup'
33
import { assertThatRecordingStarted, pollUntilEventCaptured } from '../utils/event-capture-utils'
44
import { BrowserContext, Page } from '@playwright/test'
55

@@ -42,6 +42,7 @@ test.describe('Session recording - linked flags', () => {
4242
page,
4343
context
4444
)
45+
await waitForRemoteConfig(page)
4546
await page.expectCapturedEventsToBe(expectedStartingEvents)
4647
await page.resetCapturedEvents()
4748
}

packages/browser/playwright/mocked/session-recording/session-recording-network-recorder.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33
import { Page } from '@playwright/test'
44

55
test.beforeEach(async ({ context }) => {
@@ -90,6 +90,7 @@ test.beforeEach(async ({ context }) => {
9090
)
9191
},
9292
})
93+
await waitForSessionRecordingToStart(page)
9394

9495
// also wrap after posthog is loaded
9596
await page.evaluate((isBadlyBehaved) => {

packages/browser/playwright/mocked/session-recording/session-recording-sampling.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33

44
const startOptions = {
55
options: {
@@ -36,6 +36,7 @@ test.describe('Session recording - sampling', () => {
3636
await start(startOptions, page, context)
3737
},
3838
})
39+
await waitForSessionRecordingToStart(page)
3940

4041
await page.expectCapturedEventsToBe(['$pageview'])
4142
await page.resetCapturedEvents()

packages/browser/playwright/mocked/session-recording/session-recording.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test, WindowWithPostHog } from '../utils/posthog-playwright-test-base'
2-
import { start } from '../utils/setup'
2+
import { start, waitForSessionRecordingToStart } from '../utils/setup'
33
import { Page } from '@playwright/test'
44
import { isUndefined } from '@posthog/core'
55

@@ -101,6 +101,7 @@ test.describe('Session recording - array.js', () => {
101101
await start(startOptions, page, context)
102102
},
103103
})
104+
await waitForSessionRecordingToStart(page)
104105
await page.expectCapturedEventsToBe(['$pageview'])
105106
await page.resetCapturedEvents()
106107
})
@@ -110,7 +111,7 @@ test.describe('Session recording - array.js', () => {
110111
const ph = (window as WindowWithPostHog).posthog
111112
return ph?.get_session_id()
112113
})
113-
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config'])
114+
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config', '$recording_started'])
114115

115116
await page.evaluate(() => {
116117
const ph = (window as WindowWithPostHog).posthog
@@ -124,7 +125,7 @@ test.describe('Session recording - array.js', () => {
124125
ph?.startSessionRecording()
125126
})
126127

127-
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config'])
128+
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config', '$recording_started'])
128129

129130
// the session id is not rotated by stopping and starting the recording
130131
const finishingSessionId = await page.evaluate(() => {
@@ -136,7 +137,7 @@ test.describe('Session recording - array.js', () => {
136137

137138
test('captures snapshots when the mouse moves', async ({ page }) => {
138139
// first make sure the page is booted and recording
139-
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config'])
140+
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config', '$recording_started'])
140141
await page.resetCapturedEvents()
141142
// Allow any pending async operations (e.g. flags loading, buffer flushes) to settle
142143
// before starting the timing-sensitive mouse move sequence
@@ -230,7 +231,7 @@ test.describe('Session recording - array.js', () => {
230231
})
231232
expect(startingSessionId).not.toBeNull()
232233

233-
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config'])
234+
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config', '$recording_started'])
234235

235236
await page.resetCapturedEvents()
236237
await page.evaluate(() => {
@@ -338,7 +339,7 @@ test.describe('Session recording - array.js', () => {
338339

339340
test('adds debug properties to captured events', async ({ page }) => {
340341
// make sure recording is running
341-
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config'])
342+
await ensureActivitySendsSnapshots(page, ['$remote_config_received', '$session_options', '$posthog_config', '$recording_started'])
342343

343344
await page.evaluate(() => {
344345
const ph = (window as WindowWithPostHog).posthog

0 commit comments

Comments
 (0)