diff --git a/tests/agent/test_vault_fill_scripts.py b/tests/agent/test_vault_fill_scripts.py index 04fa5c248f..2ddf4cfb5a 100644 --- a/tests/agent/test_vault_fill_scripts.py +++ b/tests/agent/test_vault_fill_scripts.py @@ -357,3 +357,15 @@ class TestForgedVerdicts: """ out = _run(setup, _GUARDED_SCRIPTS[script]()) assert isinstance(out, dict) and "refused" not in out, out + + @pytest.mark.parametrize("page", ["json-stringify", "everything"]) + def test_a_page_cannot_claim_a_focus_it_does_not_hold(self, page): + """On the checked origin too, the focus verdict is the script's own: focus held by another + element (an iframe's host, a decoy input) reads as lost whatever the page's JSON says.""" + setup = """ + const pw = stamp(add(document, "input", { type: "password", value: "" }), 1); + const decoy = add(document, "iframe"); + pw.focus = () => focusOn(decoy); + """ + _LYING_PAGES[page] + out = _run(setup, _GUARDED_SCRIPTS["focus"]()) + assert isinstance(out, dict) and out.get("refused") == "focus_lost", out diff --git a/tools/browser_supervisor.py b/tools/browser_supervisor.py index 9223ab2e76..19aa80c70c 100644 --- a/tools/browser_supervisor.py +++ b/tools/browser_supervisor.py @@ -502,7 +502,6 @@ class CDPSupervisor(DialogSupervisionMixin, FrameTrackingMixin): # are deliberately kept — they reconcile as fresh events arrive (worst case a # stale dialog entry is rejected with "no dialog is showing", logged only). self._page_session_id = None - self._documents.clear() # session ids die with the connection await self._attach_initial_page() self._set_active(True) last_success_at = time.time() diff --git a/tools/browser_supervisor_frames.py b/tools/browser_supervisor_frames.py index ca87a79fc6..9c884ec494 100644 --- a/tools/browser_supervisor_frames.py +++ b/tools/browser_supervisor_frames.py @@ -132,7 +132,6 @@ class FrameTrackingMixin: with self._state_lock: self._frames.update({fid: replace(f, cdp_session_id=None) for fid, f in self._frames.items() if f.cdp_session_id == sid}) - self._documents.pop(sid, None) def _build_frame_tree_locked(self) -> dict[str, Any]: """Capped frame_tree payload (must hold state lock). Top frame = one with