mohamad salama
mohamad salama

Reputation: 174

Javascript Debuging tool from the browser

Is there a way to debug the page with browser console or firebug to know how many times a specific Javascript function is called while loading the page ?

Upvotes: 1

Views: 63

Answers (2)

hon2a
hon2a

Reputation: 7214

As @SamGreenhalgh pointed out, in Google Chrome, you can simply open the Developer Tools ([Ctrl]+[Shift]+J), find your script in Sources tab, and add

console.count('some label');

right into the body of the function you wish to observe. This will print out

some label: {N}

into the console each time console.count is called at that point with that label (see documentation).

Upvotes: 1

T.J. Crowder
T.J. Crowder

Reputation: 1075537

You can set a breakpoint on the function, reload the page, and count how many times you have to press the Continue button.

In the dev tools of most browsers (and in Firebug), you'd do that something like this:

  1. Go to the page

  2. Open the dev tools (via menus, or press F12 on most browsers, etc.)

  3. Navigate to the "Source" pane (the name varies, but it's usually something like that)

  4. Find the function in the scripts. (Chrome's dev tools have a great feature: Ctrl+Shift+F does a search through all loaded scripts.)

  5. Click the gutter to the left of the function to set a breakpoint

Then reload and count. I'm not aware of an automated way to do it.

Upvotes: 1

Related Questions