Skip to content

Commit 8200194

Browse files
authored
fix: guard performance_stop_trace when tracing inactive (#295)
PR Description - Fix the stop-trace guard to call context.isRunningPerformanceTrace() so we skip page.tracing.stop() when nothing is recording, avoiding the Puppeteer error that bubbled up to users. - Extend the “does nothing” test to stub tracing.stop() and assert it stays untouched, guaranteeing the guard path is covered.
1 parent 3b197bc commit 8200194

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/tools/performance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const stopTrace = defineTool({
111111
},
112112
schema: {},
113113
handler: async (_request, response, context) => {
114-
if (!context.isRunningPerformanceTrace) {
114+
if (!context.isRunningPerformanceTrace()) {
115115
return;
116116
}
117117
const page = context.getSelectedPage();

tests/tools/performance.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,11 @@ describe('performance', () => {
218218
it('does nothing if the trace is not running and does not error', async () => {
219219
await withBrowser(async (response, context) => {
220220
context.setIsRunningPerformanceTrace(false);
221+
const selectedPage = context.getSelectedPage();
222+
const stopTracingStub = sinon.stub(selectedPage.tracing, 'stop');
221223
await stopTrace.handler({params: {}}, response, context);
224+
sinon.assert.notCalled(stopTracingStub);
225+
assert.strictEqual(context.isRunningPerformanceTrace(), false);
222226
});
223227
});
224228

0 commit comments

Comments
 (0)