const MamiSleep = durationMs => new Promise(resolve => { setTimeout(resolve, durationMs); });

const MamiWaitVisible = () => {
    return new Promise(resolve => {
        if(document.visibilityState === 'visible') {
            resolve();
            return;
        }

        const handler = () => {
            if(document.visibilityState === 'visible') {
                window.removeEventListener('visibilitychange', handler);
                resolve();
            }
        };

        window.addEventListener('visibilitychange', handler);
    });
};
