LogoPear Docs
ReferencesBareModules

bare-inspector

V8 inspector support for Bare

stable

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-inspector

Usage

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

ParameterTypeDefaultDescription
conditionunknownThe value to test; the assertion logs only when it is falsy.
dataunknown[]The values to log when condition is falsy.

Console.clear(): void

Source

Console.DirOptions

interface DirOptions {
  colors?: number
  depth?: number
  showHidden?: boolean
}
Source

Options for dir(): colors, depth, and showHidden, matching util.inspect()'s options of the same names.

Console.count(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the counter.

Console.countReset(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the counter to reset.

Console.debug(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

Console.dir(object: unknown, opts?: DirOptions): void

Source

Parameters

ParameterTypeDefaultDescription
objectunknownThe object to inspect.
opts?DirOptionsInspection options: colors, depth, and showHidden.

Console.dirxml(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

Console.error(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

Console.group(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log as the group heading.

Console.groupCollapsed(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log as the group heading.

Console.groupEnd(): void

Source

Console.info(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

Console.log(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

Console.profile(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the profile.

Console.profileEnd(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the profile to stop.

Console.table(data: unknown, props?: string[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknownThe tabular data to display.
props?string[]The property names to include as columns.

Console.time(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timer.

Console.timeEnd(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timer to stop.

Console.timeLog(label?: string, ...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timer.
dataunknown[]Additional values to log alongside the elapsed time.

Console.timeStamp(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timestamp marker.

Console.trace(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log with the stack trace.

Console.warn(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]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

ParameterTypeDefaultDescription
onpaused?() => booleanCalled 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>
Source

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

ParameterTypeDefaultDescription
methodstringThe inspector protocol method name (e.g. 'Runtime.evaluate').
cb(err: Error, result: T) => voidCalled 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]
}
Source

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>
}
Source

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

ParameterTypeDefaultDescription
optsInspectorServerOptionsOptions; 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

ParameterTypeDefaultDescription
cb?(err?: Error | null) => voidCalled 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: []
}
Source

The events an inspector Server emits: listening, once the server starts listening.

Server.InspectorServerOptions

interface InspectorServerOptions {
  path: URL | string
}
Source

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

ParameterTypeDefaultDescription
sessionSessionThe connected Session to take the snapshot over.

bare-inspector/console

InspectorConsole

InspectorConsole.assert(condition: unknown, ...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
conditionunknownThe value to test; the assertion logs only when it is falsy.
dataunknown[]The values to log when condition is falsy.

InspectorConsole.clear(): void

Source

InspectorConsole.count(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the counter.

InspectorConsole.countReset(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the counter to reset.

InspectorConsole.debug(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

InspectorConsole.dir(object: unknown, opts?: DirOptions): void

Source

Parameters

ParameterTypeDefaultDescription
objectunknownThe object to inspect.
opts?DirOptionsInspection options: colors, depth, and showHidden.

InspectorConsole.dirxml(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

InspectorConsole.error(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

InspectorConsole.group(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log as the group heading.

InspectorConsole.groupCollapsed(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log as the group heading.

InspectorConsole.groupEnd(): void

Source

InspectorConsole.info(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

InspectorConsole.log(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

InspectorConsole.profile(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the profile.

InspectorConsole.profileEnd(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the profile to stop.

InspectorConsole.table(data: unknown, props?: string[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknownThe tabular data to display.
props?string[]The property names to include as columns.

InspectorConsole.time(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timer.

InspectorConsole.timeEnd(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timer to stop.

InspectorConsole.timeLog(label?: string, ...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timer.
dataunknown[]Additional values to log alongside the elapsed time.

InspectorConsole.timeStamp(label?: string): void

Source

Parameters

ParameterTypeDefaultDescription
label?stringThe label of the timestamp marker.

InspectorConsole.trace(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log with the stack trace.

InspectorConsole.warn(...data: unknown[]): void

Source

Parameters

ParameterTypeDefaultDescription
dataunknown[]The values to log.

Types

DirOptions

interface DirOptions {
  colors?: number
  depth?: number
  showHidden?: boolean
}
Source

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

ParameterTypeDefaultDescription
onpaused?() => booleanCalled 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>
Source

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

ParameterTypeDefaultDescription
methodstringThe inspector protocol method name (e.g. 'Runtime.evaluate').
cb(err: Error, result: T) => voidCalled 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>
}
Source

An inspector protocol notification: the method name and its params.

InspectorSessionEvents

interface InspectorSessionEvents extends EventMap {
  inspectorNotification: [message: SessionMessage]
  [method: string]: [message: SessionMessage]
}
Source

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

ParameterTypeDefaultDescription
optsInspectorServerOptionsOptions; 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

ParameterTypeDefaultDescription
cb?(err?: Error | null) => voidCalled 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: []
}
Source

The events an inspector Server emits: listening, once the server starts listening.

InspectorServerOptions

interface InspectorServerOptions {
  path: URL | string
}
Source

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

ParameterTypeDefaultDescription
sessionSessionThe connected Session to take the snapshot over.

See also

On this page

Usage
Heap snapshots
API
Console
Console.assert(condition: unknown, ...data: unknown[]): void
Console.clear(): void
Console.DirOptions
Console.count(label?: string): void
Console.countReset(label?: string): void
Console.debug(...data: unknown[]): void
Console.dir(object: unknown, opts?: DirOptions): void
Console.dirxml(...data: unknown[]): void
Console.error(...data: unknown[]): void
Console.group(...data: unknown[]): void
Console.groupCollapsed(...data: unknown[]): void
Console.groupEnd(): void
Console.info(...data: unknown[]): void
Console.log(...data: unknown[]): void
Console.profile(label?: string): void
Console.profileEnd(label?: string): void
Console.table(data: unknown, props?: string[]): void
Console.time(label?: string): void
Console.timeEnd(label?: string): void
Console.timeLog(label?: string, ...data: unknown[]): void
Console.timeStamp(label?: string): void
Console.trace(...data: unknown[]): void
Console.warn(...data: unknown[]): void
Session
new Session(onpaused?: () => boolean)
Session.connect(): void
Session.connected: boolean
Session.destroy(): void
Session.destroyed: boolean
Session.post
Session.InspectorSessionEvents
Session.SessionMessage
Server
new Server(opts: InspectorServerOptions)
Server.address(): TCPSocketAddress
Server.close(cb?: (err?: Error | null) => void): this
Server.listening: boolean
Server.ref(): this
Server.InspectorServerEvents
Server.InspectorServerOptions
Server.unref(): this
HeapSnapshot
new HeapSnapshot(session: Session)
bare-inspector/console
InspectorConsole
InspectorConsole.assert(condition: unknown, ...data: unknown[]): void
InspectorConsole.clear(): void
InspectorConsole.count(label?: string): void
InspectorConsole.countReset(label?: string): void
InspectorConsole.debug(...data: unknown[]): void
InspectorConsole.dir(object: unknown, opts?: DirOptions): void
InspectorConsole.dirxml(...data: unknown[]): void
InspectorConsole.error(...data: unknown[]): void
InspectorConsole.group(...data: unknown[]): void
InspectorConsole.groupCollapsed(...data: unknown[]): void
InspectorConsole.groupEnd(): void
InspectorConsole.info(...data: unknown[]): void
InspectorConsole.log(...data: unknown[]): void
InspectorConsole.profile(label?: string): void
InspectorConsole.profileEnd(label?: string): void
InspectorConsole.table(data: unknown, props?: string[]): void
InspectorConsole.time(label?: string): void
InspectorConsole.timeEnd(label?: string): void
InspectorConsole.timeLog(label?: string, ...data: unknown[]): void
InspectorConsole.timeStamp(label?: string): void
InspectorConsole.trace(...data: unknown[]): void
InspectorConsole.warn(...data: unknown[]): void
Types
DirOptions
bare-inspector/session
InspectorSession
new InspectorSession(onpaused?: () => boolean)
InspectorSession.connect(): void
InspectorSession.connected: boolean
InspectorSession.destroy(): void
InspectorSession.destroyed: boolean
InspectorSession.post
Types
SessionMessage
InspectorSessionEvents
bare-inspector/server
InspectorServer
new InspectorServer(opts: InspectorServerOptions)
InspectorServer.address(): TCPSocketAddress
InspectorServer.close(cb?: (err?: Error | null) => void): this
InspectorServer.listening: boolean
InspectorServer.ref(): this
InspectorServer.unref(): this
Types
InspectorServerEvents
InspectorServerOptions
bare-inspector/heap-snapshot
InspectorHeapSnapshot
new InspectorHeapSnapshot(session: Session)
See also