dede
dede

Reputation: 805

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)

Upvotes: 6

Views: 9737

Answers (4)

Ujjwal Kumar Gupta
Ujjwal Kumar Gupta

Reputation: 2376

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.

Upvotes: 2

Alexander Fresh
Alexander Fresh

Reputation: 92

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

Upvotes: 1

mkk
mkk

Reputation: 7693

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

Upvotes: 1

jfriend00
jfriend00

Reputation: 707158

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.

Upvotes: 6

Related Questions