Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging onFocus event using Chrome Developer Tools? Can't return focus after break point

I'm trying to debug a JavaScript onFocus event attached to a bunch of text boxes on a page. The bug occurs when selecting a text box and then tabbing to the next text box. I'm trying to debug this by placing a break point in the onFocus event using the Chrome Developer Tools. The problem I'm facing is that when I select a text box and the break point is caught, Chrome Developer Tools steals focus and does not return it, so I can't tab to the next text box. Anyone have an idea for a work around? I guess I can resort to alert statements to print all of the information I need without using Chrome Developer Tools......

like image 538
busoni34 Avatar asked Jan 23 '12 20:01

busoni34


People also ask

How do I get focus on Google Chrome?

Chrome DevTools provides the ability of tracking the focused element. This live expression will represent the active element which has the focus currently. You can right click on the expression's result and then choose Reveal in Elements panel to inspect the focused element.


3 Answers

Chrome Dev Tools includes a Play/Pause button both in the Inspector and as an overlay to the webpage. Using the overlay prevents focus from landing on the Inspector.

Also, I've found the following type of logging solution to be easier to track than the interval method (thanks to less redundancy and the ability to pick up on changes that occur more rapidly than the interval):

$('*').on('focus blur', function(event) {console.log(event.type + " to:"); console.log(document.activeElement);});
like image 55
aminimalanimal Avatar answered Oct 31 '22 18:10

aminimalanimal


One option for debugging tricky cases is to set an interval to poll the focus in the console.

setInterval(function() {console.log($(':focus')); }, 1000);

Type this in the console (update it to include whatever details you are interested in), hit enter, and then keep the console where you can see it while you do stuff in your UI.

*MDN docs for setInerval()

like image 27
Malcolm Dwyer Avatar answered Oct 31 '22 17:10

Malcolm Dwyer


You are right, Chrome DevTools receive focus and do not restore it when you switch back to the debugged page. Feel free to file a bug at http://new.crbug.com (make sure you start the summary with "DevTools: " so that the bug can be assigned to the appropriate team as quickly as possible.)

On a side note, console.log() is a slightly better alternative to alert() as it allows formatted output.

like image 39
Alexander Pavlov Avatar answered Oct 31 '22 17:10

Alexander Pavlov