Thursday, 17 June 2021

How to add or remove Chrome Extensions "after" selenium web-driver has been instantiated / defined?

The title says it all - I am looking for a way (or ways) to load, enable, add (and likewise: disable / remove) extensions after the webdriver has been created.

Context: Python, selenium (per tags). Pyautogui for certain parts would be unavoidable, but would need to be robust. I have a draft working soln but its rough and a little GPU dependent (point: can/will not accept "this cannot be done with Chrome" as I know it can be done, but would like to see some soln/code to this effect).

I am perfectly aware of the various methods to load an extension prior to the driver being instantiated / created. i.e.

  1. o.add_extension(crx file location)
  2. o.add_argument(unpacked folder loc)
  3. o.add_argument('--user-data-dir=' + profileX)

where o = Options, profileX has extensions pre-installed and so forth. So will be clear - I am completely uninterested in proposals to this effect.

Any ideas/proposals in regards to the question in the title/above?

Ideally (but not absolutely critical) would be a programmatic solution that is not entirely GUI based (robotic/PyAutogui dependent).

You can assume the extension is available on the chrome store for this exercise.

Use-case: The extension I'm testing involves registering points and to protect fair / intended usage terms, its designed to cease functioning whenever it recognises automated manipulation (which is perfectly possible with 'headed' chrome, e.g. you just assign it a hotkey in chrome settings, and use Pyautogui to activate, or locate it's html page and interact directly etc.). GIVEN this, and the very many, many tests I have, it seems a waste of resource me having to reload the tests, or set up profiles, or stop and start the tests every so often so that I can include 'fresh' copies of the crx files or deploy one of the other methods I mention above. To date / my best knowledge, there is no solution for this. Happy to be pleasantly surprised if someone can point me to a 'duplicate' Q in this regard.



from How to add or remove Chrome Extensions "after" selenium web-driver has been instantiated / defined?

No comments:

Post a Comment