4

I have <p> tag in my webpage and i am trying to find out which JavaScript function that adding text inside this element, is there any specific way in chrome to add listener on this tag to find out which script that writing on this tag?

5
  • The one way I know how to do this is using the timeline i developer tools (f12). So set it to record, click or do some action to change a function and then look through and see if you can find the function Commented Mar 16, 2016 at 19:42
  • 4
    You can use "Developers Tool > Profile > Collect JavaScript CPU Profile" and check which function is executing Commented Mar 16, 2016 at 19:44
  • @JagsSparrow I like your solution but it doesn't specify which element was changed by the listed actions. Commented Mar 16, 2016 at 19:47
  • It will not, but it will reduce lookup area of code Commented Mar 16, 2016 at 19:49
  • @JagsSparrow Yes you are right i voted up your answer, but i think there's better way to find the sneaky beaky script :) Commented Mar 16, 2016 at 19:56

1 Answer 1

3

The most direct (low noise) way uses a sync pause that lets you poke around in the whole call stack:

  1. Open chrome's devtools.
  2. Right-click the element in the devtools "Elements" tab to reveal the context menu
  3. Choose Break On... > Subtree Modifications.

Once the element's "innerHTML" changes, the script execution will pauses and you can view the whole call stack in the "Sources" tab, including whatever function requested the DOM change.

Certain DOM modifications like animation libraries can use a setTimeout or callback that discards much of the call stack that lead up to the change, and in those cases, a Profile might be more interesting, since the animation function should stand out like a sore thumb in a "Heavy" view.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.