-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
3,108 additions
and
388 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length = 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
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 | ||
run: pytest |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
VERSION = 1.0 | ||
|
||
__all__ = ["VERSION"] |
Oops, something went wrong.