I’m trying to open a Chrome browser using undetected-chromedriver in Python, specifying a remote debugging port, and I want the browser to remain open after the script finishes. Here is my current code:
import undetected_chromedriver as uc
import sys
if len(sys.argv) != 3:
print("Usage: python open_browser.py <url> <port>")
sys.exit(1)
url = sys.argv[1]
port = sys.argv[2]
# ChromeOptions configuration
options = uc.ChromeOptions()
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument(f"--remote-debugging-port={port}")
# Start ChromeDriver
driver = uc.Chrome(options=options)
# Open the provided URL
driver.get(url)
# Print a message and exit the script
print(f"Browser opened at {url} with remote debugging port {port}.")
When I run this script with:
python open_browser.py https://www.example.com 9222
The browser opens correctly, but I need to ensure that the browser remains open after the Python script finishes. How can I achieve this?
I don’t want my program to get stuck with while(true) or an input(”), I want the browser to stay open after execution
Any help would be greatly appreciated!