9

I have this curiosity,

Is it, in some way, possible to inject javascript in my page and execute it and debug it? As you do with the console, but in the console you can't pause and watch variables.

Is it possible to debug code that i put through console? Why isn't it possible to debug code received via XHR?

Thanks!

Andr
  • 617
  • 2
  • 9
  • 24

2 Answers2

12

One trick I learned today from Chromium is that if you place the word:

debugger;

Right before the statement you want to debug. It will break on the debugger. It is really useful for injected scripts.

Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90
  • But this word must be placed there before paged is fetched. Does it work if you put it with edit? Anyway, how do you debug on XHR? – Andr Mar 11 '11 at 17:51
  • The exact same way. In your code that your injecting, you place that word that is the only way you can debug using debugger. – Mohamed Mansour Mar 12 '11 at 14:40
0

yes, its possible to include the javascript function in our webpage by using

window.onload = function fun(){alert("test");}

with in this event u can give a statement or any function.

Sakthi
  • 363
  • 1
  • 13
  • Yes, but this occurs only once. I want to put code after my page is loaded and understand it in the debugger. Nice trick, though. – Andr Mar 11 '11 at 17:49
  • s brother u give your code with in the function or in onload event. your code will execute at the end of your page load. – Sakthi Mar 12 '11 at 12:42
  • yea. but it don't want to be executed only at pageload. I want to: copy paste a code and execute it based on the data of the page. – Andr Mar 12 '11 at 14:21
  • k.. if your executing the based on the data, u must check the html element. u do the same here also brother. by using these script var spanArray = document.getElementsByTagName('span'); alert(spanArray[0].innerHTML); – Sakthi Mar 13 '11 at 16:40