Skip to content

Commit 2c1061b

Browse files
authored
chore: skip all pauses in all DevTools universes (#631)
1 parent 6b0984a commit 2c1061b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

src/DevtoolsUtils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ const DEFAULT_FACTORY: TargetUniverseFactoryFn = async (page: Page) => {
247247
const connection = new PuppeteerDevToolsConnection(session);
248248

249249
const targetManager = universe.context.get(TargetManager);
250+
targetManager.observeModels(DebuggerModel, SKIP_ALL_PAUSES);
251+
250252
const target = targetManager.createTarget(
251253
'main',
252254
'',
@@ -258,3 +260,18 @@ const DEFAULT_FACTORY: TargetUniverseFactoryFn = async (page: Page) => {
258260
);
259261
return {target, universe};
260262
};
263+
264+
// We don't want to pause any DevTools universe session ever on the MCP side.
265+
//
266+
// Note that calling `setSkipAllPauses` only affects the session on which it was
267+
// sent. This means DevTools can still pause, step and do whatever. We just won't
268+
// see the `Debugger.paused`/`Debugger.resumed` events on the MCP side.
269+
const SKIP_ALL_PAUSES = {
270+
modelAdded(model: DebuggerModel): void {
271+
void model.agent.invoke_setSkipAllPauses({skip: true});
272+
},
273+
274+
modelRemoved(): void {
275+
// Do nothing.
276+
},
277+
};

tests/DevtoolsUtils.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {afterEach, describe, it} from 'node:test';
99

1010
import sinon from 'sinon';
1111

12-
import {AggregatedIssue} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
12+
import {
13+
AggregatedIssue,
14+
DebuggerModel,
15+
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
1316
import {
1417
extractUrlLikeFromDevToolsTitle,
1518
urlsEqual,
@@ -240,4 +243,23 @@ describe('UniverseManager', () => {
240243
assert.notStrictEqual(manager.get(page), null);
241244
});
242245
});
246+
247+
it('ignores pauses', async () => {
248+
await withBrowser(async (browser, page) => {
249+
const manager = new UniverseManager(browser);
250+
await manager.init([page]);
251+
const targetUniverse = manager.get(page);
252+
assert.ok(targetUniverse);
253+
const model = targetUniverse.target.model(DebuggerModel);
254+
assert.ok(model);
255+
256+
const pausedSpy = sinon.stub();
257+
model.addEventListener('DebuggerPaused' as any, pausedSpy); // eslint-disable-line
258+
259+
const result = await page.evaluate('debugger; 1 + 1');
260+
assert.strictEqual(result, 2);
261+
262+
sinon.assert.notCalled(pausedSpy);
263+
});
264+
});
243265
});

0 commit comments

Comments
 (0)