-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
Adds require('inspector').console, mapping it to the original global.console of V8. This enables applications to send messages to the inspector console programmatically. Fixes: nodejs#21651
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,8 @@ | |
|
||
const browserGlobals = !process._noBrowserGlobals; | ||
if (browserGlobals) { | ||
// we are setting this here to foward it to the inspector later | ||
perThreadSetup.originalConsole = global.console; | ||
setupGlobalTimeouts(); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jdalton
|
||
setupGlobalConsole(); | ||
setupGlobalURL(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Flags: --expose-internals | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
common.skipIfInspectorDisabled(); | ||
|
||
const { NodeInstance } = require('../common/inspector-helper.js'); | ||
const assert = require('assert'); | ||
|
||
async function runTest() { | ||
const script = 'require(\'inspector\').console.log(\'hello world\');'; | ||
const child = new NodeInstance('--inspect-brk=0', script, ''); | ||
|
||
let out = ''; | ||
child.on('stdout', (line) => out += line); | ||
|
||
const session = await child.connectInspectorSession(); | ||
|
||
const commands = [ | ||
{ 'method': 'Runtime.enable' }, | ||
{ 'method': 'Runtime.runIfWaitingForDebugger' } | ||
]; | ||
|
||
session.send(commands); | ||
|
||
const msg = await session.waitForNotification('Runtime.consoleAPICalled'); | ||
|
||
assert.strictEqual(msg.params.type, 'log'); | ||
assert.deepStrictEqual(msg.params.args, [{ | ||
type: 'string', | ||
value: 'hello world' | ||
}]); | ||
assert.strictEqual(out, ''); | ||
|
||
session.disconnect(); | ||
} | ||
|
||
common.crashOnUnhandledRejection(); | ||
runTest(); |
@mcollina
Can you explain this bit some more.
Is the original console (the one not produced by the lib/console) automatically piped to the inspector?