Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add debugging blackbox section #490

Merged
merged 3 commits into from
Aug 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions debugging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,65 @@ Name | Sponsor | Protocol available | State |
[Chrome DevTools]: https://github.com/ChromeDevTools/devtools-frontend
[Theseus]: https://github.com/adobe-research/theseus


## Blackbox

Blackbox is a popular term that allows debugging user-land code without touching in their internals.

For futher reference in nodejs debugging follow [these instructions](https://nodejs.org/en/docs/guides/debugging-getting-started/).

### Enabling Blackbox through UI

// TODO: waiting https://github.com/GoogleChrome/developer.chrome.com/issues/1074 resolution and point to this tutorial.

### Enabling Blackbox through CLI

Let's create a file called `example-blackbox.js` to simulate a blackbox usage

```js
module.exports = {
doSomethingAsync: async () => {
debugger
console.log('Async done')
}
}
```

Then we have our `index.js` file

```js
const { doSomethingAsync } = require('./example-blackbox')
async function main() {
await doSomethingAsync()
console.log('Done!')
}

main()
```

Start debugging using CLI:

```console
node inspect index.js
```

and enable the blackbox by calling [`Debugger.setBlackBoxPatterns`](https://chromedevtools.github.io/devtools-protocol/tot/Debugger/#method-setBlackboxPatterns) and passing the ignore regex, in our case a simple `example-blackbox.js`:

```console
debug> Debugger.setBlackboxPatterns({ patterns: ['example-blackbox.js'] })
```

Afterall, perform a `continue` and see the script be running without stopping into `example-blackbox.js` function.

```console
debug> continue
RafaelGSS marked this conversation as resolved.
Show resolved Hide resolved
< Async done
<
< Done!
<
< Waiting for the debugger to disconnect...
```

### Additional information

The `blackbox` term was replaced by `ignore-list` at Google Chrome Dev Tools in latest versions.