import { WaitForScript } from "@pioneerjs/core" ; import { LoginScript } from "../login/types" ; param script export async function waitForReady ( script ) { const waitFor = new WaitForScript ( script ) ; await waitFor . documentReady ( ) ; await waitFor . nextTick ( "requestfinished" ) ; } param script param selector export async function waitForClickAndNavigation ( script , selector ) { await Promise . all ( [ script . page . click ( selector ) , waitForReady ( script ) ] ) ; } param script param url export async function waitForNavigation ( script , url ) { await Promise . all ( [ script . page . goto ( url ) , waitForReady ( script ) ] ) ; } export function TimeoutTask ( period , task , timeout ) { return new Promise < any > ( async ( resolve , reject ) => { let resolved = false ; let to = setTimeout ( async ( ) => { if ( ! resolved ) { resolved = true ; await timeout ( ) ; setTimeout ( resolve , 3000 ) ; } } , period ) ; const v = await task ( ) ; if ( ! resolved ) { clearTimeout ( to ) ; resolved = true ; resolve ( v ) ; } } ) ; }