Using breakpoints to debug javascript code

Zack's icon

I'm trying to see if it is possible to use breakpoints to debug javascript code (I'm creating a Max for Live plugin using the Live Object Model api). I am using vscode, and I've been trying to attach the debugger to a process to get it to work, but to no avail. I made an 'attach configuration' in the launch.json file in vscode, but it expects a "type", which I set as "node" since I'm not sure what else to use (I think I read that max is using an old javascript runtime, but was hoping it might still work, maybe with some bugs). I've tried attaching it to multiple different processes (Live, Max, Max helper processes, etc), but it either doesn't work or causes Live/Max to crash. It would help if I knew exactly which process was running the javascript runtime, so I could narrow down that variable at least.

Has anyone got this to work before? Or, if you were trying to get this to work, what would you try? And if it's not possible, how hard would it really be to implement? Since javascript is not strongly typed, I feel that breakpoint debugging is even more important since many errors can occur at runtime. I am using up a lot of my time writing console logs for simple problems that would be solved in seconds with the use of breakpoints. Thanks for reading.

Iain Duncan's icon

Having written something like the JS object (my Scheme for Max) I would highly doubt this is possible, but I'd love to be told I'm wrong. The fundamental thing is that the JS engine runs *inside* the Max process, so it's not at all similar to running JS in a browser or in a node process.

But if I'm wrong and someone has made this work, I'd love to know how so I can try something similar in s4m!

Zack's icon

Yeah that is the issue, I'm not sure exactly how the JS engine is running inside the max process and what the barriers are to getting this to work. I was once debugging a VST I was creating, and all I had to do was attach my debugger to the vsthost.exe program process (which was running the VST inside it, much like Max is running the JS engine inside it). So in theory this should work, but I don't have enough experience with dealing with the JS engine itself to figure it out.