bare-inspector
V8 inspector support for Bare
bare-inspector — V8 inspector support for Bare. It is a native addon and requires Bare >=1.29.0.
Mirrors the Node.js inspector module.
npm i bare-inspectorUsage
const { Session } = require('bare-inspector')
const session = new Session()
session.connect()
try {
const { result } = await session.post('Runtime.evaluate', {
expression: '1 + 2'
})
console.log(result)
} catch (err) {
console.error(err)
}Heap snapshots
const { Session, HeapSnapshot } = require('bare-inspector')
const fs = require('bare-fs')
const session = new Session()
session.connect()
const snapshot = new HeapSnapshot(session)
snapshot.pipe(fs.createWriteStream('profile.heapsnapshot'))API
Console
Console.assert(condition: unknown, ...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
condition | unknown | — | The value to test; the assertion logs only when it is falsy. |
data | unknown[] | — | The values to log when condition is falsy. |
Console.clear(): void
Source
Console.DirOptions
interface DirOptions {
colors?: number
depth?: number
showHidden?: boolean
}Options for dir(): colors, depth, and showHidden, matching util.inspect()'s options of the same names.
Console.count(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the counter. |
Console.countReset(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the counter to reset. |
Console.debug(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Console.dir(object: unknown, opts?: DirOptions): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
object | unknown | — | The object to inspect. |
opts? | DirOptions | — | Inspection options: colors, depth, and showHidden. |
Console.dirxml(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Console.error(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Console.group(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log as the group heading. |
Console.groupCollapsed(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log as the group heading. |
Console.groupEnd(): void
Source
Console.info(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Console.log(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Console.profile(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the profile. |
Console.profileEnd(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the profile to stop. |
Console.table(data: unknown, props?: string[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown | — | The tabular data to display. |
props? | string[] | — | The property names to include as columns. |
Console.time(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timer. |
Console.timeEnd(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timer to stop. |
Console.timeLog(label?: string, ...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timer. |
data | unknown[] | — | Additional values to log alongside the elapsed time. |
Console.timeStamp(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timestamp marker. |
Console.trace(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log with the stack trace. |
Console.warn(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Session
new Session(onpaused?: () => boolean)
Source
Dispatches messages to the V8 inspector back-end and receives responses and notifications, mirroring Node's inspector.Session. onpaused is called whenever the debugger pauses; return true to keep the pause, or a falsy value to resume immediately.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
onpaused? | () => boolean | — | Called whenever the debugger pauses; return true to keep the pause, or a falsy value to resume immediately (the default resumes). |
Session.connect(): void
Source
Connects the session to the inspector back-end, enabling post() to send messages. A no-op if already connected or destroyed.
Session.connected: boolean
Source
Whether the session is connected and not destroyed.
Session.destroy(): void
Source
Destroys the session, releasing its inspector back-end handle. A no-op if already destroyed.
Session.destroyed: boolean
Source
Whether the session has been destroyed.
Session.post
post<T extends unknown = unknown>(method: string, cb: (err: Error, result: T) => void): Promise<T>Posts method (with optional params) to the inspector back-end. Resolves or calls cb with the result, or with an Error if the inspector returns one.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
method | string | — | The inspector protocol method name (e.g. 'Runtime.evaluate'). |
cb | (err: Error, result: T) => void | — | Called with the error or result; when given, no promise is returned. |
Returns Promise<T> — A promise settling with the inspector's response, or undefined when cb is given.
Session.InspectorSessionEvents
interface InspectorSessionEvents extends EventMap {
inspectorNotification: [message: SessionMessage]
[method: string]: [message: SessionMessage]
}The events a Session emits: inspectorNotification for every inspector notification, and one event per inspector protocol method name (e.g. 'Debugger.paused') carrying the same message.
Session.SessionMessage
interface SessionMessage {
method: string
params: Record<string, unknown>
}An inspector protocol notification: the method name and its params.
Server
new Server(opts: InspectorServerOptions)
Source
A WebSocket server exposing a Session for remote debugging, compatible with Chrome DevTools and mirroring the endpoints Node's --inspect exposes (/json/list and a WebSocket debugger URL).
Overloads:
new Server(opts: InspectorServerOptions)
new Server(port: number, opts: InspectorServerOptions)
new Server(port: number, host: string, opts?: InspectorServerOptions)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts | InspectorServerOptions | — | Options; path is the script URL reported to DevTools and defaults to require.main.path. |
Server.address(): TCPSocketAddress
Source
Returns the address the server is listening on.
Server.close(cb?: (err?: Error | null) => void): this
Source
Stops the server from accepting new connections, destroys existing connections and the underlying debugger session, and calls cb once closed.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cb? | (err?: Error | null) => void | — | Called once the underlying server has closed. |
Server.listening: boolean
Source
Whether the server is currently listening for connections.
Server.ref(): this
Source
Marks the server so the event loop won't exit while it's listening.
Server.InspectorServerEvents
interface InspectorServerEvents extends EventMap {
listening: []
}The events an inspector Server emits: listening, once the server starts listening.
Server.InspectorServerOptions
interface InspectorServerOptions {
path: URL | string
}Options for Server: path, the entry-point URL reported to DevTools as the URL of the inspected script.
Server.unref(): this
Source
Unmarks the server so the event loop can exit even while it's listening.
HeapSnapshot
new HeapSnapshot(session: Session)
Source
A readable stream of a V8 heap snapshot taken over session, using the inspector protocol's HeapProfiler.takeHeapSnapshot. Pipe it to a file (e.g. with a .heapsnapshot extension) to load it in Chrome DevTools.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
session | Session | — | The connected Session to take the snapshot over. |
bare-inspector/console
InspectorConsole
InspectorConsole.assert(condition: unknown, ...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
condition | unknown | — | The value to test; the assertion logs only when it is falsy. |
data | unknown[] | — | The values to log when condition is falsy. |
InspectorConsole.clear(): void
Source
InspectorConsole.count(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the counter. |
InspectorConsole.countReset(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the counter to reset. |
InspectorConsole.debug(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
InspectorConsole.dir(object: unknown, opts?: DirOptions): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
object | unknown | — | The object to inspect. |
opts? | DirOptions | — | Inspection options: colors, depth, and showHidden. |
InspectorConsole.dirxml(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
InspectorConsole.error(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
InspectorConsole.group(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log as the group heading. |
InspectorConsole.groupCollapsed(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log as the group heading. |
InspectorConsole.groupEnd(): void
Source
InspectorConsole.info(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
InspectorConsole.log(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
InspectorConsole.profile(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the profile. |
InspectorConsole.profileEnd(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the profile to stop. |
InspectorConsole.table(data: unknown, props?: string[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown | — | The tabular data to display. |
props? | string[] | — | The property names to include as columns. |
InspectorConsole.time(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timer. |
InspectorConsole.timeEnd(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timer to stop. |
InspectorConsole.timeLog(label?: string, ...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timer. |
data | unknown[] | — | Additional values to log alongside the elapsed time. |
InspectorConsole.timeStamp(label?: string): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
label? | string | — | The label of the timestamp marker. |
InspectorConsole.trace(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log with the stack trace. |
InspectorConsole.warn(...data: unknown[]): void
Source
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown[] | — | The values to log. |
Types
DirOptions
interface DirOptions {
colors?: number
depth?: number
showHidden?: boolean
}Options for dir(): colors, depth, and showHidden, matching util.inspect()'s options of the same names.
bare-inspector/session
InspectorSession
new InspectorSession(onpaused?: () => boolean)
Source
Dispatches messages to the V8 inspector back-end and receives responses and notifications, mirroring Node's inspector.Session. onpaused is called whenever the debugger pauses; return true to keep the pause, or a falsy value to resume immediately.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
onpaused? | () => boolean | — | Called whenever the debugger pauses; return true to keep the pause, or a falsy value to resume immediately (the default resumes). |
InspectorSession.connect(): void
Source
Connects the session to the inspector back-end, enabling post() to send messages. A no-op if already connected or destroyed.
InspectorSession.connected: boolean
Source
Whether the session is connected and not destroyed.
InspectorSession.destroy(): void
Source
Destroys the session, releasing its inspector back-end handle. A no-op if already destroyed.
InspectorSession.destroyed: boolean
Source
Whether the session has been destroyed.
InspectorSession.post
post<T extends unknown = unknown>(method: string, cb: (err: Error, result: T) => void): Promise<T>Posts method (with optional params) to the inspector back-end. Resolves or calls cb with the result, or with an Error if the inspector returns one.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
method | string | — | The inspector protocol method name (e.g. 'Runtime.evaluate'). |
cb | (err: Error, result: T) => void | — | Called with the error or result; when given, no promise is returned. |
Returns Promise<T> — A promise settling with the inspector's response, or undefined when cb is given.
Types
SessionMessage
interface SessionMessage {
method: string
params: Record<string, unknown>
}An inspector protocol notification: the method name and its params.
InspectorSessionEvents
interface InspectorSessionEvents extends EventMap {
inspectorNotification: [message: SessionMessage]
[method: string]: [message: SessionMessage]
}The events a Session emits: inspectorNotification for every inspector notification, and one event per inspector protocol method name (e.g. 'Debugger.paused') carrying the same message.
bare-inspector/server
InspectorServer
new InspectorServer(opts: InspectorServerOptions)
Source
A WebSocket server exposing a Session for remote debugging, compatible with Chrome DevTools and mirroring the endpoints Node's --inspect exposes (/json/list and a WebSocket debugger URL).
Overloads:
new InspectorServer(opts: InspectorServerOptions)
new InspectorServer(port: number, opts: InspectorServerOptions)
new InspectorServer(port: number, host: string, opts?: InspectorServerOptions)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
opts | InspectorServerOptions | — | Options; path is the script URL reported to DevTools and defaults to require.main.path. |
InspectorServer.address(): TCPSocketAddress
Source
Returns the address the server is listening on.
InspectorServer.close(cb?: (err?: Error | null) => void): this
Source
Stops the server from accepting new connections, destroys existing connections and the underlying debugger session, and calls cb once closed.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cb? | (err?: Error | null) => void | — | Called once the underlying server has closed. |
InspectorServer.listening: boolean
Source
Whether the server is currently listening for connections.
InspectorServer.ref(): this
Source
Marks the server so the event loop won't exit while it's listening.
InspectorServer.unref(): this
Source
Unmarks the server so the event loop can exit even while it's listening.
Types
InspectorServerEvents
interface InspectorServerEvents extends EventMap {
listening: []
}The events an inspector Server emits: listening, once the server starts listening.
InspectorServerOptions
interface InspectorServerOptions {
path: URL | string
}Options for Server: path, the entry-point URL reported to DevTools as the URL of the inspected script.
bare-inspector/heap-snapshot
InspectorHeapSnapshot
new InspectorHeapSnapshot(session: Session)
Source
A readable stream of a V8 heap snapshot taken over session, using the inspector protocol's HeapProfiler.takeHeapSnapshot. Pipe it to a file (e.g. with a .heapsnapshot extension) to load it in Chrome DevTools.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
session | Session | — | The connected Session to take the snapshot over. |
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.