I'm actually building a web app using custom Polymer elements (which is based on web-components and shadow-dom) but I encountered a serious problem.
I want this app to run on an Android 4.4 WebView, but I experienced some issues with the shadow-dom when testing the app on the WebView, although it works perfectly fine on Chrome (Android and Desktop). This problem occurs when I try to access a shadowRoot element from CSS (with ::shadow or /deep/) or from pure js.
Here is a simple illustration of my problem :
<!-- custom-elt.html -->
<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="custom-elt">
<template>
<div id="elt">some content</div>
</template>
<script>
Polymer('custom-elt',{
getElt: function(){
return this.shadowRoot.getElementById('elt');
}
});
</script>
</polymer-element>
// script.js
window.addEventListener('polymer-ready',function(){
var e = document.getElementsByTagName('custom-elt')[0];
alert(e.getElt().innerHTML);
});
Works perfectly on Chrome, but not in the WebView. According to caniuse.com, shadow-dom is supported by Android 4.4 browser (which is used by the WebView right ?) with the 'webkit' prefix (http://caniuse.com/#feat=shadowdom), but I didn't find a way to use it with the prefix.
Any solution ?
Thanks
Baptiste
Shadow DOM (V1) on Chrome is fully supported on 53-106, partially supported on None of the versions, and not supported on 4-52 Chrome versions.
Shadow DOM is a new DOM feature that helps you build components. You can think of shadow DOM as a scoped subtree inside your element. Read more on Web Fundamentals.
Work with Shadow DOM elements using RemoteWebDriver To access these Shadow DOM elements, we need to use the JavascriptExecutor executeScript() function. If you look at the DOM structure, every element that includes Shadow DOM also has a shadowRoot property that describes the underlying elements.
Click on 3 vertical dots on the top right corner of dev tools before close button. Now click on settings there you will find “Show user agent shadow DOM” checkbox under the Elements section in General Tab. By checking that button it will enable shadow dom on one's browser.
This was on the polymer site:
On browsers without native shadow DOM, use the
wrap
function to access methods and properties on your element:
wrap($0).fire('my-event');
wrap($0).myproperty
Here is more documentation on the shadowDOM and polyfill: https://www.polymer-project.org/docs/polymer/debugging.html#shadowdom
That leads me to ask, are you including the current polyfill? https://github.com/furier/WebComponents
It just changed recently with the 0.5 build and is a breaking change.
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