chromate-rb 0.0.1.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +39 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +132 -0
- data/LICENSE.txt +21 -0
- data/README.md +124 -0
- data/Rakefile +71 -0
- data/dockerfiles/Dockerfile +85 -0
- data/dockerfiles/docker-entrypoint.sh +15 -0
- data/docs/browser.md +163 -0
- data/lib/chromate/actions/dom.rb +39 -0
- data/lib/chromate/actions/navigate.rb +71 -0
- data/lib/chromate/actions/screenshot.rb +56 -0
- data/lib/chromate/browser.rb +113 -0
- data/lib/chromate/c_logger.rb +22 -0
- data/lib/chromate/client.rb +120 -0
- data/lib/chromate/configuration.rb +119 -0
- data/lib/chromate/element.rb +194 -0
- data/lib/chromate/elements/select.rb +19 -0
- data/lib/chromate/exceptions.rb +9 -0
- data/lib/chromate/hardwares/mouse_controller.rb +67 -0
- data/lib/chromate/hardwares/mouses/linux_controller.rb +79 -0
- data/lib/chromate/hardwares/mouses/mac_os_controller.rb +133 -0
- data/lib/chromate/hardwares/mouses/virtual_controller.rb +81 -0
- data/lib/chromate/hardwares.rb +33 -0
- data/lib/chromate/helpers.rb +23 -0
- data/lib/chromate/user_agent.rb +34 -0
- data/lib/chromate/version.rb +5 -0
- data/lib/chromate.rb +17 -0
- data/results/brotector.png +0 -0
- data/results/cloudflare.png +0 -0
- data/sig/chromate.rbs +4 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76c6ae8c74c3238f41db246836afd03b20c8bbb19a706575a424be2de6b84d41
|
4
|
+
data.tar.gz: 9b07855d6fb9139e0c0a223bffa40f1558de7e82d4ca62ec20039ad22ceabfce
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2701dc1057b0f038f53aea6e42a34dc5a6a222900c61b2f1004f58dbb00453467d31ec8f8acb0e6a6545e4f32af5d2461873abdd898a0a47c05339dc65e038f6
|
7
|
+
data.tar.gz: b8ef6aba60741c21570c36e68f4a3e6e9e4aa4fa52335284b8aef97f63fa3da7d5849bac44bc2c64db2436fd42f81adda365a5e00f63f60f119dc3e54dcb2533
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.0
|
3
|
+
NewCops: enable
|
4
|
+
Exclude:
|
5
|
+
- 'Rakefile'
|
6
|
+
- 'bin/**/*'
|
7
|
+
- 'vendor/**/*'
|
8
|
+
|
9
|
+
Style/StringLiterals:
|
10
|
+
EnforcedStyle: single_quotes
|
11
|
+
|
12
|
+
Style/StringLiteralsInInterpolation:
|
13
|
+
EnforcedStyle: double_quotes
|
14
|
+
|
15
|
+
Style/Documentation:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Layout/LineLength:
|
19
|
+
Max: 160
|
20
|
+
|
21
|
+
Metrics/MethodLength:
|
22
|
+
Max: 25
|
23
|
+
|
24
|
+
Metrics/AbcSize:
|
25
|
+
Max: 30
|
26
|
+
|
27
|
+
Metrics/CyclomaticComplexity:
|
28
|
+
Max: 15
|
29
|
+
|
30
|
+
Metrics/PerceivedComplexity:
|
31
|
+
Max: 15
|
32
|
+
|
33
|
+
Metrics/ClassLength:
|
34
|
+
Max: 200
|
35
|
+
|
36
|
+
Metrics/BlockLength:
|
37
|
+
Max: 50
|
38
|
+
Exclude:
|
39
|
+
- 'spec/**/*'
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our
|
6
|
+
community a harassment-free experience for everyone, regardless of age, body
|
7
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
8
|
+
identity and expression, level of experience, education, socio-economic status,
|
9
|
+
nationality, personal appearance, race, caste, color, religion, or sexual
|
10
|
+
identity and orientation.
|
11
|
+
|
12
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
13
|
+
diverse, inclusive, and healthy community.
|
14
|
+
|
15
|
+
## Our Standards
|
16
|
+
|
17
|
+
Examples of behavior that contributes to a positive environment for our
|
18
|
+
community include:
|
19
|
+
|
20
|
+
* Demonstrating empathy and kindness toward other people
|
21
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
22
|
+
* Giving and gracefully accepting constructive feedback
|
23
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
24
|
+
and learning from the experience
|
25
|
+
* Focusing on what is best not just for us as individuals, but for the overall
|
26
|
+
community
|
27
|
+
|
28
|
+
Examples of unacceptable behavior include:
|
29
|
+
|
30
|
+
* The use of sexualized language or imagery, and sexual attention or advances of
|
31
|
+
any kind
|
32
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
33
|
+
* Public or private harassment
|
34
|
+
* Publishing others' private information, such as a physical or email address,
|
35
|
+
without their explicit permission
|
36
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
37
|
+
professional setting
|
38
|
+
|
39
|
+
## Enforcement Responsibilities
|
40
|
+
|
41
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
42
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
43
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
44
|
+
or harmful.
|
45
|
+
|
46
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
47
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
48
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
49
|
+
decisions when appropriate.
|
50
|
+
|
51
|
+
## Scope
|
52
|
+
|
53
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
54
|
+
an individual is officially representing the community in public spaces.
|
55
|
+
Examples of representing our community include using an official email address,
|
56
|
+
posting via an official social media account, or acting as an appointed
|
57
|
+
representative at an online or offline event.
|
58
|
+
|
59
|
+
## Enforcement
|
60
|
+
|
61
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
62
|
+
reported to the community leaders responsible for enforcement at
|
63
|
+
[INSERT CONTACT METHOD].
|
64
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
65
|
+
|
66
|
+
All community leaders are obligated to respect the privacy and security of the
|
67
|
+
reporter of any incident.
|
68
|
+
|
69
|
+
## Enforcement Guidelines
|
70
|
+
|
71
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
72
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
73
|
+
|
74
|
+
### 1. Correction
|
75
|
+
|
76
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
77
|
+
unprofessional or unwelcome in the community.
|
78
|
+
|
79
|
+
**Consequence**: A private, written warning from community leaders, providing
|
80
|
+
clarity around the nature of the violation and an explanation of why the
|
81
|
+
behavior was inappropriate. A public apology may be requested.
|
82
|
+
|
83
|
+
### 2. Warning
|
84
|
+
|
85
|
+
**Community Impact**: A violation through a single incident or series of
|
86
|
+
actions.
|
87
|
+
|
88
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
89
|
+
interaction with the people involved, including unsolicited interaction with
|
90
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
91
|
+
includes avoiding interactions in community spaces as well as external channels
|
92
|
+
like social media. Violating these terms may lead to a temporary or permanent
|
93
|
+
ban.
|
94
|
+
|
95
|
+
### 3. Temporary Ban
|
96
|
+
|
97
|
+
**Community Impact**: A serious violation of community standards, including
|
98
|
+
sustained inappropriate behavior.
|
99
|
+
|
100
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
101
|
+
communication with the community for a specified period of time. No public or
|
102
|
+
private interaction with the people involved, including unsolicited interaction
|
103
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
104
|
+
Violating these terms may lead to a permanent ban.
|
105
|
+
|
106
|
+
### 4. Permanent Ban
|
107
|
+
|
108
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
109
|
+
standards, including sustained inappropriate behavior, harassment of an
|
110
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
111
|
+
|
112
|
+
**Consequence**: A permanent ban from any sort of public interaction within the
|
113
|
+
community.
|
114
|
+
|
115
|
+
## Attribution
|
116
|
+
|
117
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
118
|
+
version 2.1, available at
|
119
|
+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
|
120
|
+
|
121
|
+
Community Impact Guidelines were inspired by
|
122
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
123
|
+
|
124
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
125
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
|
126
|
+
[https://www.contributor-covenant.org/translations][translations].
|
127
|
+
|
128
|
+
[homepage]: https://www.contributor-covenant.org
|
129
|
+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
|
130
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
131
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
132
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Eth3rnit3
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# Chromate
|
2
|
+
[![eth3rnit3 - chromate](https://img.shields.io/static/v1?label=eth3rnit3&message=chromate&color=red&logo=github)](https://github.com/eth3rnit3/chromate "Go to GitHub repo")
|
3
|
+
[![GitHub release](https://img.shields.io/github/release/eth3rnit3/chromate?include_prereleases=&sort=semver&color=red)](https://github.com/eth3rnit3/chromate/releases/)
|
4
|
+
[![Ruby](https://github.com/Eth3rnit3/chromate/actions/workflows/main.yml/badge.svg)](https://github.com/Eth3rnit3/chromate/actions/workflows/main.yml)
|
5
|
+
[![issues - chromate](https://img.shields.io/github/issues/eth3rnit3/chromate)](https://github.com/eth3rnit3/chromate/issues)
|
6
|
+
[![License](https://img.shields.io/badge/License-MIT-red)](#license)
|
7
|
+
|
8
|
+
Chromate is a custom driver for Chrome using the Chrome DevTools Protocol (CDP) to create undetectable bots with human-like behavior. The ultimate goal is to enable the creation of AI agents capable of navigating and performing actions on the web on behalf of the user. This gem is the first step towards achieving that goal.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add gem to your application's Gemfile:
|
13
|
+
|
14
|
+
```sh
|
15
|
+
bundle add chromate
|
16
|
+
```
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
gem install chromate
|
22
|
+
```
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
[![view - Documentation](https://img.shields.io/badge/view-Documentation-blue?style=for-the-badge)](/docs/ "Go to project documentation")
|
27
|
+
|
28
|
+
### Basic Example
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'chromate'
|
32
|
+
|
33
|
+
browser = Chromate::Browser.new # default headless: true
|
34
|
+
browser.start
|
35
|
+
|
36
|
+
url = 'http://example.com'
|
37
|
+
browser.navigate_to(url)
|
38
|
+
browser.find_element('#some-element').click
|
39
|
+
browser.screenshot_to_file('screenshot.png')
|
40
|
+
|
41
|
+
browser.stop
|
42
|
+
```
|
43
|
+
|
44
|
+
### Configuration
|
45
|
+
|
46
|
+
You can configure Chromate using a block:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
Chromate.configure do |config|
|
50
|
+
config.user_data_dir = '/path/to/user/data'
|
51
|
+
config.headless = true
|
52
|
+
config.native_control = true
|
53
|
+
config.proxy = { host: 'proxy.example.com', port: 8080 }
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
## Principle of Operation
|
58
|
+
|
59
|
+
Chromate leverages the Chrome DevTools Protocol (CDP) to interact with the browser. It provides a custom driver that mimics human-like behavior to avoid detection by anti-bot systems. The gem includes native mouse controllers for macOS and Linux, which do not trigger JavaScript events, making interactions more human-like.
|
60
|
+
|
61
|
+
### Features
|
62
|
+
|
63
|
+
- **Headless Mode**: Run Chrome without a graphical user interface.
|
64
|
+
- **Native Mouse Control**: Use native mouse events for macOS and Linux.
|
65
|
+
- **Screenshot Capture**: Capture screenshots of the browser window.
|
66
|
+
- **Form Interaction**: Fill out and submit forms.
|
67
|
+
- **Shadow DOM Support**: Interact with elements inside Shadow DOM.
|
68
|
+
- **Element Interaction**: Click, hover, and type text into elements.
|
69
|
+
- **Navigation**: Navigate to URLs and wait for page load.
|
70
|
+
- **Docker xvfb Support**: Dockerfile provided with xvfb setup for easy usage.
|
71
|
+
|
72
|
+
### Limitations
|
73
|
+
|
74
|
+
- **Windows Support**: Native mouse control is not yet supported on Windows.
|
75
|
+
- **Headless Mode Complexity**: Requires xvfb for headless mode, adding complexity due to different proportions.
|
76
|
+
- **Anti-Bot Detection**: Current systems can detect keyboard and mouse interactions via CDP.
|
77
|
+
|
78
|
+
# Native controls and headless
|
79
|
+
|
80
|
+
Chromate provides native mouse control for macOS and Linux, which helps in creating more human-like interactions that are harder to detect by anti-bot systems. However, using native controls in headless mode requires additional setup, such as using xvfb (X Virtual Framebuffer) to simulate a display.
|
81
|
+
|
82
|
+
## Docker Setup
|
83
|
+
|
84
|
+
To simplify the setup process, Chromate includes a Dockerfile and an entrypoint script that handle the installation and configuration of necessary dependencies, including xvfb.
|
85
|
+
|
86
|
+
### Dockerfile
|
87
|
+
|
88
|
+
The Dockerfile sets up a minimal environment with all the necessary dependencies to run Chromate in headless mode with xvfb. It installs Chrome, xvfb, and other required libraries.
|
89
|
+
|
90
|
+
The [entrypoint](dockerfiles/docker-entrypoint.sh) script ensures that xvfb is running before starting the main process. It removes any existing lock files, starts xvfb and a window manager (fluxbox), and waits for xvfb to initialize.
|
91
|
+
|
92
|
+
### Example Docker Usage
|
93
|
+
|
94
|
+
Here is an example of how you can use Chromate inside a Docker container:
|
95
|
+
|
96
|
+
```sh
|
97
|
+
# Build the Docker image
|
98
|
+
docker build -f dockerfiles/Dockerfile -t chromate .
|
99
|
+
|
100
|
+
# Run the Docker container
|
101
|
+
docker run -v $(pwd):/app -it chromate
|
102
|
+
|
103
|
+
# Inside the container, run your Ruby script
|
104
|
+
ruby your_script.rb # or bundle exec rspec
|
105
|
+
```
|
106
|
+
|
107
|
+
This setup ensures that all necessary dependencies are installed and configured correctly, allowing you to focus on writing your automation scripts without worrying about the underlying environment.
|
108
|
+
|
109
|
+
## Contribution
|
110
|
+
|
111
|
+
Contributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request on GitHub.
|
112
|
+
|
113
|
+
### How to Contribute
|
114
|
+
|
115
|
+
1. Fork the repository.
|
116
|
+
2. Create a new branch (`git checkout -b feature-branch`).
|
117
|
+
3. Make your changes.
|
118
|
+
4. Commit your changes (`git commit -am 'Add new feature'`).
|
119
|
+
5. Push to the branch (`git push origin feature-branch`).
|
120
|
+
6. Create a new Pull Request.
|
121
|
+
|
122
|
+
## License
|
123
|
+
|
124
|
+
Released under [MIT](/LICENSE.txt) by [@eth3rnit3](https://github.com/eth3rnit3).
|
data/Rakefile
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
|
8
|
+
require "rubocop/rake_task"
|
9
|
+
|
10
|
+
RuboCop::RakeTask.new
|
11
|
+
|
12
|
+
task default: %i[spec rubocop]
|
13
|
+
|
14
|
+
require_relative "lib/chromate"
|
15
|
+
|
16
|
+
namespace :chromate do
|
17
|
+
namespace :test do
|
18
|
+
task :open do
|
19
|
+
browser = Chromate::Browser.new(headless: false)
|
20
|
+
browser.start
|
21
|
+
browser.navigate_to("https://2captcha.com/fr/demo/recaptcha-v2")
|
22
|
+
sleep 2
|
23
|
+
element = browser.find_element("#root")
|
24
|
+
binding.irb
|
25
|
+
browser.stop
|
26
|
+
end
|
27
|
+
|
28
|
+
task :pixelscan do
|
29
|
+
browser = Chromate::Browser.new
|
30
|
+
browser.start
|
31
|
+
browser.navigate_to("https://pixelscan.net")
|
32
|
+
sleep 10
|
33
|
+
browser.screenshot_to_file("results/pixelscan.png")
|
34
|
+
browser.stop
|
35
|
+
end
|
36
|
+
|
37
|
+
task :brotector do
|
38
|
+
require "chromate/native/mouse_controller"
|
39
|
+
browser = Chromate::Browser.new
|
40
|
+
browser.start
|
41
|
+
browser.navigate_to("https://kaliiiiiiiiii.github.io/brotector?crash=false")
|
42
|
+
sleep 2
|
43
|
+
# browser.click_element("#clickHere")
|
44
|
+
mouse = Chromate::Native::MouseController.new(browser.client)
|
45
|
+
mouse.click(100, 100)
|
46
|
+
browser.screenshot_to_file("results/brotector.png")
|
47
|
+
browser.stop
|
48
|
+
end
|
49
|
+
|
50
|
+
task :bot do
|
51
|
+
browser = Chromate::Browser.new
|
52
|
+
browser.start
|
53
|
+
browser.navigate_to("https://bot.sannysoft.com")
|
54
|
+
sleep 2
|
55
|
+
browser.screenshot_to_file("results/bot.png")
|
56
|
+
browser.stop
|
57
|
+
end
|
58
|
+
|
59
|
+
task :cloudflare do
|
60
|
+
Chromate.configure do |config|
|
61
|
+
config.headless = false
|
62
|
+
end
|
63
|
+
browser = Chromate::Browser.new
|
64
|
+
browser.start
|
65
|
+
browser.navigate_to("https://2captcha.com/fr/demo/cloudflare-turnstile-challenge")
|
66
|
+
sleep 10
|
67
|
+
browser.screenshot_to_file("results/cloudflare.png")
|
68
|
+
browser.stop
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
FROM ruby:3.2-slim
|
2
|
+
|
3
|
+
RUN apt-get update && apt-get install -y \
|
4
|
+
nano \
|
5
|
+
xvfb \
|
6
|
+
curl \
|
7
|
+
git \
|
8
|
+
bash \
|
9
|
+
build-essential \
|
10
|
+
libx11-xcb1 \
|
11
|
+
libxcomposite1 \
|
12
|
+
libxrandr2 \
|
13
|
+
libxdamage1 \
|
14
|
+
libjpeg62-turbo \
|
15
|
+
libwebp-dev \
|
16
|
+
udev \
|
17
|
+
fonts-freefont-ttf \
|
18
|
+
fonts-noto-color-emoji \
|
19
|
+
nodejs \
|
20
|
+
npm \
|
21
|
+
libxcursor1 \
|
22
|
+
libgtk-3-0 \
|
23
|
+
libpangocairo-1.0-0 \
|
24
|
+
libcairo-gobject2 \
|
25
|
+
libgdk-pixbuf2.0-0 \
|
26
|
+
libgstreamer1.0-0 \
|
27
|
+
libgstreamer-plugins-base1.0-0 \
|
28
|
+
gstreamer1.0-gl \
|
29
|
+
gstreamer1.0-libav \
|
30
|
+
gstreamer1.0-plugins-bad \
|
31
|
+
libxslt1.1 \
|
32
|
+
libwoff1 \
|
33
|
+
libvpx7 \
|
34
|
+
libevent-2.1-7 \
|
35
|
+
libopus0 \
|
36
|
+
libsecret-1-0 \
|
37
|
+
libenchant-2-2 \
|
38
|
+
libharfbuzz-icu0 \
|
39
|
+
libhyphen0 \
|
40
|
+
libmanette-0.2-0 \
|
41
|
+
libflite1 \
|
42
|
+
libavcodec-extra \
|
43
|
+
libx11-dev \
|
44
|
+
libxtst-dev \
|
45
|
+
x11-utils \
|
46
|
+
x11-apps \
|
47
|
+
imagemagick \
|
48
|
+
xdotool \
|
49
|
+
fluxbox \
|
50
|
+
ffmpeg \
|
51
|
+
psmisc \
|
52
|
+
--no-install-recommends && rm -rf /var/lib/apt/lists/*
|
53
|
+
|
54
|
+
# Donwload and install Chrome
|
55
|
+
|
56
|
+
RUN apt-get update && apt-get install -y wget gnupg gnupg2 gnupg1 && rm -rf /var/lib/apt/lists/*
|
57
|
+
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
|
58
|
+
&& echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
|
59
|
+
RUN apt-get update && apt-get -y install google-chrome-stable
|
60
|
+
|
61
|
+
ENV CHROME_BIN=/usr/bin/google-chrome
|
62
|
+
|
63
|
+
RUN gem install bundler -v 2.5.21
|
64
|
+
|
65
|
+
WORKDIR /app
|
66
|
+
|
67
|
+
COPY Gemfile Gemfile.lock chromate.gemspec ./
|
68
|
+
COPY lib/chromate/version.rb ./lib/chromate/version.rb
|
69
|
+
|
70
|
+
RUN bundle install
|
71
|
+
|
72
|
+
COPY dockerfiles/docker-entrypoint.sh /usr/local/bin/
|
73
|
+
|
74
|
+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
75
|
+
|
76
|
+
COPY . .
|
77
|
+
|
78
|
+
ENV DISPLAY=:99
|
79
|
+
|
80
|
+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
81
|
+
|
82
|
+
CMD [ "bash" ]
|
83
|
+
|
84
|
+
# docker build -f dockerfiles/Dockerfile -t chromate .
|
85
|
+
# docker run -v $(pwd):/app -it chromate
|
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
if [ -f /tmp/.X99-lock ]; then
|
4
|
+
rm -f /tmp/.X99-lock
|
5
|
+
fi
|
6
|
+
|
7
|
+
if ! pgrep -x "Xvfb" > /dev/null; then
|
8
|
+
Xvfb :99 -screen 0 1920x1080x24 &
|
9
|
+
DISPLAY=:99 fluxbox &
|
10
|
+
fi
|
11
|
+
|
12
|
+
echo "Waiting for Xvfb to start..."
|
13
|
+
sleep 1
|
14
|
+
|
15
|
+
exec "$@"
|
data/docs/browser.md
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# Browser
|
2
|
+
|
3
|
+
The `Chromate::Browser` class is the main interface for interacting with the Chrome browser using the Chromate gem. It provides methods for navigating, interacting with elements, taking screenshots, and more.
|
4
|
+
|
5
|
+
## Initialization
|
6
|
+
|
7
|
+
To create a new instance of the `Browser` class, you can pass in various options:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
browser = Chromate::Browser.new(
|
11
|
+
headless: true,
|
12
|
+
native_control: true,
|
13
|
+
user_data_dir: '/path/to/user/data',
|
14
|
+
record: false
|
15
|
+
)
|
16
|
+
```
|
17
|
+
|
18
|
+
### Options
|
19
|
+
|
20
|
+
- `headless`: Run Chrome in headless mode (default: true).
|
21
|
+
- `native_control`: Use native mouse control (default: false).
|
22
|
+
- `user_data_dir`: Directory to store user data (default: a temporary directory).
|
23
|
+
- `record`: Record the browser session (default: false).
|
24
|
+
- `xfvb`: Use xvfb for headless mode (default: false).
|
25
|
+
|
26
|
+
## Methods
|
27
|
+
|
28
|
+
###
|
29
|
+
|
30
|
+
start
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
Starts the Chrome browser with the specified options.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
browser.start
|
38
|
+
```
|
39
|
+
|
40
|
+
###
|
41
|
+
|
42
|
+
stop
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
Stops the Chrome browser and any associated processes.
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
browser.stop
|
50
|
+
```
|
51
|
+
|
52
|
+
### `navigate_to(url)`
|
53
|
+
|
54
|
+
Navigates to the specified URL and waits for the page to load.
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
browser.navigate_to('http://example.com')
|
58
|
+
```
|
59
|
+
|
60
|
+
### `find_element(selector)`
|
61
|
+
|
62
|
+
Finds an element on the page using the specified CSS selector.
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
element = browser.find_element('#some-element')
|
66
|
+
```
|
67
|
+
|
68
|
+
### `click_element(selector)`
|
69
|
+
|
70
|
+
Clicks on an element specified by the CSS selector.
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
browser.click_element('#some-element')
|
74
|
+
```
|
75
|
+
|
76
|
+
### `hover_element(selector)`
|
77
|
+
|
78
|
+
Hovers over an element specified by the CSS selector.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
browser.hover_element('#some-element')
|
82
|
+
```
|
83
|
+
|
84
|
+
### `type_text(selector, text)`
|
85
|
+
|
86
|
+
Types text into an element specified by the CSS selector.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
browser.type_text('#input-field', 'Hello, world!')
|
90
|
+
```
|
91
|
+
|
92
|
+
### `screenshot_to_file(file_path, options = {})`
|
93
|
+
|
94
|
+
Takes a screenshot of the current page and saves it to the specified file path.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
browser.screenshot_to_file('screenshot.png')
|
98
|
+
```
|
99
|
+
|
100
|
+
###
|
101
|
+
|
102
|
+
native_control?
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
Returns whether native control is enabled.
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
puts browser.native_control? # => true or false
|
110
|
+
```
|
111
|
+
|
112
|
+
## Example Usage
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
require 'chromate'
|
116
|
+
|
117
|
+
browser = Chromate::Browser.new(headless: true, native_control: true)
|
118
|
+
browser.start
|
119
|
+
|
120
|
+
browser.navigate_to('http://example.com')
|
121
|
+
browser.find_element('#some-element').click
|
122
|
+
browser.screenshot_to_file('screenshot.png')
|
123
|
+
|
124
|
+
browser.stop
|
125
|
+
```
|
126
|
+
|
127
|
+
## Private Methods
|
128
|
+
|
129
|
+
###
|
130
|
+
|
131
|
+
start_video_recording
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
Starts recording the browser session using `ffmpeg`.
|
136
|
+
|
137
|
+
###
|
138
|
+
|
139
|
+
build_args
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
Builds the arguments for starting the Chrome process.
|
144
|
+
|
145
|
+
###
|
146
|
+
|
147
|
+
stop_and_exit
|
148
|
+
|
149
|
+
|
150
|
+
|
151
|
+
Stops the browser and exits the process.
|
152
|
+
|
153
|
+
###
|
154
|
+
|
155
|
+
config
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
Returns the Chromate configuration.
|
160
|
+
|
161
|
+
## Conclusion
|
162
|
+
|
163
|
+
The `Chromate::Browser` class provides a powerful interface for automating interactions with the Chrome browser. With support for headless mode, native mouse control, and more, it is a versatile tool for creating undetectable bots with human-like behavior.
|