Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I find where a javascript function is called in a website?

There’s a function in the external JavaScript for a website (not my own) and I want to know where it’s used, since apparently it is never run. I’ve tried every action on the website and nothing makes it run. The only way I can think of is reviewing event listeners on every element until I find it but that would take ages. Is there something in the inspect element menu where I can look up where a piece of JavaScript code is running, sort of like the inverse of looking at event listeners on an element, or something equivalent I can do using other software? If it helps, the JavaScript file is ran just one script tag in the HTML.

The website is a relatively small image editor. I’ve done everything I can on it and the code isn’t running, I’ve tried looking for ways I can view references to the function in the inspect menu too, including using console.trace(), but I don’t think that helps in my case since the code isn’t run, unless I’m misunderstanding how it works.

Edit: clarifications that the function I’m interested in doesn’t run by any of my actions, fluff removed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

So first, I have to say that what you are asking to do is not technically possible. Because you can do something like global["t" + "e" + "s" + "t"]() to call a function in the global scope called "test" you can’t be certain that you will find every reference. And there is no tool that could find every reference to the function.

That said, I would recommend using the dev tools debugger in Chrome or Firefox, go to the debugger part, and use the search. If no results come up for the name of the function in question, it is probably unused code.

I’m curious why you are doing this though. It is a very strange thing to want to do.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading