Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

fix(recorder): do not deliver buffered action to a recording started after it (#43289)

JustasMc9ac716ef531
diff --git a/packages/playwright-core/src/server/recorder/recorderApp.ts b/packages/playwright-core/src/server/recorder/recorderApp.ts
index 1c58b86407..5709025163 100644
--- a/packages/playwright-core/src/server/recorder/recorderApp.ts
+++ b/packages/playwright-core/src/server/recorder/recorderApp.ts
@@ -366,6 +366,8 @@ export class ProgrammaticRecorderApp {
if ((context as any)[recorderAppSymbol])
throw new Error('Recorder is shown, close it before starting a recording.');
const recorder = await Recorder.forContext(context, { language: params.language, mode: 'recording', recorderMode: 'api', omitCallTracking: true });
+ // Deliver the buffered action to the existing recordings only, it happened before this one started.
+ recorder.flushPendingActions();
const app = new ProgrammaticRecorderApp(context, recorder, params, onEvent);
programmaticRecorderApps(context).add(app);
await recorder.setMode('recording');
diff --git a/tests/library/multiclient.spec.ts b/tests/library/multiclient.spec.ts
index f290cebbcf..a850fe8f28 100644
--- a/tests/library/multiclient.spec.ts
+++ b/tests/library/multiclient.spec.ts
@@ -419,3 +419,26 @@ test('should stop tracing upon disconnect', async ({ twoPages, trace }) => {
await pageB.context().tracing.start();
});
+
+test('should not deliver an action buffered before the second recording started', {
+ annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/43282' },
+}, async ({ twoPages }) => {
+ const { pageA, pageB } = twoPages;
+ await pageA.setContent(`<button>Before</button><button>After</button>`);
+
+ const recorder = () => {
+ const selectors: string[] = [];
+ return { selectors, actionAdded: (page, action) => selectors.push(action.selector), actionUpdated: () => {}, signalAdded: () => {} };
+ };
+ const recorderA = recorder();
+ const recorderB = recorder();
+ await (pageA.context() as any)._startRecording({}, recorderA);
+ await pageA.getByRole('button', { name: 'Before' }).click();
+ await (pageB.context() as any)._startRecording({}, recorderB);
+ await (pageA.context() as any)._stopRecording();
+ await pageB.getByRole('button', { name: 'After' }).click();
+ await (pageB.context() as any)._stopRecording();
+
+ expect(recorderA.selectors).toEqual(['internal:role=button[name="Before"i]']);
+ expect(recorderB.selectors).toEqual(['internal:role=button[name="After"i]']);
+});