Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to trace back a javascript function call?

I need a definitive way to figure out what Javascript is modifying a form value? The best I've been able to do is:

$(function(){
    console.log($("input[name=Email]").val());
});

But the value has not been changed by the point that this executes.

like image 240
Ben Dauphinee Avatar asked Feb 12 '12 15:02

Ben Dauphinee


1 Answers

There's a new way to do this in Chrome and Firefox: console.trace

See here:

https://developer.mozilla.org/en-US/docs/Web/API/console.trace

In web inspector:

> console.trace()
console.trace() VM251:2
(anonymous function) VM251:2
InjectedScript._evaluateOn VM223:581
InjectedScript._evaluateAndWrap VM223:540
InjectedScript.evaluate VM223:459
undefined

So to modify the accepted answer:

$('input#myInputAbove').change(function(){
    console.trace(); // No breakpoint needed anymore.
});
like image 114
Bjorn Avatar answered Sep 27 '22 20:09

Bjorn