24

Is it possible to view JavaScript function calls in the browser's JavaScript console? I know you can view XHR, but can you view function calls?

For example, I hover my mouse over some element on a page and a div pops up. I know there was a JavaScript function that was called to show the popup so it would be nice to be able to view this call in the console so I can see what function was called.

Am I missing something or is this not possible?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
styfle
  • 22,361
  • 27
  • 86
  • 128
  • Try also https://javascriptweblog.wordpress.com/2010/06/01/a-tracer-utility-in-2kb/ - it can do a function call trace – sdaau Mar 01 '17 at 11:27

3 Answers3

12

So basically you want to view JS calls in real-time?

The Firebug extension on Firefox offers that (http://getfirebug.com/javascript).

Basically, what you want to do is find your function within your code, then set a breakpoint on it. You should then be able to step through execution on it, just like a normal debugger. It shouldn't be hard to find the JS function associated with a and a particular event (e.g. mouseover) on that - is this page in question using straight JS or a framework? And if so, which one?

Google Chrome's built-in developer tools offer a smaller subset - depending on what you want, the Profile tab on it might be useful?

What exactly do you need to trace this JS function for? We might be able to recommend a better tool for you based on your particular need.

FullStackDeveloper
  • 910
  • 1
  • 16
  • 40
victorhooi
  • 16,775
  • 22
  • 90
  • 113
  • 4
    The debugger is a good choice if I know what function I'm looking for. But sometimes it's not as easy as looking for a onhover attribute. For example, you can attach a function to all elements with a specific class using JQuery. There is nothing specific I am looking for. I just like to view the source of pages like facebook and try to figure out what's going on. Viewing which function was called would be really helpful. – styfle Apr 15 '11 at 03:03
  • It doesn't matter if it's your site. Download Firebug and goto the script tab - it allows you to 'pause' execution, and then step through it. It can be become very detailed very quickly. Just be warned though that most live code is usually minified/obfuscated so it might be: v()->r();a=2;t++["$gg"]..... etc – Chris Apr 15 '11 at 03:33
  • @Chris Yes I know I can use the debugger on another site, but I don't know what I'm looking for because I don't know what function was called, so setting a break point won't help. And as you mention, a lot of javascript is minified so it's all on one line anyway. – styfle Apr 15 '11 at 03:53
  • 5
    Yep exactly. But you don't need to set a break point, just click the pause button, and perform the action that you want to watch – Chris Apr 15 '11 at 04:13
  • @Chris Thank you! The pause button works perfectly in Firebug. In Chrome I can't seem to get it to work properly and my extensions (like adblock) get in the way :/ – styfle Apr 19 '11 at 00:26
  • If a function is being called from 5 different places can we distinguish that a particular call was made from 2nd place or the 5th place? – techie_28 Aug 11 '16 at 08:20
8

Check into the Firebug Profiler you can use it to see a break down of what's going on without having to manually add in console.log statements.

To use the profiler, just go to the Console tab and click the "Profile" button. Then use your app for a bit or reload the page and then click the "Profile" button again. You'll then see a detailed report that shows what functions were called and how much time each one took.

http://michaelsync.net/2007/09/10/firebug-tutorial-logging-profiling-and-commandline-part-ii

Understanding Firebug profiler output

Community
  • 1
  • 1
SavoryBytes
  • 35,571
  • 4
  • 52
  • 61
2

Not unless you explicitly attach that information to the DOM.

You can, however, set breakpoints in the developers tools for some browsers, such as Safari, Chrome and Firebug for Firefox.

alex
  • 479,566
  • 201
  • 878
  • 984