0

I need to modify a JavaScript that runs on a webpage. The procedure described here Override Javascript file in chrome works fine if I set it up manually, however, I would like to set up the override programatically using Selenium (either Geckodriver or Chromedriver) and Python. Is that at all possible? I have the modified JavaScript on my local computer.

Per
  • 43
  • 5
  • [This](https://www.tutorialspoint.com/how-to-execute-a-javascript-using-selenium-in-python#:~:text=Selenium%20executes%20the%20Javascript%20commands,help%20of%20the%20Javascript%20Executor.)? – Wakeme UpNow Feb 13 '23 at 06:50
  • Hi Wakeme, I gave it a try but it does not seem to work.The JavaScript on the site continuously handles messages received over a websocket. If I understand the link you send correctly, it allows to execute a JavaScript once, however, I need to handle the messages received over the websocket continously using my modified JavaScript code. – Per Feb 13 '23 at 13:15
  • Like on every event message? – Wakeme UpNow Feb 13 '23 at 13:17
  • yes, exactly. It works fine when setting up the overrides manually using the developer tools in Chrome as in this example https://stackoverflow.com/questions/35580017/override-javascript-file-in-chrome however, I would like to set this up from python – Per Feb 13 '23 at 14:26
  • [This](https://stackoverflow.com/questions/31354352/selenium-how-to-inject-execute-a-javascript-in-to-a-page-before-loading-executi), or [this](https://stackoverflow.com/questions/68620443/how-to-inject-javascript-into-page-before-page-loads-with-selenium) (See `execute_cdp_cmd`)? – Wakeme UpNow Feb 13 '23 at 14:45
  • I tried both, but could not make any of them work, any other suggestions are welcome – Per Feb 14 '23 at 07:11

0 Answers0