import sys from selenium import webdriver def run_js_in_browser(js_file_path): with open(js_file_path, 'r') as file: js_code = file.read() options = webdriver.ChromeOptions() options.set_capability('goog:loggingPrefs', {'browser': 'ALL'}) driver = webdriver.Remote( command_executor='http://localhost:4444/wd/hub', options=options, ) driver.get("about:blank") res = driver.execute_script(js_code) print(res) for entry in driver.get_log('browser'): print(entry) driver.quit() if __name__ == "__main__": if len(sys.argv) < 2: print("Usage: python run_js.py ") sys.exit(1) js_file_path = sys.argv[1] run_js_in_browser(js_file_path)