Last active
February 1, 2024 15:23
-
-
Save geotrev/32e8c10075494b08f907bd9eebde9fdc to your computer and use it in GitHub Desktop.
Active Element Live Expression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This script recursively checks `shadowRoot`s and `contentDocument`s until the true `activeElement` is found. | |
* | |
* HOW TO USE: Copy and paste this into your Chrome dev tools in the `Create live expression` input. | |
*/ | |
(function(){function d(){var u=arguments[0]||document.activeElement;if(u.shadowRoot&&u.shadowRoot.activeElement){return d(u.shadowRoot.activeElement)}if(u.contentDocument&&u.contentDocument.activeElement){return d(u.contentDocument.activeElement)}return u}return d()})(); | |
/** | |
Unminified version: | |
(function getActiveElement(el = document.activeElement) { | |
if (el.shadowRoot && el.shadowRoot.activeElement) { | |
return getActiveElement(el.shadowRoot.activeElement) | |
} | |
if (el.contentDocument && el.contentDocument.activeElement) { | |
return getActiveElement(el.contentDocument.activeElement) | |
} | |
return el | |
})() | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment