Find when an object is modified in JavaScript
There's an object in your js app that is mysteriously updated. Your app deals with lots of real time events and you don't know where to start. Object.observe is the solution.
Object.observe is part of ES6 and is notably implemented by Chrome. The cool thing is that you can use it on-the-fly, without having to change your code.
Just open the js console and break somewhere where you object is in scope, before the unexpected change occurs. Then, just type:
Object.observe(myObj, function () {
debugger;
});
Then, do the action that triggers the unexpected change and look in the call stack for your code.
Written by Laurent Perrin
Related protips
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside