/Selenium-Profiles

undetected Selenium using chromedriver and emulation / device profiles

Primary LanguageJupyter NotebookOtherNOASSERTION

Selenium-Profiles V2

  • Overwrite device metrics using Selenium
  • Mobile and Desktop emulation
  • Undetected by Google, Cloudflare, ..
  • Modifying or adding headers supported using "ModHeader" chrome-extension

Feel free to test my code!

Getting Started

Dependencies

Installing

Start Driver

from selenium_profiles.driver import driver as mydriver
from selenium_profiles.profiles import profiles
from selenium.webdriver.common.by import By  # locate elements

mydriver = mydriver()
driver = mydriver.start(profiles.Windows(), uc_driver=False)  # or .Android

# get url
driver.get('https://browserleaks.com/client-hints')  # test client hints

input("Press ENTER to exit: ")
driver.quit()  # Execute on the End!

Don't forget to execute driver.quit() in the End. Else-wise your temporary folder will get flooded! (Windows)

Run with Google-Colab

Google-Colab (file: google-colab/selenium_profiles.ipynb)

Profiles

Example Profile:

{
  "device":{
      "mobile": false,
      "model": "modelName",
      "language": "de-CH,de;q=0.9",
      "touch_device": true,
      "maxtouchpoints": 5,
      "hardware_accel": false,
      "emulation": {"width": 384, "height": 700, "deviceScaleFactor": 10,
        "screenOrientation": {"type": "portraitPrimary", "angle": 0}},
      "agent_override": {
                "platform": "Win32",
                "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36",
                "userAgentMetadata": {
                    "brands": [{"brand":"Google Chrome","version":"107"},
                              {"brand":"Chromium","version":"107"},
                              {"brand":"Not=A?Brand","version":"24"}],
                    "fullVersionList": [{"brand":"Google Chrome","version":"107.0.5304.88"},
                                        {"brand":"Chromium","version":"107.0.5304.88"},
                                        {"brand":"Not=A?Brand","version":"24.0.0.0"}],
                    "fullVersion": "107.0.5304.88",
                    "platform": "Windows",
                    "platformVersion": "10.0.0",
                    "architecture": "x86",
                    "model": "modelName",
                    "mobile": true,
                    "bitness": "64",
                    "wow64": false}
    }},
  "browser": {
      "sandbox": true, "inkognito": true,"headless":false, "proxy": null, "darkmode": true,
      "pointer_as_touch": false, "mobile_view":  false, "app": false, "touch_events": true,
      "window_size": {"x": 400, "y": 400}
    },
  "chromeoptions": {"arguments": ["--my-argument=value", ".."], "capabilities": [["cap_name", "cap_value"], ".."]},
  "cdp_cmd": [["name", "value"], ".."],
  "evaluate_on_new_document": "my_js_script",
  "plugins": {
      "selenium-wire": false,
      "modheader":"[{\"headers\":[{\"enabled\":true,\"name\":\"google\",\"value\":\"\\\"x\\\"\"}],\"shortTitle\":\"1\",\"title\":\"Profile 1\",\"version\":2}]",
      "stealth": false,
      "buster": false
    }
}

To export a profile:

go to https://jsconsole.com/ in your browser and copy the text.

and then run in Python:

from selenium_profiles.scripts.profiles import navigator2profile
myprofile = navigator2profile("my_copied_text", filename='myprofile.json')

Help

Please feel free to open an issue or fork!

Known Bugs

  • click_as_touch makes automation hung

Todo // Features

  • Undetected
  • support custom device metrics
  • export browser profile
  • Add License
  • installer.py script
  • Selenium-Devices as installable module
  • implement headless javascript headless
  • Mobile emulation
    • click_as touch makes code hung
  • default metrics
    • Android
    • Windows
    • IOS
    • Linux
    • Tablet
  • change metrics while running
    • disable emulation while running
  • test.py script
    • test_driver.py
      • useragent, profile_export (no error)
        • Windows
        • Android
  • plugins support
    • selenium-wire
    • modheader
      • load modheader profile
      • add headers without profile
    • stealth
  • audio_captcha_solver
  • Rewrite driver.py to V2.2
  • support for
    • Windows
    • Jupyter Notebook (Google-Colab)
    • Linux

Deprecated

Authors

Aurin Aegerter

Version History

  • patched_driverV1
    • first version as importable file
  • sel_profilesV2
    • added custom device metrics
    • added default.json metrics
      • Android
      • Windows
    • added navigator2profile, driver.get_profile()
    • added modheader (load modheader json profile)
    • put everything into folders
  • googleV1 (not released yet!)
    • first version as importable file
  • selenium-profilesV2.2
    • installable as module (pip) *selenium-profiles V2.2.4 (pre-release, unstable!)
    • removed undetected-chromedriver dependency
    • moved parts of driver to selenium_profiles/scripts

License

Shield: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Disclaimer

I am not responsible what you use the code for!!! Also no warranty!

Acknowledgments

Inspiration, code snippets, etc.