skip to Main Content

I’d like to test the browser support of web components. Thus I thought of doing it using:

if('define' in customElements) return true;

Is there a better or different way of doing this?

2

Answers


    1. Maybe this: Detect if dom element is custom web component or html element

    2. in most cases only web component will have shadow dom, might also be an option

    Login or Signup to reply.
  1. You can also do this for better approach.

    if (window.customElements) {
      // Custom elements are supported
      return true;
    } else {
      // Custom elements are not supported
      return false;
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search