Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Enhance terminal reset handling on second Ctrl+C for improved user experience
Max Comperatoreacf5e4f3e2bf
diff --git a/browser_use/utils.py b/browser_use/utils.pyindex 95ea0ee51..b3759f4eb 100644--- a/browser_use/utils.py+++ b/browser_use/utils.py@@ -136,9 +136,30 @@ class SignalHandler:# Force immediate exit - more reliable than sys.exit()print('\n\n🛑 Got second Ctrl+C. Exiting immediately...\n', file=stderr)- # write carriage return + newline + ASNI reset to both stdout and stderr to clear any color codes- print('\r\033[0m', end='', flush=True, file=stderr)- print('\r\033[0m', end='', flush=True)++ # Reset terminal to a clean state by sending multiple escape sequences+ # Order matters for terminal resets - we try different approaches++ # Reset terminal modes for both stdout and stderr+ print('\033[?25h', end='', flush=True, file=stderr) # Show cursor+ print('\033[?25h', end='', flush=True) # Show cursor++ # Reset text attributes and terminal modes+ print('\033[0m', end='', flush=True, file=stderr) # Reset text attributes+ print('\033[0m', end='', flush=True) # Reset text attributes++ # Disable special input modes that may cause arrow keys to output control chars+ print('\033[?1l', end='', flush=True, file=stderr) # Reset cursor keys to normal mode+ print('\033[?1l', end='', flush=True) # Reset cursor keys to normal mode++ # Disable bracketed paste mode+ print('\033[?2004l', end='', flush=True, file=stderr)+ print('\033[?2004l', end='', flush=True)++ # Carriage return helps ensure a clean line+ print('\r', end='', flush=True, file=stderr)+ print('\r', end='', flush=True)+os._exit(0)def sigint_handler(self) -> None: