@@ -5,17 +5,17 @@ import type {
55} from "../../core/src/runtime/timelineInspection" ;
66import type { RuntimeQuery , RuntimeResponse } from "./types" ;
77
8- /**
9- * Runs a function inside the inspected document: Puppeteer's page for headless inspection, the host's preview frame
10- * for live inspection. `fn` crosses into the page as source text, so it may not refer to anything outside its body.
11- */
128export interface PageRunner {
139 run < A , R > ( fn : ( arg : A ) => R , arg : A ) : Promise < R > ;
1410}
1511
1612export interface PageTimeline extends TimelineRuntimeResult {
17- /** At a boundary: for each animation crossing it, the next one on the same target and property. */
1813 following : TimelineEvent [ ] ;
14+ generation : string | null ;
15+ }
16+
17+ export interface PageRuntimeResponse extends RuntimeResponse {
18+ generation : string | null ;
1919}
2020
2121type InspectedWindow = Window & {
@@ -36,7 +36,6 @@ export interface PlayerState {
3636 duration : number | undefined ;
3737}
3838
39- /** Moves the player, so only a page the inspector owns may run it, never a person's preview. */
4039export function seekPage ( time : number ) : void {
4140 const player = ( window as InspectedWindow ) . __player ;
4241 if ( ! player ) throw new Error ( "player_unavailable" ) ;
@@ -48,18 +47,24 @@ export function playerStatePage(): PlayerState {
4847 return { time : player ?. getTime ( ) , duration : player ?. getDuration ( ) } ;
4948}
5049
51- export function queryPage ( query : RuntimeQuery ) : RuntimeResponse {
52- const inspection = ( window as InspectedWindow ) . __hfInspection ;
50+ export function queryPage ( query : RuntimeQuery ) : PageRuntimeResponse {
51+ const inspected = window as InspectedWindow ;
52+ const inspection = inspected . __hfInspection ;
5353 if ( ! inspection ) throw new Error ( "inspector_unavailable" ) ;
54- return inspection . query ( query ) ;
54+ return {
55+ generation : inspected . __hfLiveInspection ?. generation ?? null ,
56+ ...inspection . query ( query ) ,
57+ } ;
5558}
5659
5760export function timelinePage ( request : TimelineRequest ) : PageTimeline {
58- const inspection = ( window as InspectedWindow ) . __hfInspection ;
61+ const inspected = window as InspectedWindow ;
62+ const inspection = inspected . __hfInspection ;
5963 if ( ! inspection ) throw new Error ( "inspector_unavailable" ) ;
6064 const result = inspection . timeline ( request ) ;
6165 const following : TimelineEvent [ ] = [ ] ;
62- if ( request . boundary === undefined ) return { ...result , following } ;
66+ const generation = inspected . __hfLiveInspection ?. generation ?? null ;
67+ if ( request . boundary === undefined ) return { ...result , following, generation } ;
6368 const boundary = request . boundary ;
6469 const schedule = inspection . timeline ( { ...request , boundary : undefined } ) ;
6570 for ( const crossing of result . events ) {
@@ -77,10 +82,9 @@ export function timelinePage(request: TimelineRequest): PageTimeline {
7782 if ( next && ! following . includes ( next ) ) following . push ( next ) ;
7883 }
7984 }
80- return { ...result , following } ;
85+ return { ...result , following, generation } ;
8186}
8287
83- /** The generation stamped into a live preview when its document was prepared, or null in any other page. */
8488export function liveGenerationPage ( ) : string | null {
8589 return ( window as InspectedWindow ) . __hfLiveInspection ?. generation ?? null ;
8690}
0 commit comments