From e8afffd91a7a6e16077e356acea2787b0d8a57ae Mon Sep 17 00:00:00 2001 From: Pavel Feldman Date: Tue, 17 Mar 2026 11:09:33 -0700 Subject: [PATCH] fix(api): make Tracing.group return Disposable Tracing.group() now returns a Disposable that calls groupEnd() on dispose, enabling `await using` pattern for automatic group cleanup. --- CLAUDE.md | 2 ++ docs/src/api/class-tracing.md | 1 + packages/playwright-client/types/types.d.ts | 2 +- packages/playwright-core/src/client/tracing.ts | 2 ++ packages/playwright-core/types/types.d.ts | 2 +- tests/library/screencast.spec.ts | 4 ++-- 6 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 9b85a3d23fa0e..d5bdcd3a62372 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -96,6 +96,8 @@ When creating or moving files, update the relevant `DEPS.list` to declare allowe ## Commit Convention +Before committing, run `npm run flint` and fix errors. + Semantic commit messages: `label(scope): description` Labels: `fix`, `feat`, `chore`, `docs`, `test`, `devops` diff --git a/docs/src/api/class-tracing.md b/docs/src/api/class-tracing.md index 704409a1705da..9c4b5221d0e62 100644 --- a/docs/src/api/class-tracing.md +++ b/docs/src/api/class-tracing.md @@ -305,6 +305,7 @@ To specify the final trace zip file name, you need to pass `path` option to ## async method: Tracing.group * since: v1.49 +- returns: <[Disposable]> :::caution Use `test.step` instead when available. diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts index 572435010d35c..3f8e9d677c7cd 100644 --- a/packages/playwright-client/types/types.d.ts +++ b/packages/playwright-client/types/types.d.ts @@ -21957,7 +21957,7 @@ export interface Tracing { column?: number; }; - }): Promise; + }): Promise; /** * Closes the last group created by diff --git a/packages/playwright-core/src/client/tracing.ts b/packages/playwright-core/src/client/tracing.ts index cd5e06ff5d042..5fed143e0a805 100644 --- a/packages/playwright-core/src/client/tracing.ts +++ b/packages/playwright-core/src/client/tracing.ts @@ -16,6 +16,7 @@ import { Artifact } from './artifact'; import { ChannelOwner } from './channelOwner'; +import { DisposableStub } from './disposable'; import type * as api from '../../types/types'; import type * as channels from '@protocol/channels'; @@ -62,6 +63,7 @@ export class Tracing extends ChannelOwner implements ap if (options.location) this._additionalSources.add(options.location.file); await this._channel.tracingGroup({ name, location: options.location }); + return new DisposableStub(() => this.groupEnd()); } async groupEnd() { diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 572435010d35c..3f8e9d677c7cd 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -21957,7 +21957,7 @@ export interface Tracing { column?: number; }; - }): Promise; + }): Promise; /** * Closes the last group created by diff --git a/tests/library/screencast.spec.ts b/tests/library/screencast.spec.ts index 69bdfbe150615..7ab98d300b008 100644 --- a/tests/library/screencast.spec.ts +++ b/tests/library/screencast.spec.ts @@ -97,9 +97,9 @@ test('screencast.start dispose stops screencast', async ({ browser, server, trac const page = await context.newPage(); const frames: { data: Buffer }[] = []; - page.screencast().on('screencastframe', frame => frames.push(frame)); + page.screencast.on('screencastframe', frame => frames.push(frame)); - const disposable = await page.screencast().start({ maxSize: { width: 500, height: 400 } }); + const disposable = await page.screencast.start({ maxSize: { width: 500, height: 400 } }); await page.goto(server.EMPTY_PAGE); await page.evaluate(() => document.body.style.backgroundColor = 'red'); await rafraf(page, 100);