--- id: "593dd201-cd5a-43c0-9fa0-4ccf245d5323" name: "Star Clicking via CDP" micro_summary: "Stars Gmail messages with CDP mouse events using the explicit session_id; synthetic DOM events fail Gmail's trusted-event check." status: "resolved" see_also: [] scope: "How to star/unstar Gmail emails. All DOM-based approaches fail because Gmail checks isTrusted. Only CDP Input.dispatchMouseEvent with explicit session_id works." --- ## The Working Approach Only CDP `Input.dispatchMouseEvent` with explicit session_id works. Gmail checks `event.isTrusted` and rejects all synthetic DOM events. ```python sid = switch_tab(gmail_targetId) # 1. Find and scroll to the star js("document.querySelector('[aria-label=\"Not starred\"]').scrollIntoView({block: 'center'})") time.sleep(0.5) # 2. Get viewport position pos = js("""(() => { const el = document.querySelector('[aria-label="Not starred"]'); const r = el.getBoundingClientRect(); return JSON.stringify({x: Math.round(r.left + r.width/2), y: Math.round(r.top + r.height/2)}); })()""") # 3. Click with CDP using session_id from switch_tab cdp("Input.dispatchMouseEvent", type="mousePressed", x=pos["x"], y=pos["y"], button="left", clickCount=1, session_id=sid) time.sleep(0.1) cdp("Input.dispatchMouseEvent", type="mouseReleased", x=pos["x"], y=pos["y"], button="left", clickCount=1, session_id=sid) ``` ## Why Everything Else Failed Read children for discarded probes. Root cause: Gmail's event handler checks `event.isTrusted`, which is only true for events dispatched by the browser itself (i.e., CDP Input.dispatch*). All JS-based approaches (.click, dispatchEvent, KeyboardEvent) produce `isTrusted: false`.