import { Page , ElementHandle , Frame } from 'playwright' ; declare const window ; export async function getFocusedHandle ( page ) { if ( ! page ) { throw new Error ( `Cannot get focused handle because no browser has been launched` ) ; } const focusedElement = await page . evaluateHandle ( ( ) => window . document . activeElement ) ; if ( focusedElement === null ) { return null ; } const handle = focusedElement . asElement ( ) ; return handle ; }