from flask import Flask, render_template_string, request, redirect, url_for from selenium import webdriver from selenium.webdriver.chrome.options import Options import threading app = Flask(__name__) # Start browser in kiosk mode at server startup chrome_options = Options() chrome_options.add_argument("--kiosk") # Fullscreen, good for TV chrome_options.add_argument("--disable-blink-features=AutomationControlled") # chrome_options.add_experimental_option("detach", True) # Prevents Chrome from closing when script ends # Store the browser globally browser = webdriver.Chrome(options=chrome_options) browser.get("about:blank") @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": url = request.form.get("url") if url: # Ensure URL has a protocol if not url.startswith(("http://", "https://")): url = "http://" + url # Use Selenium to navigate current tab to new URL browser.get(url) return redirect(url_for("index")) # Render a minimalist HTML page return render_template_string("""