diff --git a/src/CustomElements/observe.js b/src/CustomElements/observe.js index 23c3146..6a3f3b2 100644 --- a/src/CustomElements/observe.js +++ b/src/CustomElements/observe.js @@ -289,13 +289,17 @@ function upgradeDocumentTree(doc) { } -// ensure that all ShadowRoots watch for CustomElements. +// Patch `createShadowRoot()` if Shadow DOM is available, otherwise leave +// undefined to aid feature detection of Shadow DOM. var originalCreateShadowRoot = Element.prototype.createShadowRoot; -Element.prototype.createShadowRoot = function() { - var root = originalCreateShadowRoot.call(this); - CustomElements.watchShadow(this); - return root; -}; +if (originalCreateShadowRoot) { + // ensure that all ShadowRoots watch for CustomElements. + Element.prototype.createShadowRoot = function() { + var root = originalCreateShadowRoot.call(this); + CustomElements.watchShadow(this); + return root; + }; +} // exports scope.watchShadow = watchShadow;