MediaWiki:Common.js: Difference between revisions

added a temporary debug banner to see what's happening on your phone
Tag: Reverted
found and fixed the real cause of the mobile menu issue
Tag: Reverted
Line 5: Line 5:
// worse experience than the (now mobile-responsive) desktop skin.
// worse experience than the (now mobile-responsive) desktop skin.
//
//
// The server does set a loop-guard cookie on the toggle ("stopMobileRedirect"),
// No loop-guard flag needed: the check itself ("are we currently rendering
// but it's HttpOnly (confirmed by testing), so client-side JS can never
// Minerva") is self-limiting. Once the redirect lands on the desktop skin,
// actually read it - that check would always be dead code. sessionStorage
// body no longer has the skin-minerva class, so this is a no-op on every
// is the only guard we can use here, wrapped in its own try/catch so a
// later page view - no persistent flag to get stuck. An earlier version
// browser that blocks storage access doesn't cancel the whole redirect.
// used a sessionStorage flag to avoid re-attempting, but that tracked
//
// "did we try" rather than "did it work": once set (e.g. from an earlier
// This used to bail out permanently if document.body wasn't available yet
// attempt that didn't fully land), it permanently blocked all future
// ("if (!document.body) return"), with no retry. Real-device testing (real
// attempts for the rest of that browser session. Confirmed via a debug
// Safari/Chrome on iOS - NOT reproducible by spoofing the user-agent string
// banner on a real phone that this was exactly what was happening.
// in a desktop Electron/Chromium test, since that never runs WebKit at all)
// showed the redirect worked fine when triggered manually via URL, but never
// fired on its own: this script runs before <body> exists in some real
// mobile browsers, so it needs to wait for DOMContentLoaded instead of
// giving up on the first check.
(function () {
(function () {
  // TEMPORARY DEBUG BUILD: the automatic redirect isn't firing on some real
  // phones and it can't be reproduced in any test environment available
  // here (Electron only fakes the user-agent string, it never actually runs
  // WebKit). Instead of guessing again, this shows what the script actually
  // sees directly on the page, and does NOT navigate away, so the banner
  // stays put to be read/screenshotted. Remove this block and restore the
  // plain redirect once the real cause is identified from that report.
  function showDebugBanner(lines) {
    try {
      var el = document.createElement('div');
      el.id = 'wov-debug-banner';
      el.style.cssText = 'position:fixed;top:0;left:0;right:0;z-index:99999;background:#111;color:#0f0;font:12px monospace;padding:8px;white-space:pre-wrap;word-break:break-all;max-height:60vh;overflow:auto;';
      el.textContent = lines.join('\n');
      (document.body || document.documentElement).appendChild(el);
    } catch (e) {}
  }
   function tryForceDesktop() {
   function tryForceDesktop() {
    var log = [];
     try {
     try {
       log.push('readyState: ' + document.readyState);
       if (!document.body || !document.body.classList.contains('skin-minerva')) return;
      log.push('bodyClass: ' + (document.body ? document.body.className : 'NO BODY'));
       var sep = window.location.search ? '&' : '?';
      var isMinerva = !!(document.body && document.body.classList.contains('skin-minerva'));
       window.location.replace(window.location.pathname + window.location.search + sep + 'mobileaction=toggle_view_desktop');
      log.push('isMinerva: ' + isMinerva);
      if (!isMinerva) { log.push('DECISION: not Minerva, nothing to do'); showDebugBanner(log); return; }
       var storageWorks = true, alreadyTried = false;
      try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) { storageWorks = false; log.push('sessionStorage error: ' + e.message); }
      log.push('storageWorks: ' + storageWorks + ', alreadyTried: ' + alreadyTried);
       if (alreadyTried) { log.push('DECISION: already tried this session, stopping (would normally stay on Minerva)'); showDebugBanner(log); return; }
      var targetUrl = window.location.pathname + window.location.search + (window.location.search ? '&' : '?') + 'mobileaction=toggle_view_desktop';
      log.push('DECISION: would redirect to: ' + targetUrl);
      log.push('cookie: ' + document.cookie);
      showDebugBanner(log);
      // Redirect intentionally disabled during this debug pass.
     } catch (e) {
     } catch (e) {
       log.push('FATAL ERROR: ' + e.message);
       // if something here is blocked, just leave the user on Minerva rather
      showDebugBanner(log);
      // than risk breaking the rest of the site's scripts.
     }
     }
   }
   }