{"record":{"id":"51043ebc609ffb37","repo":"browser-use/browser-use","slug":"source-element-is-not-visible","errorCode":null,"errorMessage":"Source element is not visible","messagePattern":"Source element is not visible","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"browser_use/actor/element.py","lineNumber":602,"sourceCode":"\t\t\t\t\t\t# Create an Element for the option and click it\n\t\t\t\t\t\toption_element = Element(self._browser_session, option_backend_id, self._session_id)\n\t\t\t\t\t\tawait option_element.click()\n\n\tasync def drag_to(\n\t\tself,\n\t\ttarget: Union['Element', Position],\n\t\tsource_position: Position | None = None,\n\t\ttarget_position: Position | None = None,\n\t) -> None:\n\t\t\"\"\"Drag this element to another element or position.\"\"\"\n\t\t# Get source coordinates\n\t\tif source_position:\n\t\t\tsource_x = source_position['x']\n\t\t\tsource_y = source_position['y']\n\t\telse:\n\t\t\tsource_box = await self.get_bounding_box()\n\t\t\tif not source_box:\n\t\t\t\traise RuntimeError('Source element is not visible')\n\t\t\tsource_x = source_box['x'] + source_box['width'] / 2\n\t\t\tsource_y = source_box['y'] + source_box['height'] / 2\n\n\t\t# Get target coordinates\n\t\tif isinstance(target, dict) and 'x' in target and 'y' in target:\n\t\t\ttarget_x = target['x']\n\t\t\ttarget_y = target['y']\n\t\telse:\n\t\t\tif target_position:\n\t\t\t\ttarget_box = await target.get_bounding_box()\n\t\t\t\tif not target_box:\n\t\t\t\t\traise RuntimeError('Target element is not visible')\n\t\t\t\ttarget_x = target_box['x'] + target_position['x']\n\t\t\t\ttarget_y = target_box['y'] + target_position['y']\n\t\t\telse:\n\t\t\t\ttarget_box = await target.get_bounding_box()\n\t\t\t\tif not target_box:\n\t\t\t\t\traise RuntimeError('Target element is not visible')","sourceCodeStart":584,"sourceCodeEnd":620,"githubUrl":"https://github.com/browser-use/browser-use/blob/6c73fced2f6d45a11d88622fe56365a5fe18f28b/browser_use/actor/element.py#L584-L620","documentation":"A registered action declares `page` (a Playwright/Page-like object for a single tab) with no default, and the injected value was None. The page dependency is derived from the browser session's active tab, so None means there is no active page — session missing, closed, or all tabs closed.","triggerScenarios":"Calling a page-dependent action when browser_session is absent or has no active tab: browser not started, tab closed by a prior step, or direct invocation with page=None.","commonSituations":"Actions like 'evaluate on current page' invoked after close_tab closed the last tab; tests calling the action without a live browser; race where the action runs after the session shut down.","solutions":["Ensure a live session with at least one open tab exists before the call: start Browser, navigate somewhere, then invoke the action.","For tab-closing actions, guard with a check on remaining tab count before closing the last tab.","Pass page explicitly from the session's active page when orchestrating manually."],"exampleFix":"# before\nresult = await run_js(js='document.title')  # page resolves to None\n\n# after\npage = await session.get_current_page()  # ensure a tab is open\nresult = await run_js(js='document.title', page=page)","handlingStrategy":"validation","validationCode":"async def has_active_page(session) -> bool:\n    try:\n        page = await session.get_current_page()\n        return page is not None and not page.is_closed()\n    except Exception:\n        return False","typeGuard":"def requires_page(func) -> bool:\n    import inspect, inspect as i\n    p = inspect.signature(func).parameters.get('page')\n    return p is not None and p.default is i.Parameter.empty","tryCatchPattern":"try:\n    await action(**kwargs)\nexcept ValueError as e:\n    if 'requires page' in str(e):\n        page = await session.get_current_page()\n        await action(**kwargs, page=page)","preventionTips":["Verify a tab is open before page-scoped actions.","Depend on browser_session instead of page in custom actions for simpler wiring.","Guard tab-closing logic so the last tab is never closed mid-run."],"tags":["custom-actions","page","dependency-injection","browser-use"],"backgroundTag":null,"analyzedSha":"6c73fced2f6d45a11d88622fe56365a5fe18f28b","analyzedAt":"2026-08-14T19:42:40.557Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}