Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/playwright-core/src/tools/backend/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ const tracingStop = defineTool({

handle: async (context, params, response) => {
const browserContext = await context.ensureBrowserContext();
await browserContext.tracing.stop();
// eslint-disable-next-line no-restricted-syntax
const traceLegend = (browserContext.tracing as any)[traceLegendSymbol];
if (!traceLegend)
throw new Error('Tracing is not started');
await browserContext.tracing.stop();
// eslint-disable-next-line no-restricted-syntax
delete (browserContext.tracing as any)[traceLegendSymbol];

Expand Down
13 changes: 13 additions & 0 deletions tests/mcp/tracing.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,16 @@ test('check that trace is saved with browser_start_tracing (no output dir)', asy
expect.stringMatching(/trace-\d+\.trace/),
]);
});

test('browser_stop_tracing without start returns error', async ({ startClient }) => {
const { client } = await startClient({
args: ['--caps=tracing'],
});

expect(await client.callTool({
name: 'browser_stop_tracing',
})).toHaveResponse({
isError: true,
error: expect.stringContaining('Tracing is not started'),
});
});
Loading