// Admin Sidebar Scroll Test - Run directly in browser console // Copy and paste this entire script into the browser console on any admin page (function adminScrollTest() { console.clear(); console.log('=== ADMIN SIDEBAR SCROLL TEST ===\n'); // Find sidebar const sidebar = document.querySelector('[data-sidebar="true"]'); if (!sidebar) { console.error('โŒ No sidebar found. Make sure you are on an admin page (/admin/*)'); return; } console.log('โœ… Sidebar found'); console.log('๐Ÿ“ Current scroll:', sidebar.scrollTop); console.log('๐Ÿ“ Scroll height:', sidebar.scrollHeight); console.log('๐Ÿ“ Client height:', sidebar.clientHeight); console.log('๐Ÿ“ Scrollable:', sidebar.scrollHeight > sidebar.clientHeight ? 'โœ… YES' : 'โŒ NO'); // Check if scrollable if (sidebar.scrollHeight <= sidebar.clientHeight) { console.log('\nโš ๏ธ Sidebar is NOT scrollable!'); console.log(' To test scroll retention, the sidebar needs to be scrollable.'); console.log(' Try: 1) Reducing browser window height, or 2) Zoom in (Ctrl +)'); return; } console.log('\n๐Ÿงช Testing scroll retention...'); // Clear any existing scroll data sessionStorage.removeItem('admin-sidebar-scroll'); sessionStorage.removeItem('admin-sidebar-scroll-emergency'); delete window.__adminSidebarScrollTarget; // Scroll to a test position (middle of scrollable area) const maxScroll = sidebar.scrollHeight - sidebar.clientHeight; const testScroll = Math.floor(maxScroll * 0.5); console.log('๐Ÿ“ Scrolling to test position:', testScroll, 'px'); sidebar.scrollTop = testScroll; setTimeout(() => { const actualScroll = sidebar.scrollTop; console.log('๐Ÿ“ Current position after scroll:', actualScroll, 'px'); // Check if scroll was saved const savedData = sessionStorage.getItem('admin-sidebar-scroll'); const emergencyData = sessionStorage.getItem('admin-sidebar-scroll-emergency'); const globalTarget = window.__adminSidebarScrollTarget; console.log('\n๐Ÿ’พ Storage check:'); console.log(' Main saved data:', savedData); console.log(' Emergency saved:', emergencyData); console.log(' Global target:', globalTarget); console.log('\n๐Ÿš€ NOW CLICK ANY ADMIN NAVIGATION LINK'); console.log(' The test will automatically detect navigation and check scroll preservation'); // Intercept navigation to test let navDetected = false; const originalPushState = history.pushState; history.pushState = function(...args) { if (!navDetected) { navDetected = true; const scrollBefore = sidebar.scrollTop; console.log('\n๐Ÿšฆ Navigation detected!'); console.log(' Scroll position before navigation:', scrollBefore, 'px'); // Check scroll preservation at multiple intervals const checkPoints = [100, 300, 600, 1000]; checkPoints.forEach((delay, index) => { setTimeout(() => { const scrollAfter = sidebar.scrollTop; const difference = Math.abs(scrollAfter - scrollBefore); console.log(` ๐Ÿ“ Check ${index + 1} (${delay}ms): ${scrollAfter}px (diff: ${difference}px)`); if (delay === 1000) { if (difference < 10) { console.log('\nโœ… SUCCESS: Scroll position preserved!'); console.log(' The admin sidebar scroll retention is working correctly.'); } else { console.log('\nโŒ FAILURE: Scroll position was reset'); console.log(' Difference:', difference, 'px'); console.log('\n๐Ÿ” Debugging info:'); console.log(' - Check browser console for any scroll-related errors'); console.log(' - Verify AdminScrollManager is loaded'); console.log(' - Check if CSS is interfering'); } // Restore original history function history.pushState = originalPushState; } }, delay); }); } return originalPushState.apply(this, args); }; }, 500); })();