Did you try adding the event to the document element? You can add this code in a regular script at the Playcanvas initialize() method (taken from the MDN JavaScript docs):
//startSimulation and pauseSimulation defined elsewhere
function handleVisibilityChange() {
if (document.hidden) {
pauseSimulation();
} else {
startSimulation();
}
}
document.addEventListener("visibilitychange", handleVisibilityChange, false);