test.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Eye Demo - Debug Test</title>
  6. <style>
  7. body { background: #111; color: #0f0; font-family: monospace; padding: 20px; white-space: pre-wrap; font-size: 13px; }
  8. .err { color: #f44; }
  9. .ok { color: #0f0; }
  10. .warn { color: #fa0; }
  11. </style>
  12. </head>
  13. <body>
  14. <h2>Eye Tracking Debug Test</h2>
  15. <div id="output"></div>
  16. <script>
  17. // Extract and test the JS from index.html
  18. fetch('/eye-demo/index.html')
  19. .then(r => r.text())
  20. .then(html => {
  21. const out = document.getElementById('output');
  22. function log(msg, cls) {
  23. const div = document.createElement('div');
  24. div.className = cls || '';
  25. div.textContent = msg;
  26. out.appendChild(div);
  27. }
  28. // 1. Extract main script
  29. const match = html.match(/<script>\(function \(\) \{([\s\S]+)\}\)\(\);<\/script>/);
  30. if (!match) {
  31. log('ERROR: Could not extract main IIFE script', 'err');
  32. return;
  33. }
  34. log('Script extracted OK (' + match[1].length + ' chars)', 'ok');
  35. // 2. Syntax check
  36. try {
  37. new Function(match[1]);
  38. log('JS SYNTAX: VALID', 'ok');
  39. } catch(e) {
  40. log('JS SYNTAX ERROR: ' + e.message, 'err');
  41. // Try to find the error location
  42. log('Error stack: ' + e.stack, 'err');
  43. }
  44. // 3. Check DOM element IDs referenced in JS
  45. const script = match[1];
  46. const ids = script.match(/getElementById\(['"]([^'"]+)['"]\)/g) || [];
  47. log('\n--- DOM ID Check (' + ids.length + ' refs) ---');
  48. let missingCount = 0;
  49. ids.forEach(ref => {
  50. const id = ref.match(/getElementById\(['"]([^'"]+)['"]\)/)[1];
  51. const exists = html.indexOf('id="' + id + '"') !== -1;
  52. if (!exists) {
  53. log(' MISSING ID: "' + id + '" (JS looks for it but HTML has no such id)', 'err');
  54. missingCount++;
  55. }
  56. });
  57. if (missingCount === 0) log(' All DOM IDs found in HTML', 'ok');
  58. // 4. Key logic flow check
  59. log('\n--- Logic Flow ---');
  60. // Check that calibration flow doesn't have issues
  61. const hasCalStart = script.indexOf('startCalibration()') !== -1;
  62. const hasCalFinish = script.indexOf('finishCalibration()') !== -1;
  63. const hasOnResults = script.indexOf('function onResults') !== -1;
  64. const hasApplyRegression = script.indexOf('applyRegression') !== -1;
  65. const hasFrameSkip = script.indexOf('frameCount % 2') !== -1;
  66. log(' startCalibration: ' + (hasCalStart ? 'found' : 'MISSING'), hasCalStart ? 'ok' : 'err');
  67. log(' finishCalibration: ' + (hasCalFinish ? 'found' : 'MISSING'), hasCalFinish ? 'ok' : 'err');
  68. log(' onResults: ' + (hasOnResults ? 'found' : 'MISSING'), hasOnResults ? 'ok' : 'err');
  69. log(' applyRegression: ' + (hasApplyRegression ? 'found' : 'MISSING'), hasApplyRegression ? 'ok' : 'err');
  70. log(' frameSkip: ' + (hasFrameSkip ? 'found' : 'MISSING'), hasFrameSkip ? 'ok' : 'err');
  71. // 5. Check right eye fix
  72. const hasRFlip = script.indexOf('r_inner.x - r_outer.x') !== -1;
  73. log('\n Right eye flip fix: ' + (hasRFlip ? 'PRESENT' : 'MISSING'), hasRFlip ? 'ok' : 'err');
  74. // 6. Check that old Kalman is removed
  75. const hasKalman = script.indexOf('SimpleKalman') !== -1;
  76. log(' Kalman removed: ' + (!hasKalman ? 'YES' : 'STILL PRESENT'), !hasKalman ? 'ok' : 'warn');
  77. // 7. Check that head pose is removed
  78. const hasHeadPose = script.indexOf('nose') !== -1 && script.indexOf('headOffY') !== -1;
  79. log(' Head pose removed: ' + (!hasHeadPose ? 'YES' : 'STILL PRESENT'), !hasHeadPose ? 'ok' : 'warn');
  80. // 8. Check EMA
  81. const hasEMA = script.indexOf('EMA_ALPHA') !== -1;
  82. log(' EMA smoothing: ' + (hasEMA ? 'PRESENT' : 'MISSING'), hasEMA ? 'ok' : 'err');
  83. // 9. Check localStorage
  84. const hasStorage = script.indexOf('localStorage') !== -1;
  85. log(' localStorage: ' + (hasStorage ? 'PRESENT' : 'MISSING'), hasStorage ? 'ok' : 'err');
  86. // 10. Check if there's an unused eyeData function inside computeIrisGaze
  87. const computeGazeSection = script.match(/function computeIrisGaze[\s\S]*?function eyeData[\s\S]*?\n \}/);
  88. if (computeGazeSection) {
  89. log('\n WARNING: Unused nested eyeData() inside computeIrisGaze (dead code, harmless)', 'warn');
  90. }
  91. log('\n--- DONE ---');
  92. })
  93. .catch(e => {
  94. document.getElementById('output').textContent = 'Fetch error: ' + e.message;
  95. });
  96. </script>
  97. </body>
  98. </html>