Is it possible to change javascript variable values while debugging in Google Chrome?

Why is this answer still getting upvotes?

There is a better answer than this one after all these years, and I approve it since I’m using it all the time.
Go upvote Tyler Collier‘s answer instead. They explain that you can either modify values in the console or in the stack trace. No need for a trick.


Obsolete answer

This is now possible in chrome 35 (today as of July 11, 2014). I don’t know which version allowed it first though.

Just tested @gilly3 example on my machine and it works.

  • Open the console, in Sources and the tab Snippets, add a new snippet, paste the following code into it:

    var g_n = 0; function go() { var n = 0; var o = { n: 0 }; return g_n + n + o.n; // breakpoint here }

  • Right-click the snippet name, click ‘Run’ (this does not fire the function though)

  • Add the breakpoint at the return statement.

  • In the console below, type go()

  • and change the variable values as demonstrated below

function with local modification allowed.

and the returned result g_n + n + o.n is 30.

Leave a Comment