Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save moro-programmer/b82eea049e8583038fcc to your computer and use it in GitHub Desktop.
Save moro-programmer/b82eea049e8583038fcc to your computer and use it in GitHub Desktop.

Bookmarklet: Active Element Logger

This will log the current document.activeElement to the console. Useful when debugging keyboard focus issues. Click once to turn it on, click again to turn it off.

Unfortunately, markdown gists aren't allowed to include JS in links, or this would work:

Active Element Logger

So you'll have to add this to your bookmarks the hard way:

javascript:(function(){if(window._activeElInterval){clearInterval(window._activeElInterval);delete window._activeElInterval;}else{var activeEl;window._activeElInterval=setInterval(function(){var currentActiveEl=document.activeElement;if(currentActiveEl!==activeEl){activeEl=currentActiveEl;console.log(activeEl);}},200);}})();
(function() {
if (window._activeElInterval) {
clearInterval(window._activeElInterval);
delete window._activeElInterval;
} else {
var activeEl;
window._activeElInterval = setInterval(function() {
var currentActiveEl = document.activeElement;
if (currentActiveEl !== activeEl) {
activeEl = currentActiveEl;
console.log(activeEl);
}
}, 200);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment