Problem with Ambient mode and document.addEventListener “visibilitychange” if !document.hidden

Problem with Ambient mode and document.addEventListener “visibilitychange” if !document.hidden

BY 25 Mar 2017 Web Application Development

My watch face is updated every 500 ms when document is not hidden. I want do the same when Ambient mode is turned on. And it works well but in a while it works like Ambient mode is ‘document.hidden’, so watch face isn’t updated any more. I need to reboot device and it works fine again.

What is a reason? What do I need to do?

 

document.addEventListener(“visibilitychange”, function() {
            if (!document.hidden) {
                interval = setInterval(update_watch, 500);
            }

            else {   //or if (document.hidden) no matter, the same effect
                clearInterval(interval);
            }
            
        });

 

I don’t even use window.addEventListener “ambientmodechanged”

I added just two cases.

– If hidden then stop updating.

– If not hidden then start updating

Written by