$w.onReady(function () {
// Check every 500ms if STWidgetManager is available
let checkInterval = setInterval(() => {
if (typeof window.STWidgetManager !== "undefined") {
clearInterval(checkInterval); // Stop checking
console.log("ServiceTitan Web Scheduler is now available.");
// Attach the button click event once STWidgetManager is ready
$w("#openSchedulerButton").onClick(() => {
window.STWidgetManager("ws-open");
});
} else {
console.log("Waiting for ServiceTitan Web Scheduler to load...");
}
}, 500);
});