debug(pwa): add admin-only display-mode overlay for diagnosis on mobile
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Shows detected display-mode, navigator.standalone, and PWA cookies
as a small green text at bottom of screen. Only visible for admin users.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-03-18 10:09:15 +01:00
parent 8d70760ef8
commit ec51db9de4
2 changed files with 11 additions and 9 deletions

View File

@ -2382,12 +2382,17 @@
} }
} }
if (window.navigator.standalone === true) detected = 'ios-standalone'; if (window.navigator.standalone === true) detected = 'ios-standalone';
// Set cookie with detected mode for debugging
document.cookie = 'pwa_display=' + detected + '; path=/; max-age=86400; SameSite=Lax'; document.cookie = 'pwa_display=' + detected + '; path=/; max-age=86400; SameSite=Lax';
// PWA = anything that is NOT 'browser' and NOT 'unknown'
if (detected !== 'browser' && detected !== 'unknown') { if (detected !== 'browser' && detected !== 'unknown') {
document.cookie = 'pwa_mode=1; path=/; max-age=86400; SameSite=Lax'; document.cookie = 'pwa_mode=1; path=/; max-age=86400; SameSite=Lax';
} }
{% if current_user.is_authenticated and current_user.has_role(SystemRole.ADMIN) %}
// Debug: show detected mode for admin (temporary)
var d = document.createElement('div');
d.style.cssText = 'position:fixed;bottom:0;left:0;background:rgba(0,0,0,0.8);color:#0f0;font-size:11px;padding:4px 8px;z-index:99999;font-family:monospace;';
d.textContent = 'display-mode: ' + detected + ' | standalone: ' + window.navigator.standalone + ' | cookies: ' + document.cookie.split(';').filter(function(c){return c.trim().startsWith('pwa')}).join(', ');
document.body.appendChild(d);
{% endif %}
})(); })();
// PWA Smart Banner logic // PWA Smart Banner logic

View File

@ -98,14 +98,11 @@ def get_or_create_analytics_session():
user_session.last_activity_at = datetime.now() user_session.last_activity_at = datetime.now()
if current_user.is_authenticated and not user_session.user_id: if current_user.is_authenticated and not user_session.user_id:
user_session.user_id = current_user.id user_session.user_id = current_user.id
# PWA cookie arrives on 2nd request (after JS sets it) # PWA detection from cookie (set by JS in standalone mode)
pwa_cookie = request.cookies.get('pwa_mode') pwa_cookie = request.cookies.get('pwa_mode') == '1'
pwa_display = request.cookies.get('pwa_display') pwa_display = request.cookies.get('pwa_display', '')
if pwa_display: if not user_session.is_pwa and pwa_cookie:
logger.info(f"PWA display mode: '{pwa_display}' pwa_mode={pwa_cookie} session={user_session.id} browser={user_session.browser}")
if not user_session.is_pwa and pwa_cookie == '1':
user_session.is_pwa = True user_session.is_pwa = True
logger.info(f"Setting is_pwa=True for session {user_session.id}")
db.commit() db.commit()
return user_session.id return user_session.id