Skip to main content

inject javascript into chrome

Project description

Selenium-Injector

  • Change proxy while running (auth supported)
  • remotely contoll Chrome using websockets and extensions

Feel free to test my code!

Getting Started

Dependencies

Installing

Example scripts

click on element

from selenium_injector.webdriver import Chrome

# base driver to use
# from selenium.webdriver import Chrome as base_driver
from undetected_chromedriver import Chrome as base_driver

driver = Chrome(base_drivers=(base_driver,))

driver.get("https://www.wikipedia.org/")
driver.injector.socket.exec_command("utils.find_element.ByXpath", '//*[@id="js-link-box-en"]/strong', user=driver.injector.tab_user)

js = driver.injector.socket.js
t = js.types
u = js.utils

prev_url = driver.current_url[:]
try:
    driver.injector.socket.exec(u.click_element(u.find_element_by_xpath('//*[@id="js-link-box-en"]/strong')), user=driver.injector.tab_user, timeout=2)
except TimeoutError as e:
    if driver.current_url != prev_url:
        pass # new page loaded before send_response
    else:
        raise e

driver.quit()

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

set proxy dynamically

from selenium_injector.webdriver import Chrome
driver = Chrome()

driver.injector.proxy.set_single(host="example_host.com", port=143, password="password", username="user-1")

driver.get("https://whatismyipaddress.com/")

driver.injector.proxy.clear()
driver.quit()

use events

from selenium_injector.webdriver import Chrome
import json

driver = Chrome()

driver.get("chrome://version")

t = driver.injector.socket.js.types

event_id = driver.injector.socket.make_event_id()
user = driver.injector.any_user

driver.injector.socket.exec(t.list([
    t.set_event_id(event_id),
    t.exec(
        t.path("chrome.webRequest.onCompleted.addListener"),
        args=[t.event_callback(), t.value({"urls": ["<all_urls>"]})]
    )
]), user=user, max_depth=1)

event = driver.injector.socket.event(event_id, user=user)
for e in event:  # will block forever
    e = json.loads(e)
    data = e["result"][0]
    time = e["t"]
    print(time + "\n", data['url'])

warning: as driver.quit() isn't called in this example, it will leave files in your temp directories

Help

Please feel free to open an issue or fork!

Todo

  • eval within tab scope from extension
  • Add MV2 extension
    • change headers
  • add events
    • make protocoll use UUIDS's
    • allow response to event within scope
      • using (...args) => {new event_handler(...args)}
  • types.eval
    • for-loops
    • async execution
  • authentificaten proxies
    • manage webrtc-leak
    • manage location api leak
    • proxy per request
  • add chrome.scripting support
  • add automation tools
    • click
    • send_keys
    • find_element
      • by XPATH
  • undetectability
    • make tab scripts private
    • support base_driver argument
    • make /files/js/utils.js private

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_injector-2.2.tar.gz (17.7 kB view details)

Uploaded Source

File details

Details for the file selenium_injector-2.2.tar.gz.

File metadata

  • Download URL: selenium_injector-2.2.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.9

File hashes

Hashes for selenium_injector-2.2.tar.gz
Algorithm Hash digest
SHA256 6e48599c7f44f8f203396b0d7f44bd1a580da5ad0124e2d49bedfcf83c9f8cc3
MD5 c7ff743e14ef4b01ac77acd7f36baabd
BLAKE2b-256 2141f5f050c5ac4021af5506466e273d28a0cc7307da64f0d4559b0175085846

See more details on using hashes here.

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