PWA and back button on Android

Please share your experience on how to close dialog boxes and exit PWA applications on Android (not Cordova).
Tried using window.history.pushState and “popstate”. But after visiting a page and returning to the main page, you can exit only after 2 clicks on the back button. Well, there are many other points that prevent the implementation of a PWA application.