@@ -3045,6 +3045,62 @@ interface StaticVerificationDependencies {
30453045 capture ?: typeof pageScreenshotCapture ;
30463046}
30473047
3048+ /**
3049+ * Prepare an isolated page for static-frame verification. Verification seeks
3050+ * intentionally visit frames out of capture order, so they must never mutate
3051+ * the page that will later be captured sequentially.
3052+ */
3053+ export async function createStaticVerificationPage ( session : CaptureSession ) : Promise < Page > {
3054+ const page = await session . browser . newPage ( ) ;
3055+ const pageNavigationTimeout =
3056+ session . config ?. pageNavigationTimeout ?? DEFAULT_CONFIG . pageNavigationTimeout ;
3057+ const pageReadyTimeout = session . config ?. playerReadyTimeout ?? DEFAULT_CONFIG . playerReadyTimeout ;
3058+
3059+ try {
3060+ await page . evaluateOnNewDocument ( ( ) => {
3061+ const w = window as unknown as { __name ?: < T > ( fn : T , _name : string ) => T } ;
3062+ if ( typeof w . __name !== "function" ) {
3063+ w . __name = < T > ( fn : T , _name : string ) : T => fn ;
3064+ }
3065+ } ) ;
3066+ if ( session . options . variables && Object . keys ( session . options . variables ) . length > 0 ) {
3067+ const variablesJson = JSON . stringify ( session . options . variables ) ;
3068+ await page . evaluateOnNewDocument ( ( json : string ) => {
3069+ ( window as Window & { __hfVariables ?: Record < string , unknown > } ) . __hfVariables =
3070+ JSON . parse ( json ) ;
3071+ } , variablesJson ) ;
3072+ }
3073+ await page . setViewport ( {
3074+ width : session . options . width ,
3075+ height : session . options . height ,
3076+ deviceScaleFactor : session . options . deviceScaleFactor || 1 ,
3077+ } ) ;
3078+ await page . goto ( `${ session . serverUrl } /index.html` , {
3079+ waitUntil : "domcontentloaded" ,
3080+ timeout : pageNavigationTimeout ,
3081+ } ) ;
3082+ await page . evaluate ( `window.__hfFlushSync?.()` ) ;
3083+ await pollHfReady ( page , pageReadyTimeout ) ;
3084+ await pollSubCompositionTimelines ( page , pageReadyTimeout ) ;
3085+ await applyVideoMetadataHints ( page , session . options . videoMetadataHints ) ;
3086+
3087+ const skipVideoIds = session . options . skipReadinessVideoIds ?? [ ] ;
3088+ await Promise . all ( [
3089+ pollVideosReady ( page , skipVideoIds , pageReadyTimeout ) ,
3090+ pollImagesReady ( page , pageReadyTimeout ) . then ( ( ready ) =>
3091+ ready ? decodeAllImages ( page ) : undefined ,
3092+ ) ,
3093+ page . evaluate ( `document.fonts?.ready` ) ,
3094+ waitForOptionalTailwindReady ( page , pageReadyTimeout ) ,
3095+ ] ) ;
3096+ if ( session . options . format === "png" ) await initTransparentBackground ( page ) ;
3097+ return page ;
3098+ } catch ( error ) {
3099+ await page . close ( ) . catch ( ( ) => { } ) ;
3100+ throw error ;
3101+ }
3102+ }
3103+
30483104/**
30493105 * Empirically verify the predicted-static set before trusting it. Group static frames
30503106 * into runs; each run [a..b] reuses anchor a-1. CRITICAL: compare against the ANCHOR,
@@ -3236,7 +3292,24 @@ async function armStaticDedup(
32363292 ) ;
32373293 return ;
32383294 }
3239- const verdict = await verifyStaticFramesSafe ( session , page , stats . staticFrameSet , fps , samples ) ;
3295+ let verificationPage : Page | undefined ;
3296+ let verdict : StaticVerificationResult ;
3297+ try {
3298+ verificationPage = await createStaticVerificationPage ( session ) ;
3299+ verdict = await verifyStaticFramesSafe (
3300+ session ,
3301+ verificationPage ,
3302+ stats . staticFrameSet ,
3303+ fps ,
3304+ samples ,
3305+ ) ;
3306+ } catch {
3307+ session . staticDedupSkipReason = "verification_failed" ;
3308+ logInitPhase ( "static-frame dedup: disabled (verification infrastructure failure)" ) ;
3309+ return ;
3310+ } finally {
3311+ await verificationPage ?. close ( ) . catch ( ( ) => { } ) ;
3312+ }
32403313 session . staticDedupVerification = verdict ;
32413314 if ( verdict . outcome === "mismatch" || verdict . outcome === "infrastructure" ) {
32423315 session . staticDedupSkipReason = "verification_failed" ;
0 commit comments