For example if I run on some page in Chrome with following code:
<div onclick="someFunction('test')"></div>
I would like to know which js file contains "someFunction". Is it possible and how? (I suppose it could be done with debugging but don't know how)
For example if I run on some page in Chrome with following code:
<div onclick="someFunction('test')"></div>
I would like to know which js file contains "someFunction". Is it possible and how? (I suppose it could be done with debugging but don't know how)
Share Improve this question edited Aug 5, 2017 at 7:06 Cœur 38.7k26 gold badges203 silver badges277 bronze badges asked Sep 6, 2011 at 0:06 dededede 8053 gold badges11 silver badges26 bronze badges 5- 1 Go into devtools and look for 'function someFunction' in the search bar at the top right. Then just click through each js file till you find it. Shoudln't take that long – James Hay Commented Sep 6, 2011 at 0:10
- That will do the job but it could be slow if that page has a lot of js files, so I would need to go through each file and do search on every page. I was thinking more about some shortcut if it exist that will find it faster (one click for example or something like that)? – dede Commented Sep 6, 2011 at 0:19
- Well I'm not sure if such a shortcut exists, but how many js files are you really going to have on a page? I can find a function from 10 js files in like 15 seconds. – James Hay Commented Sep 6, 2011 at 1:41
- @dede, you don't need to access it each file. Just put 'function someFunction' in the search box on the right side after you click on the 'Scripts' tab. And click search and this will direct you automatically to each file that contains 'function someFunction'. – ace Commented Sep 6, 2011 at 4:20
- stackoverflow./questions/41146373/… – Bergi Commented Jun 30, 2022 at 14:47
4 Answers
Reset to default 6In Firefox with Web Developer add-on, Information/View Javascript/Expand All, search for "someFunction".
There are of course, a lot of other ways to do this too, but this add-on puts all JS from the page into one browser which makes it simple to search for anything page-wide.
Write the function name in google console without parenthesis e.g- for function submit(a,b) - i want to know where is the submit function.
just write submit in the console.The output will be definition of the function. Click on the output, you will be redirected to the function.You can see the file name at the top of the developer tools in source tab.
what I do is: [ Assuming you have access to the source code ]
grep -r "function someFunction" .
where .
is directory where to begin recursive search for the pattern. It will show you all files which contains pattern "function someFunction".
By the way, if you have a lot of hits but you want to search in the directory which generates them, you can discard results that contains:
grep -r "function someFunction" | grep -v "withouth this text"
hope that helps! on windows maybe you can use this with cygwin ?
This of course will not work if someFunction is hosted on external host...
Try to save page in file system (menu -> save page as -> web bage pletely) and find you function in files by text searcher.