it was impossible for developers to specify the code that can be executed under any case of unloading a page. In order to solve this problem, Page Visibility API was introduced. The API will listen to any visible change of the page under all the cases, regardless of that, it's on phone or desktop.