Skip to content

Instantly share code, notes, and snippets.

@chrisbateman
Last active January 10, 2019 08:25
Show Gist options
  • Save chrisbateman/db337ca37846c3bc6739 to your computer and use it in GitHub Desktop.
Save chrisbateman/db337ca37846c3bc6739 to your computer and use it in GitHub Desktop.
Bookmarklet for logging the current document.activeElement

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