Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.