import type { Page , Serializable } from 'puppeteer' ; import type { PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router' ; type PageService = typeof PAGE_SERVICE_TOKEN ; type NavigateOptions = Parameters < PageService [ 'navigate' ] > [ 0 ] ; type UpdateCurrentRouteOptions = Parameters < PageService [ 'updateCurrentRoute' ] > [ 0 ] ; export const wrapRouter = ( page ) => { const navigate = async ( options ) => { return page . evaluate ( ( navigateOptions ) => { return ( window as any ) . contextExternal . di . get ( 'router pageService' ) . navigate ( navigateOptions ) ; } , ( options as unknown ) as Serializable ) ; } ; const navigateThenWaitForReload = async ( options ) => { return Promise . all ( [ page . evaluate ( ( navigateOptions ) => { ( window as any ) . contextExternal . di . get ( 'router pageService' ) . navigate ( navigateOptions ) ; } , ( options as unknown ) as Serializable ) , page . waitForNavigation ( ) , ] ) ; } ; const updateCurrentRoute = async ( options ) => { return page . evaluate ( ( navigateOptions ) => { return ( window as any ) . contextExternal . di . get ( 'router pageService' ) . updateCurrentRoute ( navigateOptions ) ; } , ( options as unknown ) as Serializable ) ; } ; return { navigate , navigateThenWaitForReload , updateCurrentRoute , } ; } ;