How to get list of registered custom elements

前端 未结 7 529
萌比男神i
萌比男神i 2020-12-08 09:55

I\'m trying to detect whether a custom element with a specific name was registered or not. Is there a way to make such check?

Or is there a way to get list of regist

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-08 10:18

    While I am not sure it applies to other Web Component frameworks, while using Polymer in Chrome, I have a CustomElements object to the window object. The CustomElements object has a key/value collection of all registered custom elements called registry.

    function isRegistered(name) {
        if (window.CustomElements && window.CustomElements.registry)
            return name in window.CustomElements.registry;
        return undefined;
    }
    

提交回复
热议问题