Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Main to Vinyzu Workspace #4

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 200
34 changes: 34 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
name: Bug report
about: Create a report to help us improve
title: '[BUG] '
labels: bug, help wanted
assignees: ''

---

**Describe the bug**
A clear and concise description of what the bug is.

**Code Sample**
If applicable, add a code sample to replicate the bug.

**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
20 changes: 20 additions & 0 deletions .github/ISSUE_TEMPLATE/feature_request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: enhancement, question
assignees: ''

---

**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

**Describe the solution you'd like**
A clear and concise description of what you want to happen.

**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.

**Additional context**
Add any other context or screenshots about the feature request here.
24 changes: 24 additions & 0 deletions .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
name: Question
about: Ask a question about Botright
title: '[Question] '
labels: question, help wanted, documentation
assignees: ''

---

**Describe your quesiton**
A clear and concise question.

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Version [e.g. 22]

**Additional context**
Add any other context about the problem here.
11 changes: 11 additions & 0 deletions .github/depenabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for all configuration options:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
- package-ecosystem: "pip" # See documentation for possible values
directory: "/" # Location of package manifests
schedule:
interval: "weekly"
55 changes: 55 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: CDP-Patches CI

on:
- push
- pull_request

jobs:
Linting:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
- name: (Linting) isort
run: isort . --check-only
- name: (Linting) Flake8
run: flake8 .
- name: (Linting) MyPy
run: mypy .
- name: (Linting) Black
run: black . --check

Build:
strategy:
matrix:
os: [ubuntu-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']

runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
pip install -e .
python -c "import os; os.environ['TOKENIZERS_PARALLELISM'] = 'false'"
- name: Install Chrome Browser
uses: browser-actions/setup-chrome@v1
- name: Install Chromium Driver
run: python -m playwright install chromium
- name: Test with PyTest
uses: maufrontier/puppeteer-headful@v3
with:
commands: pytest
112 changes: 110 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,110 @@
# CDP-Patches
- Bypass CDP Leaks in [Input](https://chromedevtools.github.io/devtools-protocol/tot/Input/) domains
# CDP-Patches v1.0
![CDP-Patches CI](https://github.com/Kaliiiiiiiiii-Vinyzu/CDP-Patches/actions/workflows/ci.yml/badge.svg)
[![](https://img.shields.io/pypi/v/cdp-patches.svg?color=1182C3)](https://pypi.org/project/cdp-patches/)
[![Downloads](https://static.pepy.tech/badge/cdp-patches)](https://pepy.tech/project/cdp-patches)

## Install it from PyPI

```bash
pip install cdp-patches
```

---

# Leaks
### Concept: Input Domain Leaks
Bypass CDP Leaks in [Input](https://chromedevtools.github.io/devtools-protocol/tot/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](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 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

```py
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())
```

> [!IMPORTANT]
> 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://github.com/Kaliiiiiiiiii-Vinyzu/CDP-Patches/blob/main/docs/index.rst)

---

## 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/)

---

![Version](https://img.shields.io/badge/CDP_Patches-v1.0-blue)
![License](https://img.shields.io/badge/License-GNU%20GPL-green)
![Python](https://img.shields.io/badge/Python-v3.x-lightgrey)
3 changes: 3 additions & 0 deletions cdp_patches/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VERSION = 1.0

__all__ = ["VERSION"]
Loading
Loading