Last active
May 30, 2019 19:17
-
-
Save ebidel/cea24a0c4fdcda8f8af2 to your computer and use it in GitHub Desktop.
Logs any custom elements on a page that are not registerd (e.g. missing an HTML import)
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
javascript:(function(){function isUnregisteredCustomElement(el){if(el.constructor==HTMLElement){console.error("Found unregistered custom element:",el);return true;}return false;}function isCustomEl(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}var allCustomElements=document.querySelectorAll('html /deep/ *');allCustomElements=Array.prototype.slice.call(allCustomElements).filter(function(el){return isCustomEl(el);});var foundSome=false;for(var i=0,el;el=allCustomElements[i];++i){if(isUnregisteredCustomElement(el)){foundSome=true;}}if(foundSome){alert('Oops: found one or more unregistered custom elements in use! Check the console.');}else{alert('Good: All custom elements are registered :)');}})(); |
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
// Logs any custom elements on a page that are not registerd (e.g. missing an HTML import) | |
// To create a bookmarklet, use http://ted.mielczarek.org/code/mozilla/bookmarklet.html | |
function isUnregisteredCustomElement(el) { | |
if (el.constructor == HTMLElement) { | |
console.error("Found unregistered custom element:", el); | |
return true; | |
} | |
return false; | |
} | |
function isCustomEl(el) { | |
return el.localName.indexOf('-') != -1 || el.getAttribute('is'); | |
} | |
//document.addEventListener('polymer-ready', function() { | |
var allCustomElements = document.querySelectorAll('html /deep/ *'); | |
allCustomElements = Array.prototype.slice.call(allCustomElements).filter(function(el) { | |
return isCustomEl(el); | |
}); | |
var foundSome = false; | |
for (var i = 0, el; el = allCustomElements[i]; ++i) { | |
if (isUnregisteredCustomElement(el)) { | |
foundSome = true; | |
} | |
} | |
if (foundSome) { | |
alert('Oops: found one or more unregistered custom elements in use! Check the console.'); | |
} else { | |
alert('Good: All custom elements are registered :)'); | |
} | |
//}); |
@ulybu You shouldn't need this to be cross-platform. It's essentially a development tool. So just check in chrome you are doing all the right imports, then the other browsers won't have an issue. Right?
I wonder if this is suppose to work on iframe contents too? My index.html has two polymer elements in it, and one of them is the 'app' element and it uses another element that has an iframe in it - I expected this tool to flag some unregistered elements in the content of that iframe, but it seems not.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work on polyfilled browser.
Indeed,
isUnregisteredCustomElement
checks if the constructor is stillHTMLElement
or if it has been upgraded. On safari (polyfilled), the constructor will be HTMLUnknowElement in any case, so it won't be detected as unresolved.Is there a cross-platform way to do that ?