One way would be to check if there is a .shadowRoot property on an element, however I need to return a boolean before the page is rendered.
Shadow DOM (V1) on Android Browser is fully supported on 97-103, partially supported on None of the versions, and not supported on 2.3-4 Android Browser versions. Shadow DOM (V1) on Opera Mobile is fully supported on 64-64, partially supported on None of the versions, and not supported on 10-12 Opera Mobile versions.
To identify Shadow DOM:Open Developer tools (press the shortcut keys Fn+F12). On the Elements tab, expand the <body> element and the first element inside the <body> element and notice the #shadow-root line.
Open Dev tool by pressing F12. Click on the cog icon in the right top. Enable option "Show Shadow DOM" under Elements category. Go to Elements panel and you will see the component DOM with all styles.
Feature detection and browser support #Declarative Shadow DOM is available in Chrome 90 and Edge 91.
One simple feature test would be:
if (document.head.createShadowRoot || document.head.attachShadow) {
// I can shadow DOM
} else {
// I can't
}
This will work even if you include the script in the head section and assumes no malicious scripts were added prior to yours (a safe assumption).
Currently, Chrome, Opera, and derived browsers (like Android browsers) support it. For more information, visit: https://caniuse.com/#feat=shadowdomv1 and http://caniuse.com/#feat=shadowdom
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With