MediaWiki:Common.js: Difference between revisions

fixed the redirect not firing on its own on real phones
Tag: Reverted
added a temporary debug banner to see what's happening on your phone
Tag: Reverted
Line 20: Line 20:
// giving up on the first check.
// 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 {
       if (!document.body || !document.body.classList.contains('skin-minerva')) return;
       log.push('readyState: ' + document.readyState);
       var alreadyTried = false;
      log.push('bodyClass: ' + (document.body ? document.body.className : 'NO BODY'));
       try { alreadyTried = !!sessionStorage.getItem('wovForcedDesktop'); } catch (e) {}
      var isMinerva = !!(document.body && document.body.classList.contains('skin-minerva'));
       if (alreadyTried) return;
      log.push('isMinerva: ' + isMinerva);
       try { sessionStorage.setItem('wovForcedDesktop', '1'); } catch (e) {}
      if (!isMinerva) { log.push('DECISION: not Minerva, nothing to do'); showDebugBanner(log); return; }
       var sep = window.location.search ? '&' : '?';
       var storageWorks = true, alreadyTried = false;
       window.location.href = window.location.pathname + window.location.search + sep + 'mobileaction=toggle_view_desktop';
       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) {
       // if even the basic checks are blocked, just leave the user on Minerva
       log.push('FATAL ERROR: ' + e.message);
       // rather than risk breaking the rest of the site's scripts.
       showDebugBanner(log);
     }
     }
   }
   }