@@ -492,17 +492,28 @@ try {
492492 15_000 ,
493493 ) ;
494494
495- await waitForValue (
496- cdp ,
497- `
495+ try {
496+ await waitForValue (
497+ cdp ,
498+ `
498499 (() => {
499500 const videos = [...document.querySelectorAll("video.stream-video")];
500501 return videos.some((video) => video.readyState >= 2 && video.videoWidth > 0 && video.videoHeight > 0);
501502 })()
502503 ` ,
503- Boolean ,
504- streamReadyTimeoutMs ,
505- ) ;
504+ Boolean ,
505+ streamReadyTimeoutMs ,
506+ ) ;
507+ } catch ( error ) {
508+ const diagnostics = await collectReadinessDiagnostics ( cdp , clientId ) . catch (
509+ ( diagnosticError ) => ( {
510+ diagnosticError : String ( diagnosticError ?. message ?? diagnosticError ) ,
511+ } ) ,
512+ ) ;
513+ throw new Error (
514+ `${ error ?. message ?? error } \nReadiness diagnostics: ${ JSON . stringify ( diagnostics , null , 2 ) } ` ,
515+ ) ;
516+ }
506517
507518 const initialMetrics = await fetchJson ( endpoint ( "/api/metrics" ) ) ;
508519 const initialStreams = findClientStreams ( initialMetrics , clientId ) ;
@@ -840,6 +851,63 @@ async function waitForValue(cdp, expression, predicate, timeoutMs) {
840851 ) ;
841852}
842853
854+ async function collectReadinessDiagnostics ( cdp , clientId ) {
855+ const page = await evaluate (
856+ cdp ,
857+ `
858+ (() => {
859+ const videos = [...document.querySelectorAll("video.stream-video")].map((video) => ({
860+ height: video.videoHeight || 0,
861+ networkState: video.networkState,
862+ paused: video.paused,
863+ readyState: video.readyState,
864+ width: video.videoWidth || 0,
865+ }));
866+ const peerConnections = (window.__simdeckPeerConnections || []).map((pc) => ({
867+ connectionState: pc.connectionState,
868+ iceConnectionState: pc.iceConnectionState,
869+ iceGatheringState: pc.iceGatheringState,
870+ signalingState: pc.signalingState,
871+ }));
872+ return {
873+ bodyText: (document.body?.innerText || "").slice(0, 1000),
874+ canvases: document.querySelectorAll("canvas.stream-canvas").length,
875+ location: window.location.href,
876+ peerConnections,
877+ sessionClientId: window.sessionStorage.getItem("simdeck.streamClientId") || "",
878+ statusText: document.querySelector("[data-testid='stream-status']")?.textContent || "",
879+ title: document.title,
880+ videos,
881+ };
882+ })()
883+ ` ,
884+ ) ;
885+ const metrics = await fetchJson ( endpoint ( "/api/metrics" ) ) . catch ( ( error ) => ( {
886+ error : String ( error ?. message ?? error ) ,
887+ } ) ) ;
888+ return {
889+ clientId,
890+ page,
891+ streams : Array . isArray ( metrics ?. client_streams )
892+ ? findClientStreams ( metrics , clientId ) . map ( ( stream ) => ( {
893+ codec : stream . codec ,
894+ decodedFrames : stream . decodedFrames ,
895+ detail : stream . detail ,
896+ droppedFrames : stream . droppedFrames ,
897+ height : stream . height ,
898+ kind : stream . kind ,
899+ latestFrameGapMs : stream . latestFrameGapMs ,
900+ receivedPackets : stream . receivedPackets ,
901+ reconnects : stream . reconnects ,
902+ renderedFrames : stream . renderedFrames ,
903+ status : stream . status ,
904+ udid : stream . udid ,
905+ width : stream . width ,
906+ } ) )
907+ : metrics ,
908+ } ;
909+ }
910+
843911async function createPageTarget ( url ) {
844912 const response = await fetch (
845913 `http://127.0.0.1:${ debugPort } /json/new?${ encodeURIComponent ( url ) } ` ,
0 commit comments