botasaurus
botasaurus copied to clipboard
js_to_run_before_new_document :: ChromeException: Invalid parameters [code: -32602]
This code worked on earlier versions of chrome. Specifically I just tested on chrome 132 and it doesn't produce error:
from botasaurus.browser import browser, Driver
@browser(output=None)
def run_first(driver: Driver, data):
early_script = "alert('Run it before page loads!');"
driver.get('https://www.google.com', js_to_run_before_new_document=early_script)
run_first()
However chrome version 137 produced following error:
File "C:\Users\Admin\AppData\Local\Programs\Python\Python313\Lib\site-packages\botasaurus_driver\driver.py", line 757, in run_cdp_command
return self._tab.run_cdp_command(command)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python313\Lib\site-packages\botasaurus_driver\core\tab.py", line 933, in run_cdp_command
return self.send(command)
~~~~~~~~~^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python313\Lib\site-packages\botasaurus_driver\core\connection.py", line 290, in send
return self.perform_send(cdp_obj, _is_update, wait_for_response)
~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Admin\AppData\Local\Programs\Python\Python313\Lib\site-packages\botasaurus_driver\core\connection.py", line 311, in perform_send
result = parse_response(result, cdp_obj)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python313\Lib\site-packages\botasaurus_driver\core\connection.py", line 50, in parse_response
raise ChromeException(response["error"])
botasaurus_driver.exceptions.ChromeException: Invalid parameters [code: -32602]
Did u find the solutions?
Try via CDP command
driver.run_cdp_command(cdp.page.add_script_to_evaluate_on_new_document(js_code_string)
It is not working here is the code
from botasaurus.browser import browser, Driver,cdp import time @browser(output=None) def run_first(driver: Driver, data): time.sleep(4) js_code_string = "console.log('Run it before page loads!');" driver.run_cdp_command(cdp.page.add_script_to_evaluate_on_new_document(js_code_string)) driver.prompt() run_first()