From 63337ba4f8c4f31b7da96e9c3669fc29e0a03b49 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Fri, 13 May 2022 03:29:49 -0700 Subject: web: disable back button when installed as a PWA --- web/static/dartboat.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'web/static/dartboat.js') diff --git a/web/static/dartboat.js b/web/static/dartboat.js index 39e0371..6051b7e 100644 --- a/web/static/dartboat.js +++ b/web/static/dartboat.js @@ -197,3 +197,16 @@ document.addEventListener('keydown', e => { if ('serviceWorker' in navigator) navigator.serviceWorker.register('sw.js'); + +// disable back button when installed as a PWA. a single click exits the app, +// destroying match state without confirmation, so we must resort to this. +if (window.matchMedia('(display-mode: standalone)').matches) { + window.addEventListener('load', () => { + if (!history.state) { + history.replaceState(true, ''); + history.pushState(true, ''); + } + }); + + window.addEventListener('popstate', () => history.pushState(true, '')); +} -- cgit v1.2.3-70-g09d2