Skip to main content

Patching CDP (Chrome DevTools Protocol) leaks on OS level. Easy to use with Playwright, Selenium, and other web automation tools.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

CDP-Patches v1.1

PyPI PyPI


[!CAUTION] The crbug#1477537 causing the Input Leak has been fixed in #6917162. It will probably be implemented in Chrome-Stable v142+.
CoalescedEvents are now also emitted by Input Events. There is no reason to use this package anymore, except for Select Elements (crbug#40943840).


Install it from PyPI

pip install cdp-patches
Or for Full Linting

(Includes: playwright, botright, selenium, selenium_driverless)

pip install cdp-patches[automation_linting]

Leak Patches

Input Package

Concept: Input Domain Leaks

Bypass CDP Leaks in Input domains

Brotector Banner

For an interaction event e, the page coordinates won't ever equal the screen coordinates, unless Chrome is in fullscreen. However, all CDP input commands just set it the same by default (see crbug#1477537).

var is_bot = (e.pageY == e.screenY && e.pageX == e.screenX)
if (is_bot && 1 >= outerHeight - innerHeight){ // fullscreen
    is_bot = false
}

Furthermore, CDP can't dispatch CoalescedEvent's (demo).

As we don't want to patch Chromium itsself, let's just dispatch this event at OS-level!


Usage

from cdp_patches.input import SyncInput

sync_input = SyncInput(pid=pid)
# Or
sync_input = SyncInput(browser=browser)

# Dispatch Inputs
sync_input.click("left", 100, 100)  # Left click at (100, 100)
sync_input.double_click("left", 100, 100)  # Left double-click at (100, 100)
sync_input.down("left", 100, 100)  # Left mouse button down at (100, 100)
sync_input.up("left", 100, 100)  # Left mouse button up at (100, 100)
sync_input.move(100, 100)  # Move mouse to (100, 100)
sync_input.scroll("down", 10)  # Scroll down by 10 lines
sync_input.type("Hello World!")  # Type "Hello World!"

Async Usage

import asyncio

from cdp_patches.input import AsyncInput

async def main():
    async_input = await AsyncInput(pid=pid)
    # Or
    async_input = await AsyncInput(browser=browser)
    
    # Dispatch Inputs
    await async_input.click("left", 100, 100)  # Left click at (100, 100)
    await async_input.double_click("left", 100, 100)  # Left double-click at (100, 100)
    await async_input.down("left", 100, 100)  # Left mouse button down at (100, 100)
    await async_input.up("left", 100, 100)  # Left mouse button up at (100, 100)
    await async_input.move(100, 100)  # Move mouse to (100, 100)
    await async_input.scroll("down", 10)  # Scroll down by 10 lines
    await async_input.type("Hello World!")  # Type "Hello World!"

if __name__ == '__main__':
    asyncio.run(main())

TODO

  • Improve mouse movement timings.
  • Implement extensive testing.

Owner: Vinyzu

Co-Maintainer: Kaliiiiiiiiii

[!IMPORTANT]
By the nature of OS-level events (which can only impact actionable windows), this package can only be used with headful browsers.

[!WARNING]
Pressing SHIFT or CAPSLOCK manually on Windows affects input.type(text) as well.

[!WARNING]
Because Chrome does not recognize Input Events to specific tabs, these methods can only be used on the active tab. Chrome Tabs do have their own process with a process id (pid), but these can not be controlled using Input Events as they´re just engines.

Read the Documentation


Development

Read the CONTRIBUTING.md file.


Copyright and License

© Vinyzu

GNU GPL

(Commercial Usage is allowed, but source, license and copyright has to made available. Botright does not provide and Liability or Warranty)


Authors

Vinyzu, Kaliiiiiiiiii

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

cdp_patches-1.1.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cdp_patches-1.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file cdp_patches-1.1.tar.gz.

File metadata

  • Download URL: cdp_patches-1.1.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for cdp_patches-1.1.tar.gz
Algorithm Hash digest
SHA256 bc7025e7f92e4301231b6bbc231459f91260aa252ef35dedb57725e2fa9f95d0
MD5 dc8af1f8f839fc6913c36720d09b9d59
BLAKE2b-256 ade1efec51a335f988b3b0bb1d3363b03b31b572a05d1cc55d4b021b2af309a2

See more details on using hashes here.

File details

Details for the file cdp_patches-1.1-py3-none-any.whl.

File metadata

  • Download URL: cdp_patches-1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.13

File hashes

Hashes for cdp_patches-1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c7df908b2cce9ca3cc4d66d592c632538f12712f6ef4834d830046da7065e94
MD5 43ad78ff440e65967433f186eb5d67df
BLAKE2b-256 eeb05e8d56be8ceaa7f31a013932c5610e73f8689e6da8398d21528029d846c7

See more details on using hashes here.

Supported by

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