Standardize our use of the PageVisibility API

As part of #29569 (closed) we'll be introducing a lightweight library that wraps the page visibility API. We need to refactor instances in the frontend codebase to use that library.

cc: @filipa