laverdet / isolated-vm

Secure & isolated JS environments for nodejs
ISC License
2.19k stars 154 forks source link

how can i set js breakpoint on first line, Implement the stopOnEntry #474

Closed AngDH closed 5 months ago

AngDH commented 6 months ago

In the demo at https://github.com/laverdet/isolated-vm/blob/main/inspector-example.js, the JavaScript code used is as follows:

let script = await isolate.compileScript('for(;;)debugger;', { filename: 'example.js' });

// for(;;)debugger; // use for loop stop script Implement the stopOnEntry effect

Now, I want to debug my JavaScript code ,Here is what I am currently doing: //first line code let flag = 0; while (flag === 0) { debugger; }; // after code //..... Are there any good solutions to improve this? I want the debugger to break at the first line of code automatically.

laverdet commented 5 months ago

It looks like inspector sessions haven't worked for a while. This was fixed in b1d9a29cf7913d1c1efdd3b29337b35954d8d022. You'll have to get that from 5.0.1 when I release it.

I also provided an example of how you can simulate something like node's --inspect-brk option: https://github.com/laverdet/isolated-vm/blob/b1d9a29cf7913d1c1efdd3b29337b35954d8d022/inspector-example.js#L14-L17

AngDH commented 5 months ago

That's awesome ! Debugging is so convenient just like "node's --inspect-brk option "