3

Is there anyway to inject JavaScript so that I can tell every time JavaScript is executed in the web page?

For instance suppose a button triggers some function foo("bar") ... I would like to inject JavaScript such that when a user clicks the button another function is called first and passed the function name "foo" and arguments "bar".

The reason I want to do this is that I'm trying to mirror one users actions to another remote user -- so that as one user clicks I could intercept the JavaScript function send it over via node.js to the other user and execute the same function on the second users side programatically.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user491880
  • 4,709
  • 4
  • 28
  • 49
  • 1
    You plan to do this for all browsers? Not Going to Happen. – John Saunders Oct 20 '11 at 01:38
  • What if the button executes code that isn't a function call, e.g., `onclick="this.disabled=true;"`? And my example points out another issue: how do you want to handle setting of `this` within event handlers? – nnnnnn Oct 20 '11 at 01:39
  • 1
    Similar question here: http://stackoverflow.com/questions/5033836/adding-console-log-to-every-function-automatically – dgilland Oct 20 '11 at 01:42
  • How much control do you have over the environment(s)? Is this your JavaScript being served from your servers? – Richard JP Le Guen Oct 22 '11 at 13:21

1 Answers1

0
  1. load the webpage in google chrome
  2. open the developer tools (either via the wrench menu or with shift+ctrl+j)
  3. activate the Scripts tab
  4. click the little 'pause' symbol to the right of the page

Now, as soon as any javascript gets executed, chrome will show you the code and wait for your instructions.

Tobi Oetiker
  • 5,167
  • 2
  • 17
  • 23