Search code examples
javascriptgoogle-chromedeveloper-tools

Break when new variable is defined/created in browser


Is it possible to get chrome dev tool or firebug to break when a new variable is defined in an object? The object that I am interested is specifically the "window" object.

I get

Uncaught ReferenceError: remoteUser is not defined

for "if(remoteUser)" in Chrome Developer Tools. The error doesn't occur everytime the page is visited, so I want to findout the line where the variable does get defined and get set to a value.

I could search the javascript files for that variable, but that route is very tedious.


Solution

  • There's a built-in thing in Firefox: watch

    One can watch even not-yet defined variable.

    Usage: window.watch("remoteUser", callback)