"""Windows: reliably reading a browser's address-bar URL needs UI Automation (pywinauto/uiautomation). We attempt a lightweight UIA read if available and otherwise return None, letting the detector fall back to visual address-bar reading from the screenshot. """ from typing import Optional def get_active_tab_url() -> Optional[str]: try: import uiautomation as auto # optional dependency except Exception: return None try: window = auto.GetForegroundControl() # Chromium/Firefox expose the address bar as an Edit control named # "Address and search bar" / "Search or enter address". edit = window.EditControl(searchDepth=12) if edit.Exists(0.3): val = (edit.GetValuePattern().Value or "").strip() return val or None except Exception: return None return None