importjustpyasjpimporttimeimportasynciodefmouse_moved(self,msg):print('mouse moved')msg.page.start_time=time.perf_counter()returnTrueasyncdefidle_test():wp=jp.WebPage()wp.start_time=time.perf_counter()d=jp.Div(style='height: 100vh',a=wp)d.add_event('mousemove')d.on('mousemove',mouse_moved)wp.idle_div=jp.Div(text='Idle time',classes='m-4 text-lg',a=d)# Has to be in request handler so can be specific per pageasyncdefmonitor_timer():keep_monitoring=Trueidle_threshold=5whilekeep_monitoring:try:awaitasyncio.sleep(5)idle_time=time.perf_counter()-wp.start_timeifidle_time>idle_threshold:wp.idle_div.text=f'Idle for {idle_time} seconds'jp.run_task(wp.update())except:# When page is closed, it will be erased, the exception will occur and the task will terminatekeep_monitoring=Falsejp.run_task(monitor_timer())returnwpjp.justpy(idle_test)