botasaurus icon indicating copy to clipboard operation
botasaurus copied to clipboard

js_to_run_before_new_document :: ChromeException: Invalid parameters [code: -32602]

Open b4git opened this issue 6 months ago • 3 comments

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]

b4git avatar Jun 10 '25 21:06 b4git

Did u find the solutions?

RizwanSabir avatar Sep 09 '25 13:09 RizwanSabir

Try via CDP command

driver.run_cdp_command(cdp.page.add_script_to_evaluate_on_new_document(js_code_string)

malek10xdev avatar Oct 05 '25 17:10 malek10xdev

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()

RizwanSabir avatar Oct 06 '25 06:10 RizwanSabir