I'm a bit confused on migrating this question to Super User.
The OP had asked about pausing or playing CSS animations when the browser tab is changed. OP had also attached a code with it. When, I tested the code, it runs well for me except for once in 16-20 trials. I suspect that this problem could be due to browser's internal bugs or run-time errors. And, therefore I think that this could be better handled on Super User, but I'm still not sure about it!
What do you think?