4 Oct 2022

Debug into userFunction

Default blog image

As shown here you can create a userFunction and pass it to executeUserFunction to run in a worker. Because the code for it is placed in a blob generated on the fly, it's not straight-forward to debug into it. You can of course place console.log() functions in the code to track what's going on inside it, but if you want to actually debug into it, step through the code, you can follow the below steps.

1) Make the app break on executeUserFunction() 

2) When that happens place a breakpoint somewhere after importScripts() inside doExecuteCode() - e.g. on the "if (!self.userFunction) {" line 

3) Once that breakpoint is hit you can find the blob/file generated for your userFunction that importScript() loaded into the browser and can place a breakpoint inside it

... OR ... 

Just simply add keyword "debugger" to your code and let that serve as a breakpoint 😄 (Thanks Petr! Completely forgot about that 😅)

Note: the debugger window needs to be open for that to work