Skip to content

Chrome DevTools for coding agents

fix: guard performance_stop_trace when tracing inactive (#295)

leslie liu8200194c8037
diff --git a/src/tools/performance.ts b/src/tools/performance.ts
index 6f3af7c3..c9de76f7 100644
--- a/src/tools/performance.ts
+++ b/src/tools/performance.ts
@@ -111,7 +111,7 @@ export const stopTrace = defineTool({
},
schema: {},
handler: async (_request, response, context) => {
- if (!context.isRunningPerformanceTrace) {
+ if (!context.isRunningPerformanceTrace()) {
return;
}
const page = context.getSelectedPage();
diff --git a/tests/tools/performance.test.ts b/tests/tools/performance.test.ts
index ec14381e..b8ac5533 100644
--- a/tests/tools/performance.test.ts
+++ b/tests/tools/performance.test.ts
@@ -218,7 +218,11 @@ describe('performance', () => {
it('does nothing if the trace is not running and does not error', async () => {
await withBrowser(async (response, context) => {
context.setIsRunningPerformanceTrace(false);
+ const selectedPage = context.getSelectedPage();
+ const stopTracingStub = sinon.stub(selectedPage.tracing, 'stop');
await stopTrace.handler({params: {}}, response, context);
+ sinon.assert.notCalled(stopTracingStub);
+ assert.strictEqual(context.isRunningPerformanceTrace(), false);
});
});