https://github.com/kaliiiiiiiiii-vinyzu/cdp-patches
Patching CDP (Chrome DevTools Protocol) leaks on OS level. Easy to use with Playwright, Selenium, and other web automation tools.
https://github.com/kaliiiiiiiiii-vinyzu/cdp-patches
automation botting browser browser-stealth cdp chrome chromium leak leaks linux patch playwright python selenium stealth undetectable windows
Last synced: 2 months ago
JSON representation
Patching CDP (Chrome DevTools Protocol) leaks on OS level. Easy to use with Playwright, Selenium, and other web automation tools.
- Host: GitHub
- URL: https://github.com/kaliiiiiiiiii-vinyzu/cdp-patches
- Owner: Kaliiiiiiiiii-Vinyzu
- License: gpl-3.0
- Created: 2023-10-18T16:06:50.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-08-19T17:04:44.000Z (9 months ago)
- Last Synced: 2025-03-02T13:11:46.951Z (3 months ago)
- Topics: automation, botting, browser, browser-stealth, cdp, chrome, chromium, leak, leaks, linux, patch, playwright, python, selenium, stealth, undetectable, windows
- Language: Python
- Homepage: https://vinyzu.gitbook.io/cdp-patches-documentation
- Size: 159 KB
- Stars: 100
- Watchers: 7
- Forks: 9
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
CDP-Patches v1.0## Install it from PyPI
```bash
pip install cdp-patches
```Or for Full Linting
#### (Includes: playwright, botright, selenium, selenium_driverless)
```bash
pip install cdp-patches[automation_linting]
```---
# Leak Patches
Input Package
### Concept: Input Domain Leaks
Bypass CDP Leaks in [Input](https://chromedevtools.github.io/devtools-protocol/tot/Input/) domains[](https://github.com/kaliiiiiiiiii/brotector)
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](https://bugs.chromium.org/p/chromium/issues/detail?id=1477537)).
```js
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](https://omwnk.codesandbox.io/)).
As we don't want to patch Chromium itsself, let's just dispatch this event at OS-level!
---
## Usage
```py
from cdp_patches.input import SyncInputsync_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
```py
import asynciofrom 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](https://github.com/Vinyzu/)
#### Co-Maintainer: [Kaliiiiiiiiii](https://github.com/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](https://vinyzu.gitbook.io/cdp-patches-documentation)
---
## Development
Read the [CONTRIBUTING.md](https://github.com/Vinyzu/Botright/blob/main/docs/CONTRIBUTING.md) file.
---
## Copyright and License
© [Vinyzu](https://github.com/Vinyzu/)[GNU GPL](https://choosealicense.com/licenses/gpl-3.0/)
(Commercial Usage is allowed, but source, license and copyright has to made available. Botright does not provide and Liability or Warranty)
---
## Authors
[Vinyzu](https://github.com/Vinyzu/),
[Kaliiiiiiiiii](https://github.com/kaliiiiiiiiii/)