Skip to content

Instantly share code, notes, and snippets.

@ebidel
Last active May 30, 2019 19:17
Show Gist options
  • Save ebidel/cea24a0c4fdcda8f8af2 to your computer and use it in GitHub Desktop.
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)
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 :)');}})();
// 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 :)');
}
//});
@davidmaxwaterman
Copy link

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