Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find .js file where certain js function is declared (from Chrome)?

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)

like image 574
dede Avatar asked Sep 06 '11 00:09

dede


3 Answers

In 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.

like image 71
jfriend00 Avatar answered Nov 14 '22 23:11

jfriend00


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...

like image 30
mkk Avatar answered Nov 14 '22 23:11

mkk


Try to save page in file system (menu -> save page as -> web bage completely) and find you function in files by text searcher.

like image 29
Alexander Fresh Avatar answered Nov 15 '22 00:11

Alexander Fresh