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

前端 未结 3 2019
孤独总比滥情好
孤独总比滥情好 2021-02-07 07:16

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

相关标签:
3条回答
  • 2021-02-07 08:06

    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.

    0 讨论(0)
  • 2021-02-07 08:07

    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);});
    
    0 讨论(0)
  • 2021-02-07 08:19

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

    0 讨论(0)
提交回复
热议问题