Skip to content

Instantly share code, notes, and snippets.

@ebidel
Last active May 30, 2019 19:17
  • Star 17 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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 :)');
}
//});
@sean9999
Copy link

cool idea!

@ulybu
Copy link

ulybu commented Oct 13, 2014

Doesn't work on polyfilled browser.
Indeed, isUnregisteredCustomElement checks if the constructor is still HTMLElement 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 ?

@volpe
Copy link

volpe commented Nov 9, 2014

@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?

@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