I wrote a little script that calculates something in HTML page, but when the window is minimized or hidden behind other app - it stops executing. I want to continue doing something else, for example, open another tab and browse the internet, I can't sit and stare at this executing tab. Is there a way to force the JS to continue execution even when the window is blurred?
What I do is I train my LSTM model using TensorFlow.js. But to illustrate this, I created a little codepen, that calculates PI on the fly. Whe I blur it - the execution is paused. Here: https://codepen.io/shalmu/pen/ExWZbxR
function calcStep(){
const a=step*2, sign=step%2==1?1:-1;
pi += 4/(a*(a+1)*(a+2))*sign;
step++;
status.innerHTML=`step: <b>${step}</b>, pi=<i>${pi}</i>`;
setTimeout(calcStep, 16);
}