Skip to content Skip to sidebar Skip to footer

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 tr

Solution 1:

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

Solution 2:

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()

Solution 3:

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.

Post a Comment for "Debugging Onfocus Event Using Chrome Developer Tools? Can't Return Focus After Break Point"