豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content
Merged
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
17 changes: 17 additions & 0 deletions src/DevtoolsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ const DEFAULT_FACTORY: TargetUniverseFactoryFn = async (page: Page) => {
const connection = new PuppeteerDevToolsConnection(session);

const targetManager = universe.context.get(TargetManager);
targetManager.observeModels(DebuggerModel, SKIP_ALL_PAUSES);

const target = targetManager.createTarget(
'main',
'',
Expand All @@ -258,3 +260,18 @@ const DEFAULT_FACTORY: TargetUniverseFactoryFn = async (page: Page) => {
);
return {target, universe};
};

// We don't want to pause any DevTools universe session ever on the MCP side.
//
// Note that calling `setSkipAllPauses` only affects the session on which it was
// sent. This means DevTools can still pause, step and do whatever. We just won't
// see the `Debugger.paused`/`Debugger.resumed` events on the MCP side.
const SKIP_ALL_PAUSES = {
modelAdded(model: DebuggerModel): void {
void model.agent.invoke_setSkipAllPauses({skip: true});
},

modelRemoved(): void {
// Do nothing.
},
};
24 changes: 23 additions & 1 deletion tests/DevtoolsUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import {afterEach, describe, it} from 'node:test';

import sinon from 'sinon';

import {AggregatedIssue} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
import {
AggregatedIssue,
DebuggerModel,
} from '../node_modules/chrome-devtools-frontend/mcp/mcp.js';
import {
extractUrlLikeFromDevToolsTitle,
urlsEqual,
Expand Down Expand Up @@ -240,4 +243,23 @@ describe('UniverseManager', () => {
assert.notStrictEqual(manager.get(page), null);
});
});

it('ignores pauses', async () => {
await withBrowser(async (browser, page) => {
const manager = new UniverseManager(browser);
await manager.init([page]);
const targetUniverse = manager.get(page);
assert.ok(targetUniverse);
const model = targetUniverse.target.model(DebuggerModel);
assert.ok(model);

const pausedSpy = sinon.stub();
model.addEventListener('DebuggerPaused' as any, pausedSpy); // eslint-disable-line

const result = await page.evaluate('debugger; 1 + 1');
assert.strictEqual(result, 2);

sinon.assert.notCalled(pausedSpy);
});
});
});