#!/usr/bin/python3
"""Exec Chrome in-place; preserve CDP fd3/fd4 and the spawner's PID/PGID."""
import os,sys,json,datetime,time,subprocess,pathlib
p=pathlib.Path(os.environ['CAPTURE_RUN_DIR'])/'browser.jsonl'
event={'time':datetime.datetime.now(datetime.timezone.utc).isoformat(),'mono_ns':str(time.monotonic_ns()),'pid':os.getpid(),'ppid':os.getppid(),'event':'browser_start','ps':subprocess.check_output(['ps','-o','pid,ppid,pgid,sid,stat,etime,cmd','-p',str(os.getpid())],text=True)}
with p.open('a') as f:f.write(json.dumps(event)+'\n')
os.execv(os.environ['CAPTURE_CHROME'],[os.environ['CAPTURE_CHROME'],*sys.argv[1:]])
