Search code examples
javascriptpolymerweb-component

Web Components ready flag


We are using Web Components and Polymer on our site, and have quite a few bits of Javascript which wait for the "WebComponentsReady" event to be fired before executing. However, we have some asynchronous JS files which occasionally add an event listener for the event after it has been fired, meaning the script we want to run is never run.

Does anyone know if there is a flag for Web Components being ready which can be checked?

Something like this is what we would need:

if(WebComponents.ready) { // Does this flag, or something similar, exist??
    // do stuff
} else {
    document.addEventListener('WebComponentsReady', function() {
        // do stuff
    }
}

Any help appreciated.


Solution

  • The following flag is set during bootstrap

    window.CustomElements.ready