Selenium-Profiles
- Overwrite device metrics using Selenium
- Mobile and Desktop emulation
- Undetected by Google, Cloudflare, creep-js using selenium-driverless
- Modifying headers supported using Selenium-Interceptor or seleniumwire
- Touch Actions
- dynamic proxies with authentication
- making single POST, GET or other requests using
driver.profiles.fetch(url)(syntax) - headless unofficially supported
- apply profile on already running driver with
driver.profiles.apply(profiles.Android()) - use of seleniumwire
for the latest features, have a look at the dev branch
Feel free to test my code!
Getting Started
Dependencies
- Python >= 3.7
- Chrome-Browser installed
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 seleniumwire import webdriver
profile = profiles.Windows() # or .Android
options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
driver = Chrome(profile, options=options,
uc_driver=False
)
# get url
driver.get('https://abrahamjuliot.github.io/creepjs/') # test fingerprint
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)
Profiles
Example Profile:
profile = \
{
"options": {
"sandbox": True,
"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
"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}
}
},
"proxy":{
"proxy":"socks5://user1:pass@example_jost.com:5001",
"bypass_list":["localhost"]
}
}
selenium-driverless
warning:
- this package is experimental and might include bugs, please report them at bug-reports
- might only work with 64-bit Python installations
- profiles might make it detected
- requires
pip install selenium-driverless>=1.3.4first
from selenium_profiles.webdriver import Chrome
from selenium_profiles.profiles import profiles
from selenium_driverless.webdriver import ChromeOptions
from selenium_driverless.types.by import By
profile = profiles.Windows() # or .Android
options = ChromeOptions()
# options.add_argument("--headless=new")
driver = Chrome(profile, options=options, driverless_options=True)
# get url
driver.get('https://nowsecure.nl#relax') # test fingerprint
driver.quit() # Execute on the End!
see documentation for usages
Modify-headers
using selenium-wire
from selenium_profiles import webdriver
from selenium_profiles.profiles import profiles
profile = profiles.Android()
driver = webdriver.Chrome(profile, uc_driver=False, seleniumwire_options=True) # or pass seleniumwire-options
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()
Using Selenium-Injector
from selenium_profiles.webdriver import Chrome
driver = Chrome(injector_options=True)
injector = driver.profiles.injector
# modify headers
injector.declarativeNetRequest.update_headers({"test": "test_2", "sec-ch-ua-platform": "Android"})
rules = injector.declarativeNetRequest.dynamic_rules
headers = injector.declarativeNetRequest._headers
driver.get("https://httpbin.org/headers")
input("press ENTER to continue")
# block images
injector.declarativeNetRequest.update_block_on(resource_types=["image"])
driver.get("https://www.wikimedia.org/")
input("press ENTER to exit")
driver.quit()
Touch_actions
Example demonstration script
from selenium_profiles.webdriver import Chrome
from selenium_profiles.profiles import profiles
from selenium.webdriver.common.by import By
from selenium.webdriver import ChromeOptions
from selenium_profiles.scripts.driver_utils import TouchActionChain
# Start Driver
options = ChromeOptions()
profile = profiles.Android() # or .Windows()
driver = Chrome(profile, uc_driver=False, options=options)
# 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()
connect to running driver
Undetectability isn't garanteed
from selenium import webdriver
driver = webdriver.Chrome()
# driver allready started:)
from selenium_profiles.webdriver import profiles as profile_manager
from selenium_profiles.profiles import profiles
profile = profiles.Android() # or .Android()
driver.profiles = profile_manager(driver=driver, profile=profile)
driver.profiles.apply(profile)
driver.get('https://hmaker.github.io/selenium-detector/') # test fingerprint
input("Press ENTER to exit")
driver.quit() # Execute on the End!
Set proxies dynamically or with options
from selenium_profiles.webdriver import Chrome
from selenium_profiles.profiles import profiles
profile = profiles.Windows() # or .Android()
profile["proxy"] = {
"proxy":"http://user1:pass1@example_host.com:41149"
}
driver = Chrome(profile=profile, injector_options=True)
driver.profiles.proxy.set_single("http://user2:pass2@example_host.com:41149")
print(driver.profiles.proxy.proxy)
driver.quit() # Execute on the End!
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.userAgentNavigator.platformnavigator.hardwareConcurrency
- emulation leak on new tabs diskussion
- selenium-detector
- Either Devtools Console is open or CDP Runtime Domain is enabled => patch javascript objects using a Proxy or disable CDP.Runtime domain?
- document.$cdc_asdjflasutopfhvcZLmcfl_
-
document.$chrome_asyncScriptInfo - driver.execute_script() usage (needs hook on called element)
- driver.execute_async_script() usage (needs hook on called element)
- driver.find_element() usage
-
window.cdc_adoQpoasnfa76pfcZLmcfl
- [
- 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
- Windows
- assert useragent, profile_export (no error)
- test_driver.py
Deprecated
- Stealth method (Detected by Google)
- buster captcha solver | wontfix
Authors
License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Disclaimer
I am not responsible what you use the code for!!! Also no warranty!
Acknowledgments
Inspiration, code snippets, etc.
- Selenium
- selenium-documentation
- README-Template
- headless_js
- Selenium-Stealth
- Undetected-Chromedriver
- Selenium-Wire
- Modheader-Selenium
- ModHeader docs
- buster captcha solver | wontfix
- audio_captcha_solver
- Chromedriver-Options List
- Chrome DevTools Protocol (cdp_cmd)
- example_pypi_package
- google-colab installer
- scripts/touch_action_chain
- cdp_event_listeners
- proxy-auth
- webdriver-manager
- dynamic subclasses
Metadata
Release files for selenium-profiles 2.2.10
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| selenium_profiles-2.2.10.tar.gz | 30.1 kB | Without provenance | Details for selenium_profiles-2.2.10.tar.gz |
Release files / selenium_profiles-2.2.10.tar.gz
| Download URL | selenium_profiles-2.2.10.tar.gz |
|---|---|
| Size | 30.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2bb5c60c76c025f36bca62617875bc97dc2541cb25730e2dba50a3ddac95857
|
|
BLAKE2b-256 checksum How to use checksums |
d18299772a2f5951bd62de5e871056c374322aa951301503c065f001ea33cbbe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.8.10
|
Security for selenium-profiles 2.2.10
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.