# v8-debug

> v8 debugger extending API

Latest version **1.0.1** (published 2017-03-28) · 0 weekly downloads

## Install

```sh
npm install v8-debug
pnpm add v8-debug
yarn add v8-debug
bun add v8-debug
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-03-28 |
| First published | 2014-06-26 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 44 |
| Author | 3y3 Ghoti |
| Maintainers | 3y3, bajtos |
| Keywords | v8, debugger |

## Links

- npm: https://www.npmjs.com/package/v8-debug
- Repository: https://github.com/node-inspector/v8-debug
- Homepage: http://github.com/node-inspector/v8-debug
- Issues: https://github.com/node-inspector/v8-debug/issues
- npm.io page: https://npm.io/package/v8-debug

## Dependencies (2)

- [nan](https://npm.io/package/nan.md) ^2.3.2
- [node-pre-gyp](https://npm.io/package/node-pre-gyp.md) ^0.6.5

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-03-28
- 1.0.0 — 2017-03-23
- 0.7.7 — 2016-05-10
- 0.7.6 — 2016-05-08
- 0.7.5 — 2016-05-08
- 0.7.3 — 2016-04-27
- 0.7.1 — 2016-01-25
- 0.7.0 — 2015-12-06
- 0.6.2 — 2015-12-06
- 0.6.1 — 2015-11-29
- 0.6.0 — 2015-11-24
- 0.5.4 — 2015-09-17
- 0.5.3 — 2015-09-13
- 0.5.2 — 2015-08-09
- 0.5.1 — 2015-08-08
- … 21 more at https://npm.io/package/v8-debug/versions

## README

[![Build Status](https://travis-ci.org/node-inspector/v8-debug.svg?branch=master)](https://travis-ci.org/node-inspector/v8-debug)
[![Build status](https://ci.appveyor.com/api/projects/status/rb02h15b61xyryhx/branch/master?svg=true)](https://ci.appveyor.com/project/3y3/v8-debug-145/branch/master)
[![npm version](https://badge.fury.io/js/v8-debug.svg)](http://badge.fury.io/js/v8-debug)

# v8-debug
Provides extending API for [node](http://github.com/ry/node) internal debugger protocol (based on [v8 debugger protocol](https://code.google.com/p/v8/wiki/DebuggerProtocol))

This is a part of [node-inspector](http://github.com/node-inspector/node-inspector).

## Installation
```
npm install v8-debug
```
## API

### registerCommand(name, callback)
Registers new debug processor command, like `lookup`.

`callback` accepts two arguments - **request** and **response**.

You need to modify `response.body` if you want to return something to caller.
```js
debug.registerCommand('_lookup', function(request, response) {
  var test = request.attributes;
  //do someting here
  //and modify response
  response.body = {
    test: test
  };
});
```

### registerEvent(eventName)
This is a shortcut for:
```js
debug.registerCommand('someEvent', debug.commandToEvent);
```

### execCommand(commandName, attributes)
Calls debug processor command like 'lookup'.

`attributes` will be passed to `registerCommand.callback` as `request.attributes`.

`attributes` needs to be valid JSON object.
```js
debug.registerCommand('_lookup', function(request, response) {
  var test = request.attributes;
  //do someting here
  //and modify response
  response.body = {
    test: test
  };
});

debug.execCommand('_lookup', { attr: 'test' });
```

### emitEvent(eventName, attributes)
This is a semantic alias for `execCommand`
```js
debug.emitEvent('myEvent', { attr: 'test' });
```

### commandToEvent(request, response)
`response` object has a different structure for commands and events.

By default `registerCommand.callback` receives command's response.

This is a small converter.
```js
debug.registerCommand('someEvent1', function(request, response) {
  debug.commandToEvent(request, response);
});

debug.registerCommand('someEvent2', debug.commandToEvent);
```
Use `debug.registerEvent` instead of this.

### runInDebugContext(script)
(alias `get`)

Evaluates string or function (will be stringifyed) in debug context.
```js
var MakeMirror = debug.get('MakeMirror');
var mirror = MakeMirror({ test: 1 });
```

### getFromFrame(index, value)
Tries to receive a `value` from targeted frame scopes
```js
function a(options) {
  //...
  b();
}

function b() {
  // There is no info about `options` object
  var options = debug.getFromFrame(1, 'options');
}
```

### enableWebkitProtocol()
Enables experimental usage of WebKit protocol

### registerAgentCommand(command, parameters, callback)
Experimental method for registering WebKit protocol handlers

## Usage

Simple console.log checking
```js
var debug = require('v8-debug');

debug.registerEvent('console.log');

console.log = (function(fn) {
  return function() {
    debug.emitEvent('console.log', {message: arguments[0]} /*, userdata*/);
    return fn.apply(console, arguments);
  }
} (console.log));
```

For more experience see [protocol documentation](https://github.com/buggerjs/bugger-v8-client/blob/master/PROTOCOL.md)

---
_Source: https://npm.io/package/v8-debug · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
