can I turn off optimization, so in-scope variables from closures aren't "optimized out" can I turn off optimization, so in-scope variables from closures aren't "optimized out" google-chrome google-chrome

can I turn off optimization, so in-scope variables from closures aren't "optimized out"


You can get access to all variables by wrapping the debugger statement in an eval like this: eval("debugger;");. This hacky solution adds another anonymous function to the call stack though and it is obviously of no use for breakpoints that are set manually in DevTools.

This does not seem to be a very good solution, but since it is the only one that achieves the intended behaviour so far, I am posting it as an answer.


Google Chrome uses the V8 JS-Engine, you can enable native calls to it with the --allow-natives-syntax flag, this exposes many useful debugging functions (full list here) like the one you are looking for: %NeverOptimizeFunction(). Without this flag, these calls would be illegal syntax so be careful when deploying (or use the v8-Natives library).

To enable this feature just open chrome with --js-flags="--allow-natives-syntax" (only use this for debugging of trusted websites, as this can give untrusted js code access to things you really do not want it to have access to).


I really hope this question has a REAL answer. What follows isn't a real answer, it's a makeshift. I wrote a helper tool with which you can create stupid helper code of the form if (false) { console.log(variables, from, closures); } (see screen shot in question) using static analysis - you paste in your code, the stupid statement is created, you can copy it, then you don't need to type it. I don't know if that helps a lot, since all this copying and pasting also takes time, but that's what I got.

screenshot

fiddle