Patching CDP (Chrome DevTools Protocol) leaks on OS level. Easy to use with Playwright/Patchright.
Project description
re-cdp-patches
This is a pruned version of CDP Patches that only works with Playwright and Patchright, and that I'm using to enhance the stealthiness of my Cloudflare-defeating browser-use version.
By using real OS-level events when clicking elements, I can bypass certain additional limitations that occur when using a VPN.
Install it from PyPI
pip install re-cdp-patches
Or for Full Linting
(Includes: playwright, re-patchright)
pip install re-cdp-patches[automation_linting]
Leak Patches
Input Package
Concept: Input Domain Leaks
Bypass CDP Leaks in Input domains
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]
PressingSHIFTorCAPSLOCKmanually on Windows affectsinput.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. Only the part for Playwright is relevant.
Development
Read the CONTRIBUTING.md file.
Copyright and License
© Vinyzu
(Commercial Usage is allowed, but source, license and copyright has to made available. Botright does not provide and Liability or Warranty)
Authors
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file re_cdp_patches-0.9.1-py3-none-any.whl.
File metadata
- Download URL: re_cdp_patches-0.9.1-py3-none-any.whl
- Upload date:
- Size: 32.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83fc06013296e9ceb975d3e7b9dc0ad87f7d8c393db40b7d6f369373dbd5f6a8
|
|
| MD5 |
38d11ad1eaf5ecf6ce165ebc44db6295
|
|
| BLAKE2b-256 |
88690b062a91e704f7052f97839cca781ff44515a9711ec18e605b47b0135006
|
Provenance
The following attestation bundles were made for re_cdp_patches-0.9.1-py3-none-any.whl:
Publisher:
publish.yml on imamousenotacat/re-cdp-patches
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
re_cdp_patches-0.9.1-py3-none-any.whl -
Subject digest:
83fc06013296e9ceb975d3e7b9dc0ad87f7d8c393db40b7d6f369373dbd5f6a8 - Sigstore transparency entry: 347727956
- Sigstore integration time:
-
Permalink:
imamousenotacat/re-cdp-patches@f4a5272b89737c81ff7ade2857ad65878dc7b626 -
Branch / Tag:
refs/tags/0.9.1 - Owner: https://github.com/imamousenotacat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f4a5272b89737c81ff7ade2857ad65878dc7b626 -
Trigger Event:
release
-
Statement type: