-
-
Save ebidel/cea24a0c4fdcda8f8af2 to your computer and use it in GitHub Desktop.
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 :)'); | |
} | |
//}); |
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 ?
@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.
cool idea!