2

Ok, so I need to find the source code of a particular javascript function on a website. (The specifics do not really matter unless there is no way to do what it is that I am asking)

I can see the function call in a link of html code onclick="inbox.sendMessage();"

I know that the function does work because if I use a plugin a can call the function on that page, however, I have searched every .js file is referenced in that page, and none of them contain a function called sendMessage.

What I am asking is, is there a way to follow the code back to the source, perhaps if there was a way to debug the html and break when the onclick is triggered and then step into the function to see its source, but I do not know how I can do that or if it is even possible. Any help will be greatly appreciated, Thanks.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
arch
  • 477
  • 1
  • 9
  • 17

4 Answers4

4

I guess you could do :

inbox.sendMessage

In the webconsole. (the function name without the parenthesis)
It will print out the source code of the function.

Yoann
  • 3,020
  • 1
  • 24
  • 34
  • Which web console did this work in? I tried with Firefox 26, Menu > Web Developer > Web Console (Ctrl+Shift+K) and it returns [object Function] which when clicked puts a block on the right for [object Function] but I can't sort out where in there it shows the source. – jla Feb 05 '14 at 16:42
  • It works in Firefox using Firebug and in Chrome. http://stackoverflow.com/a/1368185/101151 http://stackoverflow.com/a/9828973/101151 – jla Feb 05 '14 at 16:57
2

I usually use Opera, and in that at least this is what I do:

  1. Open Opera Dragonfly (Ctrl + Shift + I).
  2. Click on the HTML tag with the onclick handler.
  3. Go to the listeners tab in the right hand side column.
  4. See the listener for the click event. It shows you the file and line number.
Aadit M Shah
  • 72,912
  • 30
  • 168
  • 299
2

sendMessage could be declared as:

var inbox{
  sendMesssage:function(){
  }
}

//or

function inbox(){
  this.sendMessage=function(){
  }
}

// or

inbox.sendMessage=function(){}

// or ...

So looking for "sendMessage(" or "function sendMessage" will not find you anything.

In chrome, Internet Explorer and Firefox (with firebug) you can hit F12 and go to debug, there you can check the scripts that have been loaded as there might have been scripts loaded dynamically.

HMR
  • 37,593
  • 24
  • 91
  • 160
0
#!/usr/bin/env ruby


Dir::glob("*").each do |name| 

        lineCount = 1

        File.open(name, "r").each do |line|
            puts "\nFile name: " + name + "\nline: " + lineCount.to_s  if line =~ /inbox.sendMessage/  && name != "findfunction.rb"
            lineCount += 1
        end



end

Wrote a quick ruby script to help you out. To execute, first make sure you have a ruby interpreter on your machine then place the script in the directory with all your relevant files. load up a command line terminal, navigate to said directory and type "ruby findfunction.rb".

It will tell you all instances (files + line number) of "inbox.sendMessage".

MeMory LEAk99
  • 295
  • 1
  • 6
  • 12