1

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.

6
  • This? Commented Feb 13, 2023 at 6: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. Commented Feb 13, 2023 at 13:15
  • Like on every event message? Commented Feb 13, 2023 at 13:17
  • yes, exactly. It works fine when setting up the overrides manually using the developer tools in Chrome as in this example stackoverflow.com/questions/35580017/… however, I would like to set this up from python Commented Feb 13, 2023 at 14:26
  • This, or this (See execute_cdp_cmd)? Commented Feb 13, 2023 at 14:45

2 Answers 2

0

I suggest using the extension Resource Override, as stated in answer.

To load the extension setting, I tried to

    options = Options()
    options.add_argument("--user-data-dir=C:/Users/USERNAME/AppData/Local/Google/Chrome/User Data")
    driver = webdriver.Chrome(options=options)

I am not sure whether there is more elegant way to load the setting of the extension.

FYI: If you want to change the setting of the extensions programmatically, you can refer to this anwser

Sign up to request clarification or add additional context in comments.

Comments

0

You can create the required rules in Requestly and then using its APIs, import them in your automation where Requestly extension is installed. Your modified JavaScript would appear.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.