runtime-test.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <!DOCTYPE html>
  2. <html><head><meta charset="UTF-8"><title>Algorithm Test</title></head>
  3. <body>
  4. <pre id="out"></pre>
  5. <script>
  6. const out = document.getElementById('out');
  7. function log(s) { out.textContent += s + '\n'; }
  8. // ============ Extract and test the core algorithm ============
  9. fetch('/eye-demo/index.html').then(r=>r.text()).then(html => {
  10. const match = html.match(/<script>\(function \(\) \{([\s\S]+)\}\)\(\);<\/script>/);
  11. if (!match) { log('FAIL: no script'); return; }
  12. try {
  13. new Function(match[1]);
  14. log('PASS: JS syntax valid');
  15. } catch(e) {
  16. log('FAIL: JS syntax error: ' + e.message);
  17. return;
  18. }
  19. // Now run the actual page in an iframe to check runtime
  20. log('\n--- Runtime test (iframe) ---');
  21. const iframe = document.createElement('iframe');
  22. iframe.style.width = '0';
  23. iframe.style.height = '0';
  24. iframe.style.border = 'none';
  25. document.body.appendChild(iframe);
  26. const iframeDoc = iframe.contentDocument;
  27. iframeDoc.open();
  28. iframeDoc.write(html);
  29. iframeDoc.close();
  30. // Wait a moment for IIFE to execute
  31. setTimeout(() => {
  32. try {
  33. const win = iframe.contentWindow;
  34. // Check that the IIFE didn't throw
  35. log('PASS: IIFE executed without throwing');
  36. // Check localStorage
  37. const calData = localStorage.getItem('eye-tracking-calibration');
  38. if (calData) {
  39. log('INFO: Found existing calibration data: ' + calData.substring(0, 100) + '...');
  40. } else {
  41. log('INFO: No calibration data in localStorage (expected on first run)');
  42. }
  43. // Check if stage canvas exists
  44. const stage = iframeDoc.getElementById('stage');
  45. log('Stage canvas: ' + (stage ? 'OK (' + stage.width + 'x' + stage.height + ')' : 'MISSING'));
  46. // Check calibration overlay
  47. const calOverlay = iframeDoc.getElementById('calibration-overlay');
  48. log('Calibration overlay: ' + (calOverlay ? 'exists' : 'MISSING'));
  49. if (calOverlay) {
  50. log(' has show class: ' + calOverlay.classList.contains('show'));
  51. }
  52. // Check status text
  53. const statusText = iframeDoc.getElementById('status-text');
  54. log('Status text: ' + (statusText ? '"' + statusText.textContent + '"' : 'MISSING'));
  55. // Check cal status
  56. const calStatusText = iframeDoc.getElementById('cal-status-text');
  57. log('Cal status: ' + (calStatusText ? '"' + calStatusText.textContent + '"' : 'MISSING'));
  58. // Check recalibrate button
  59. const recalBtn = iframeDoc.getElementById('recalibrate-btn');
  60. log('Recalibrate btn: ' + (recalBtn ? 'exists (disabled=' + recalBtn.disabled + ')' : 'MISSING'));
  61. // Check debug panel
  62. const dbgStage = iframeDoc.getElementById('dbg-stage');
  63. log('dbg-stage element: ' + (dbgStage ? 'exists' : 'MISSING (bug: JS looks for debug-stage but HTML id is dbg-stage)'));
  64. log('\n--- All runtime checks done ---');
  65. } catch(e) {
  66. log('FAIL: Runtime error: ' + e.message);
  67. log('Stack: ' + e.stack);
  68. }
  69. // Clean up
  70. document.body.removeChild(iframe);
  71. }, 2000);
  72. }).catch(e => log('Fetch error: ' + e.message));
  73. </script>
  74. </body>
  75. </html>