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!

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
The exact same way. In your code that your injecting, you place that word that is the only way you can debug using debugger.
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.

4 Comments

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.