mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
inspector: support for worker inspection in chrome devtools
Fixes: https://github.com/nodejs/node/issues/56343 PR-URL: https://github.com/nodejs/node/pull/56759 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
cff440e0fa
commit
aabafbc28f
13 files changed
+443
-23
No files matched your search
@@ -0,0 +1,75 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
common.skipIfInspectorDisabled();
|
||||
|
||||
const { NodeInstance } = require('../common/inspector-helper.js');
|
||||
|
||||
async function setupInspector(session, sessionId = undefined) {
|
||||
await session.send({ method: 'NodeRuntime.enable', sessionId });
|
||||
await session.waitForNotification('NodeRuntime.waitingForDebugger');
|
||||
await session.send({ method: 'Runtime.enable', sessionId });
|
||||
await session.send({ method: 'Debugger.enable', sessionId });
|
||||
await session.send({ method: 'Runtime.runIfWaitingForDebugger', sessionId });
|
||||
await session.send({ method: 'NodeRuntime.disable', sessionId });
|
||||
await session.waitForNotification((notification) => {
|
||||
return notification.method === 'Debugger.scriptParsed' &&
|
||||
notification.params.url === 'node:internal/bootstrap/realm' &&
|
||||
notification.sessionId === sessionId;
|
||||
});
|
||||
}
|
||||
|
||||
async function test(isSetAutoAttachBeforeExecution) {
|
||||
const child = new NodeInstance(['--inspect-brk=0', '--experimental-worker-inspection'],
|
||||
'',
|
||||
fixtures.path('inspect-worker/index.js')
|
||||
);
|
||||
|
||||
|
||||
const session = await child.connectInspectorSession();
|
||||
await setupInspector(session);
|
||||
|
||||
if (isSetAutoAttachBeforeExecution) {
|
||||
await session.send({ method: 'Target.setAutoAttach', params: { autoAttach: true, waitForDebuggerOnStart: true } });
|
||||
}
|
||||
await session.waitForNotification('Debugger.paused');
|
||||
await session.send({ method: 'Debugger.resume' });
|
||||
|
||||
const sessionId = '1';
|
||||
await session.waitForNotification('Target.targetCreated');
|
||||
|
||||
if (!isSetAutoAttachBeforeExecution) {
|
||||
await session.send({ method: 'Target.setAutoAttach', params: { autoAttach: true, waitForDebuggerOnStart: true } });
|
||||
}
|
||||
await session.waitForNotification((notification) => {
|
||||
return notification.method === 'Target.attachedToTarget' &&
|
||||
notification.params.sessionId === sessionId;
|
||||
});
|
||||
await setupInspector(session, sessionId);
|
||||
await session.waitForNotification('Debugger.paused');
|
||||
await session.send({ method: 'Debugger.resume', sessionId });
|
||||
await session.waitForDisconnect();
|
||||
}
|
||||
|
||||
test(true).then(common.mustCall());
|
||||
test(false).then(common.mustCall());
|
||||
|
||||
function withPermissionOptionTest() {
|
||||
const permissionErrorThrow = common.mustCall();
|
||||
const child = new NodeInstance(['--inspect-brk=0', '--experimental-worker-inspection', '--permission'],
|
||||
'',
|
||||
fixtures.path('inspect-worker/index.js'),
|
||||
{
|
||||
log: (_, msg) => {
|
||||
if (msg.includes('Access to this API has been restricted')) {
|
||||
permissionErrorThrow();
|
||||
}
|
||||
},
|
||||
error: () => {},
|
||||
}
|
||||
);
|
||||
child.connectInspectorSession();
|
||||
}
|
||||
withPermissionOptionTest();
|
||||
Reference in new issue
Block a user