import os, sys, time
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service

HERE = os.path.dirname(os.path.abspath(__file__))
GECKODRIVER = os.path.join(HERE, "geckodriver.exe")
BASE = "http://localhost:8000/field-capture.html?debug"

opts = Options()
opts.headless = False
svc = Service(executable_path=GECKODRIVER)
d = webdriver.Firefox(options=opts, service=svc)
d.set_window_size(480, 900)

d.get(BASE + "&_=" + str(int(time.time())))
time.sleep(2)

# Test explicit return
print("explicit return:", repr(d.execute_script("return 'hello';")))
# Test multi-line with explicit return
print("multi-line:", repr(d.execute_script("""
const x = 1;
return x + 1;
""")))
# Test side effects only (no return)
print("side effects only:", repr(d.execute_script("""
const x = 1;
""")))
d.quit()