Skip to main content

Emulate and Automate Chrome using Profiles and Selenium

Project description

Selenium-Profiles

Downloads

for the latest features, have a look at the dev branch

Feel free to test my code!

Getting Started

Dependencies

Installing

  • Install Google-Chrome (or another chromium-based browser)
  • pip install selenium-profiles

Start Driver

from selenium_profiles.webdriver import Chrome
from selenium_profiles.profiles import profiles
from selenium.webdriver.common.by import By  # locate elements
from selenium.webdriver import ChromeOptions


profile = profiles.Windows()
options = ChromeOptions()
mydriver = Chrome(profile, options=options, uc_driver=False)
# mydriver.options.add_argument("--headless=new")

driver = mydriver.start()  # or .Android

# get url
driver.get('https://abrahamjuliot.github.io/creepjs/')  # 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!

Run with Google-Colab

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

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

Profiles

Example Profile:

profile = \
{
  "options": {
      "sandbox": True,
      "window_size": {"x":1024,"y":648},
      "headless": False,
      "load_images": True,
      "incognito": True,
      "touch": True,
      "app": False,
      "gpu": False,
      "proxy": "http://example-proxy.com:9000", # note: auth not supported,
      "extension_paths": ["path/to/extension_1", ...], # directory, .crx or .zip
      "auth_proxy": {
            "host":"host", "port":9000,
            "username":"user", "password":"password", 
            "temp_dir": "C:/Downloads/proxy_extension"
                },
      "args": ["--my-arg1", ...],
      "capabilities": {"cap_1":"val_1", "cap_2":"val_2"},
      "experimental_options":{"option1":"value1", "option2":"value2"},
      "adb": False, # run on harware device over ADB
      "adb_package": "com.android.chrome",
      "use_running_app": True
  },
  "cdp": {
    "touch": True,
    "darkmode":None,
    "maxtouchpoints": 5,
    "cores":8,
    "cdp_args": [],
    "emulation": {"mobile":True,"width": 384, "height": 700, "deviceScaleFactor": 10,
        "screenOrientation": {"type": "portrait-primary", "angle": 0}},
    "patch_version": True, # to patch automatically, or use "111.0.5563.111"
    "useragent": {
                "platform": "Linux aarch64",
                "acceptLanguage":"en-US",
                "userAgent": "Mozilla/5.0 (Linux; Android 11; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Mobile Safari/537.36",
                "userAgentMetadata": {
                    "brands": [{"brand": "Google Chrome", "version": "105"}, {"brand": "Not)A;Brand", "version": "8"},
                               {"brand": "Chromium", "version": "105"}],
                    "fullVersionList": [{"brand": "Google Chrome", "version": "105.0.5195.136"},
                                        {"brand": "Not)A;Brand", "version": "8.0.0.0"},
                                        {"brand": "Chromium", "version": "105.0.5195.136"}],
                    "fullVersion": "105.0.5195.136",
                    "platform": "Android",
                    "platformVersion": "11.0.0",
                    "architecture": "",
                    "model": "HD1913",
                    "mobile": True,
                    "bitness": "",
                    "wow64": False}
    }
  }
}

Modify-headers

using selenium-wire

from selenium_profiles import webdriver
from selenium_profiles.profiles import profiles

profile = profiles.Android()

mydriver = webdriver.Chrome(profile, uc_driver=False, seleniumwire_options=True) # or pass seleniumwire-options
driver = mydriver.start()

def interceptor(request):
    request.headers['New-Header'] = 'Some Value'
driver.request_interceptor = interceptor

# checkout headers
driver.get("https://httpbin.org/headers")

input("Press ENTER to quit..")
driver.quit()
exit()

Touch_actions

Example demonstration script

from selenium_profiles.webdriver import Chrome, ChromeOptions
from selenium_profiles.profiles import profiles
from selenium.webdriver.common.by import By

from selenium_profiles.scripts.driver_utils import TouchActionChain


# Start Driver
options = ChromeOptions()
profile = profiles.Android()
mydriver = Chrome(profile, uc_driver=False, options=ChromeOptions)
driver = mydriver.start()  # or .Android

# initialise touch_actions
chain = TouchActionChain(driver)

driver.get("https://cps-check.com/de/multi-touch-test")

touch_box = driver.find_element(By.XPATH,'//*[@id="box"]') # Get element



chain.touch_and_hold(touch_box)
chain.pause(10)
chain.release(touch_box)

# perform actions
chain.perform()

# now you should see a touch indication
# point on the Website for 10 seconds

# quit driver
input('Press ENTER to quit Driver\n')
driver.quit()

To export a profile:

go to https://js.do/kaliiiiiiiiiii/get_profile in your browser and copy the text.

Help

Please feel free to open an issue or fork!

Known Bugs

Todo

  • js-undetectability
    • [navigator.connection]
    • fonts don't match platform
    • does not match worker scope (Emulation) crbug#1358491
      • Navigator.userAgent
      • Navigator.platform
      • navigator.hardwareConcurrency
  • allow passing seleniumwire-options => discussion
  • default metrics
    • Android
    • Windows
    • IOS
    • Linux
    • Tablet
  • test.py script
    • test_driver.py
      • assert useragent, profile_export (no error)
        • Windows
          • useragent-data
          • undetected
            • headless
        • Android
        • useragent-data
        • undetected
          • headless
  • audio_captcha_solver
  • support for
    • Windows
    • Jupyter Notebook (Google-Colab)
    • Linux

Deprecated

Authors

Aurin Aegerter

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

selenium_profiles-2.2.6.tar.gz (28.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page