{"record":{"id":"353379677dfd4cbb","repo":"kovidgoyal/kitty","slug":"there-is-no-active-os-window-to-screenshot","errorCode":null,"errorMessage":"There is no active OS window to screenshot","messagePattern":"There is no active OS window to screenshot","errorType":"exception","errorClass":"RemoteControlErrorWithoutTraceback","httpStatus":null,"severity":"error","filePath":"kitty/rc/screenshot.py","lineNumber":95,"sourceCode":"            tab = w.tabref()\n            tm = tab.tab_manager_ref() if tab is not None else None\n            if tab is None or tm is None or tm.active_tab is not tab or not w.is_visible_in_layout:\n                raise RemoteControlErrorWithoutTraceback('The matched window is not currently visible, screenshots can only be taken of visible windows')\n            os_window_id = w.os_window_id\n            target_window_id = w.id\n        elif match_tab:\n            tabs = list(boss.match_tabs(match_tab))\n            if not tabs:\n                raise MatchError(match_tab, 'tabs')\n            tab = tabs[0]\n            tm = tab.tab_manager_ref()\n            if tm is None or tm.active_tab is not tab:\n                raise RemoteControlErrorWithoutTraceback('The matched tab is not currently visible, screenshots can only be taken of visible tabs')\n            os_window_id = tab.os_window_id\n        else:\n            atm = boss.active_tab_manager\n            if atm is None:\n                raise RemoteControlErrorWithoutTraceback('There is no active OS window to screenshot')\n            os_window_id = atm.os_window_id\n            include_tab_bar = True\n\n        output_path = payload_get('output_path') or ''\n        responder = self.create_async_responder(payload_get, window)\n\n        def callback(cb_os_window_id: int, cb_window_id: int, pixels: bytes, width: int, height: int) -> None:\n            if not pixels:\n                responder.send_error('Failed to take screenshot, the OS window may have been closed')\n                return\n            try:\n                png_data = png_from_32bit_rgba_data(pixels, width, height, True)\n                if output_path:\n                    with open(os.path.expanduser(output_path), 'wb') as f:\n                        f.write(png_data)\n                    responder.send_data(f'Screenshot saved to: {os.path.abspath(f.name)}')\n                else:\n                    responder.send_data(standard_b64encode(png_data).decode('ascii'))","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kitty/rc/screenshot.py#L77-L113","documentation":"Raised by the remote-control screenshot command when no OS window currently has focus/exists to capture. kitty can only screenshot a visible OS window; if there is no active tab manager (e.g. all windows closed or kitty is running headless), the command aborts.","triggerScenarios":"Running @screenshot via remote control without a --match for a tab while boss.active_tab_manager is None (no OS windows exist).","commonSituations":"Scripting kitty remote control while kitty has no open windows, or during startup/shutdown races.","solutions":["Ensure at least one OS window is open in the kitty instance before issuing the screenshot command","Pass a --match for a specific visible tab so the code path that resolves a tab's os_window_id is used instead","Retry after verifying kitty is running with windows open"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import subprocess\n# ensure kitty has windows before screenshotting\ndef kitty_has_windows():\n    out = subprocess.run(['kitten','@ls'],capture_output=True).stdout\n    return b'os_window_id' in out","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass --match for a visible tab when scripting screenshots","Check @ls output for open windows first"],"tags":["kitty","remote-control","screenshot"],"backgroundTag":"no-active-window","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}