Determine if dashboard is done loading

Hello - is there a way via Javascript to determine if all the cards on a dashboard are done loading? I'm loading a dashboard embed in a headless Chromium browser to take a PDF print, and I'm running the occasional card not finished loading before the print is executed. Currently, I'm executing some JS to see if elements like the spinner and warning icon are present, but that doesn't seem to cover all of the loading states.

Hi @ajcoll5

The spinner should cover all the loading states - I would not wait on warnings/errors, since that could be caused by a query that is failing for whatever reason, so that would never finish.

There are parts, which Metabase doesn't know - like showing a pin map, then the tiles are downloaded from OpenStreetMaps by the client - or inline images, which is also downloaded by the client.

You might be able to pickup the loading time in the title, which should be an indicator as well:
https://github.com/metabase/metabase/pull/11611/files

Thanks flamber! The spinner isn't on the "Still Waiting" message, and there are a couple of cards on the dashboard in question that do take a bit to load - so looking for the spinner wasn't covering everything. I've found a slightly different way to get the answer.

For anyone in the future looking for a solution, here's some amateur-hour JS to do it. Returns 0 if we're done loading, 1 if we're still loading, and 2 if there's an error.

var isStillLoading = 0;
if(document.getElementsByClassName("LoadingSpinner").length > 0){
    isStillLoading = 1;
}else{
    var dcData = Metabase.store.getState().dashboard.dashcardData;
    for(dc in dcData){
        for(q in dcData[dc]){
            if(dcData[dc][q] != null){
                if(dcData[dc][q].error != null){
                    isStillLoading = 2;
                }else if (dcData[dc][q].status != "completed"){
                    isStillLoading = 1;
                }
            }else{
                isStillLoading = 1;
            }
        }
    }
}
isStillLoading;
1 Like

@ajcoll5 "amateur-hour" :rofl: it doesn't matter - it gets the job done, so :+1: