--- title: "UC_UI_INITIALIZED" slug: "uc-ui-initialized" updated: 2026-11-17T04:53:54Z published: 2026-11-17T04:53:54Z canonical: "usercentrics.com/uc-ui-initialized" --- > ## Documentation Index > Fetch the complete documentation index at: https://usercentrics.com/docs/llms.txt > Use this file to discover all available pages before exploring further. # UC_UI_INITIALIZED This is an example of how to wait for the CMP to initialize before executing code. > [!WARNING] > Methods on `window.__ucCmp` are only safe to call after `UC_UI_INITIALIZED` has fired. Before this event fires, `window.__ucCmp` may not exist yet, or may exist but not be fully populated. Always check whether it is already initialized and, if not, wait for the event before calling any of its methods. ## Example ```javascript window.addEventListener('UC_UI_INITIALIZED', function(event) {  // Initialized }); ``` ## Guard pattern Use this pattern whenever you call a `window.__ucCmp` method to safely handle both cases: the CMP has already initialized, or it hasn't yet. ```javascript function customHandler() {  // Safe to call any window.__ucCmp method here } if (!window.__ucCmp || !__ucCmp.isInitialized()) {  window.addEventListener('UC_UI_INITIALIZED', function() {    customHandler();  }); } else {  customHandler(); } ```