device-diag.html 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <!doctype html>
  2. <!--
  3. device-diag: real-device scrub diagnostic for scrollcraft builds.
  4. Headless verification cannot reproduce a phone's video decoder, autoplay
  5. policy, Low Power Mode, or touch scrolling. When a clip is reported frozen
  6. on a real device, deploy this page beside the site (same origin as the
  7. clips), open it on the device, scroll up and down a few times, and read the
  8. verdicts. One screenshot isolates the failing layer:
  9. suspect-blob FROZEN, suspect-direct MOVING -> the blob: URL path is the problem
  10. suspect FROZEN, known-good MOVING -> something specific to that clip's lifecycle
  11. all MOVING -> the video is fine; the fault is in the
  12. engine's reveal/tick path on the real page
  13. all FROZEN -> the device refuses scrub decode; use the
  14. poster fallback for that act
  15. To use: edit the TESTS array below. Point the first two entries at the
  16. suspect clip (same file, loaded two ways) and the third at a clip known to
  17. work on the device. Paths resolve against this page's URL.
  18. Scrubbing is driven by a rAF poll of scrollY, not scroll events, because a
  19. driven browser can move the page without firing them.
  20. -->
  21. <html lang="en">
  22. <head>
  23. <meta charset="utf-8">
  24. <meta name="viewport" content="width=device-width, initial-scale=1">
  25. <meta name="robots" content="noindex, nofollow">
  26. <title>scrub diagnostic</title>
  27. <style>
  28. * { margin: 0; box-sizing: border-box; }
  29. html { background: #0b0f14; color: #e8edf2; font: 13px/1.45 ui-monospace, Menlo, Consolas, monospace; }
  30. body { height: 520vh; }
  31. .panel { position: fixed; inset: 0; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
  32. h1 { font-size: 14px; font-weight: 600; }
  33. .hint { color: #8fa0b3; }
  34. .row { display: flex; gap: 8px; flex: 0 0 auto; }
  35. .cell { flex: 1 1 0; min-width: 0; }
  36. .cell video { width: 100%; aspect-ratio: 9 / 16; object-fit: cover; background: #000; display: block; border: 1px solid #26303c; border-radius: 6px; }
  37. .name { font-weight: 600; margin: 6px 0 2px; }
  38. .verdict { font-size: 15px; font-weight: 700; padding: 2px 6px; border-radius: 4px; display: inline-block; }
  39. .wait { background: #26303c; }
  40. .ok { background: #0f5132; color: #b6f0cd; }
  41. .bad { background: #6b1220; color: #ffc2cd; }
  42. .stats { color: #aab7c4; font-size: 11.5px; white-space: pre-line; }
  43. #meta { color: #8fa0b3; font-size: 11.5px; }
  44. #log { flex: 1 1 auto; overflow: auto; background: #10161d; border: 1px solid #26303c; border-radius: 6px; padding: 8px; font-size: 11px; color: #9fb4c8; white-space: pre-wrap; }
  45. </style>
  46. </head>
  47. <body>
  48. <div class="panel">
  49. <h1>scrub diagnostic — SCROLL UP AND DOWN A FEW TIMES, then read the verdicts</h1>
  50. <div class="hint">A: suspect clip, blob URL (how the engine loads it) &nbsp; B: suspect clip, direct file &nbsp; C: a clip that works on this device, blob URL</div>
  51. <div class="row" id="cells"></div>
  52. <div id="meta"></div>
  53. <div id="log"></div>
  54. </div>
  55. <script>
  56. (function () {
  57. 'use strict';
  58. // EDIT THESE for the build under test.
  59. var SUSPECT = 'assets/01-suspect-m.mp4';
  60. var KNOWN_GOOD = 'assets/02-known-good-m.mp4';
  61. var TESTS = [
  62. { key: 'A', label: 'A suspect blob', src: SUSPECT, mode: 'blob' },
  63. { key: 'B', label: 'B suspect direct', src: SUSPECT, mode: 'direct' },
  64. { key: 'C', label: 'C known-good blob', src: KNOWN_GOOD, mode: 'blob' }
  65. ];
  66. var logEl = document.getElementById('log');
  67. function log(m) {
  68. logEl.textContent += m + '\n';
  69. logEl.scrollTop = logEl.scrollHeight;
  70. }
  71. window.addEventListener('error', function (e) { log('JS ERROR: ' + e.message); });
  72. var maxScrolled = 0;
  73. var cellsEl = document.getElementById('cells');
  74. var canvas = document.createElement('canvas');
  75. canvas.width = 16; canvas.height = 16;
  76. var ctx = canvas.getContext('2d', { willReadFrequently: true });
  77. function make(t) {
  78. var cell = document.createElement('div');
  79. cell.className = 'cell';
  80. cell.innerHTML = '<div class="name">' + t.label + '</div>' +
  81. '<span class="verdict wait" id="v' + t.key + '">…</span>' +
  82. '<video muted playsinline preload="auto" id="el' + t.key + '"></video>' +
  83. '<div class="stats" id="s' + t.key + '"></div>';
  84. cellsEl.appendChild(cell);
  85. var T = {
  86. key: t.key, el: cell.querySelector('video'),
  87. verdict: cell.querySelector('.verdict'),
  88. stats: cell.querySelector('.stats'),
  89. seeked: 0, hashes: {}, hashCount: 0, prime: 'not tried',
  90. primed: false, priming: false, err: ''
  91. };
  92. T.el.muted = true; T.el.playsInline = true;
  93. T.el.addEventListener('seeked', function () { T.seeked++; });
  94. T.el.addEventListener('error', function () {
  95. var e = T.el.error;
  96. T.err = 'MediaError code ' + (e ? e.code : '?');
  97. log(t.key + ': ' + T.err);
  98. });
  99. T.el.addEventListener('loadedmetadata', function () {
  100. log(t.key + ': metadata, duration ' + T.el.duration.toFixed(2) + 's');
  101. try { T.el.currentTime = 0.001; } catch (e) {}
  102. prime(T, 'load'); // same as the engine: try with no gesture first
  103. });
  104. if (t.mode === 'blob') {
  105. fetch(t.src)
  106. .then(function (r) { if (!r.ok) throw new Error('HTTP ' + r.status); return r.blob(); })
  107. .then(function (b) {
  108. log(t.key + ': fetched ' + (b.size / 1048576).toFixed(2) + ' MB, blob URL set');
  109. T.el.src = URL.createObjectURL(b);
  110. })
  111. .catch(function (e) { T.err = 'fetch failed: ' + e.message; log(t.key + ': ' + T.err); });
  112. } else {
  113. T.el.src = t.src;
  114. log(t.key + ': direct src set');
  115. }
  116. return T;
  117. }
  118. function prime(T, why) {
  119. if (T.primed || T.priming || !T.el.src) return;
  120. T.priming = true;
  121. var pr;
  122. try { pr = T.el.play(); } catch (e) { T.priming = false; T.prime = 'threw (' + why + ')'; return; }
  123. setTimeout(function () {
  124. if (T.priming) { T.priming = false; if (T.prime === 'not tried') T.prime = 'play() never settled (' + why + ')'; }
  125. }, 2000);
  126. if (pr && pr.then) {
  127. pr.then(function () {
  128. T.priming = false; T.primed = true; T.prime = 'OK (' + why + ')';
  129. try { T.el.pause(); } catch (e) {}
  130. log(T.key + ': primed via ' + why);
  131. }, function (e) {
  132. T.priming = false; T.prime = (e && e.name ? e.name : 'rejected') + ' (' + why + ')';
  133. log(T.key + ': play() rejected via ' + why + ': ' + (e && e.name));
  134. });
  135. } else { T.priming = false; T.primed = true; T.prime = 'OK sync (' + why + ')'; try { T.el.pause(); } catch (e) {} }
  136. }
  137. var tests = TESTS.map(make);
  138. function primeAll(ev) { tests.forEach(function (T) { prime(T, ev); }); }
  139. ['touchstart', 'touchend', 'pointerdown', 'click', 'scroll'].forEach(function (ev) {
  140. addEventListener(ev, function () { primeAll(ev); }, { passive: true });
  141. });
  142. // scroll position drives every clip, exactly like the engine. Polled from a
  143. // rAF loop rather than a scroll listener, so the diagnostic cannot be blinded
  144. // by an environment that moves the page without firing scroll events.
  145. var lastY = -1, lastPrimeTry = 0;
  146. function loop() {
  147. var maxY = document.body.scrollHeight - innerHeight;
  148. var p = maxY > 0 ? Math.max(0, Math.min(1, scrollY / maxY)) : 0;
  149. if (scrollY !== lastY) {
  150. if (lastY !== -1 && performance.now() - lastPrimeTry > 600) {
  151. lastPrimeTry = performance.now();
  152. primeAll('scrollmove');
  153. }
  154. lastY = scrollY;
  155. maxScrolled = Math.max(maxScrolled, p);
  156. }
  157. tests.forEach(function (T) {
  158. if (!T.el.duration || T.el.seeking) return;
  159. var t = p * T.el.duration * 0.98;
  160. if (Math.abs(T.el.currentTime - t) > 0.02) {
  161. try { T.el.currentTime = t; } catch (e) {}
  162. }
  163. });
  164. requestAnimationFrame(loop);
  165. }
  166. requestAnimationFrame(loop);
  167. function frameHash(T) {
  168. if (T.el.readyState < 2) return null;
  169. try {
  170. ctx.drawImage(T.el, 0, 0, 16, 16);
  171. var d = ctx.getImageData(0, 0, 16, 16).data, h = 0;
  172. for (var i = 0; i < d.length; i += 7) h = (h * 31 + d[i]) >>> 0;
  173. return h;
  174. } catch (e) { return null; }
  175. }
  176. setInterval(function () {
  177. tests.forEach(function (T) {
  178. var h = frameHash(T);
  179. if (h !== null && !T.hashes[h]) { T.hashes[h] = 1; T.hashCount++; }
  180. T.stats.textContent =
  181. 'prime: ' + T.prime +
  182. '\nreadyState ' + T.el.readyState + ' · seeks done ' + T.seeked +
  183. '\ntime ' + T.el.currentTime.toFixed(2) + 's · frames seen ' + T.hashCount +
  184. (T.err ? '\n' + T.err : '');
  185. if (T.hashCount >= 3) { T.verdict.textContent = 'MOVING'; T.verdict.className = 'verdict ok'; }
  186. else if (T.err) { T.verdict.textContent = 'ERROR'; T.verdict.className = 'verdict bad'; }
  187. else if (maxScrolled > 0.35) { T.verdict.textContent = 'FROZEN'; T.verdict.className = 'verdict bad'; }
  188. });
  189. }, 250);
  190. document.getElementById('meta').textContent =
  191. navigator.userAgent + ' · ' + innerWidth + 'x' + innerHeight +
  192. ' · dpr ' + devicePixelRatio;
  193. })();
  194. </script>
  195. </body>
  196. </html>