chromate-rb 0.0.1.pre → 0.0.3.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -0
  3. data/CHANGELOG.md +72 -3
  4. data/README.md +33 -6
  5. data/Rakefile +48 -16
  6. data/docker_root/Gemfile +4 -0
  7. data/docker_root/Gemfile.lock +28 -0
  8. data/docker_root/TestInDocker.gif +0 -0
  9. data/docker_root/app.rb +87 -0
  10. data/dockerfiles/Dockerfile +21 -7
  11. data/dockerfiles/README.md +49 -0
  12. data/docs/BOT_BROWSER.md +74 -0
  13. data/docs/README.md +74 -0
  14. data/docs/browser.md +124 -102
  15. data/docs/client.md +126 -0
  16. data/docs/element.md +365 -0
  17. data/docs/elements/checkbox.md +69 -0
  18. data/docs/elements/radio.md +57 -0
  19. data/lib/bot_browser/downloader.rb +64 -0
  20. data/lib/bot_browser/installer.rb +99 -0
  21. data/lib/bot_browser.rb +43 -0
  22. data/lib/chromate/actions/dom.rb +35 -27
  23. data/lib/chromate/actions/navigate.rb +7 -5
  24. data/lib/chromate/actions/screenshot.rb +71 -14
  25. data/lib/chromate/actions/stealth.rb +62 -0
  26. data/lib/chromate/binary.rb +83 -0
  27. data/lib/chromate/browser.rb +120 -24
  28. data/lib/chromate/c_logger.rb +8 -0
  29. data/lib/chromate/client.rb +65 -26
  30. data/lib/chromate/configuration.rb +31 -14
  31. data/lib/chromate/element.rb +119 -16
  32. data/lib/chromate/elements/checkbox.rb +40 -0
  33. data/lib/chromate/elements/option.rb +43 -0
  34. data/lib/chromate/elements/radio.rb +37 -0
  35. data/lib/chromate/elements/select.rb +50 -6
  36. data/lib/chromate/elements/tags.rb +29 -0
  37. data/lib/chromate/exceptions.rb +2 -0
  38. data/lib/chromate/files/agents.json +11 -0
  39. data/lib/chromate/files/stealth.js +199 -0
  40. data/lib/chromate/hardwares/keyboard_controller.rb +45 -0
  41. data/lib/chromate/hardwares/keyboards/virtual_controller.rb +65 -0
  42. data/lib/chromate/hardwares/mouse_controller.rb +55 -11
  43. data/lib/chromate/hardwares/mouses/linux_controller.rb +124 -21
  44. data/lib/chromate/hardwares/mouses/mac_os_controller.rb +6 -6
  45. data/lib/chromate/hardwares/mouses/virtual_controller.rb +95 -7
  46. data/lib/chromate/hardwares/mouses/x11.rb +36 -0
  47. data/lib/chromate/hardwares.rb +19 -3
  48. data/lib/chromate/helpers.rb +22 -15
  49. data/lib/chromate/user_agent.rb +41 -15
  50. data/lib/chromate/version.rb +1 -1
  51. data/lib/chromate.rb +2 -0
  52. data/logo.png +0 -0
  53. data/results/bot.png +0 -0
  54. data/results/brotector.png +0 -0
  55. data/results/cloudflare.png +0 -0
  56. data/results/headers.png +0 -0
  57. data/results/pixelscan.png +0 -0
  58. metadata +45 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 76c6ae8c74c3238f41db246836afd03b20c8bbb19a706575a424be2de6b84d41
4
- data.tar.gz: 9b07855d6fb9139e0c0a223bffa40f1558de7e82d4ca62ec20039ad22ceabfce
3
+ metadata.gz: 69be8ab00b56202a699439b91f9578f662570c4686fd290aa2c151d0f843b18d
4
+ data.tar.gz: 9513eee5138f694a31d628f0fbb63ced5c750c4e9213967c27a9cacddc04f799
5
5
  SHA512:
6
- metadata.gz: 2701dc1057b0f038f53aea6e42a34dc5a6a222900c61b2f1004f58dbb00453467d31ec8f8acb0e6a6545e4f32af5d2461873abdd898a0a47c05339dc65e038f6
7
- data.tar.gz: b8ef6aba60741c21570c36e68f4a3e6e9e4aa4fa52335284b8aef97f63fa3da7d5849bac44bc2c64db2436fd42f81adda365a5e00f63f60f119dc3e54dcb2533
6
+ metadata.gz: ee7d1248c446032c9940c3f63b8161e2c1350800c55bcff78bec2f0bf65363c2befcf2f135171f24c1987a996935d590e50b63b12dbc2bb3ddca7ce54ade95fd
7
+ data.tar.gz: ac9446088c14121f78cb7b53cce6cdaf3b71f8b0b1a1f89c8ec940ed8844e9f97eddaa87fb0533f4771fcd6fb3c0f8249edbba80b1f9d3adfbeb85dce5f60d49
data/.rubocop.yml CHANGED
@@ -5,6 +5,8 @@ AllCops:
5
5
  - 'Rakefile'
6
6
  - 'bin/**/*'
7
7
  - 'vendor/**/*'
8
+ - 'spec/support/**/*'
9
+ - 'docker_root/**/*'
8
10
 
9
11
  Style/StringLiterals:
10
12
  EnforcedStyle: single_quotes
data/CHANGELOG.md CHANGED
@@ -1,5 +1,74 @@
1
- ## [Unreleased]
1
+ # [Unreleased]
2
2
 
3
- ## [0.1.0] - 2024-10-26
3
+ ## 🚀 Features
4
+ - **Add specialized elements**: Added support for Select, Radio, and Checkbox elements with specific behaviors
4
5
 
5
- - Initial release
6
+ ## 🛠 Core Enhancements
7
+ - **Optimize element initialization**: Reduced redundant element searches by reusing element information
8
+ - **Add native option select**: Added support for native select option handling
9
+ - **Improve element attributes**: Exposed element attributes (node_id, object_id, root_id) for better control
10
+ - **Add BotBrowser binary usage**: Integrated BotBrowser binary for improved automation capabilities
11
+
12
+ # Changelog v0.0.2.pre
13
+
14
+ ## 🚀 Features
15
+ - **Add keyboard actions**: Implemented keyboard interactions, including typing and key pressing
16
+ - **Add drag and drop action**: Implemented drag and drop between elements
17
+ - **Add b64 screenshot option**: Added support for base64 encoded screenshots
18
+
19
+ ## 🛠 Core Enhancements
20
+ - **Improve mouse movements**: Keep mouse position between interaction during browser session
21
+ - **Improve mouse movements**: Improving Bézier curve usage for more human like behavior
22
+ - **Add log level**: Added configurable logging levels
23
+ - **Keep hardwares during session**: Maintain hardware state throughout the browser session
24
+ - **Add magick find**: Enhanced element finding capabilities
25
+ - **Refactor callFunctionOn usage**: Improved JavaScript function calling mechanism
26
+ - **Add started? method**: New method to check browser startup status
27
+ - **Wait for debug url**: Enhanced browser startup synchronization
28
+
29
+ # Changelog v0.0.1.pre
30
+
31
+ ## 🚀 Features
32
+ - **Add virtual mouse on macOS**: Introduced a virtual mouse controller for macOS. (commit `9cb095b`)
33
+ - **Abstract mouse control**: Unified mouse control across different operating systems with an abstraction layer. (commit `a7e0732`)
34
+ - **Add shadow interactor**: Added support for interacting with elements inside shadow DOM. (commit `6cdea5c`)
35
+
36
+ ## 🛠 Core Enhancements
37
+ - **Add debug_url spec**: Introduced debug specifications for better error tracking. (commit `4c06c75`)
38
+ - **Add client specs**: Comprehensive tests for the core client functionality. (commits `1e17955`, `18f0bf1`)
39
+ - **Add config spec**: Added configuration testing specs. (commit `588407f`)
40
+ - **Add MPEG for recording**: Integrated MPEG support for screen recording (currently experimental). (commit `d149a14`)
41
+ - **Improve arguments priority**: Refined the argument handling mechanism for better control. (commit `9849d0f`)
42
+ - **Add Dockerfile for testing**: Included a Docker setup for running tests in isolated environments. (commit `57f334e`)
43
+ - **Use xdotool for Linux and add X screenshot**: Enhanced Linux support using `xdotool` for mouse control and added X screenshot capability. (commit `80ef37f`)
44
+ - **Improve wait for load**: Improved logic for waiting until the page is fully loaded before proceeding. (commit `28e9371`)
45
+ - **Improve DOM events**: Enhanced handling of DOM events for better interaction. (commit `36a425c`)
46
+ - **Improve nested elements handling**: Enhanced support for working with nested and complex elements. (commit `ad03ec3`)
47
+ - **Get element attributes**: Added method to retrieve element attributes as a hash. (commit `b71e1f7`)
48
+ - **Add WEBrick for testing server**: Added a simple WEBrick server for testing purposes. (commit `fc70006`)
49
+ - **Improve element interactions**: Various improvements in element manipulation methods. (commit `5430d8c`)
50
+ - **Start native mouse support**: Began implementation of native mouse interactions. (commit `fce1aef`)
51
+ - **Improve undetection mechanisms**: Enhanced techniques to bypass bot detection. (commit `7ff622a`)
52
+
53
+ ## 🐛 Bug Fixes
54
+ - **Fix bad stop method**: Corrected an issue with the stopping method that caused unexpected behavior. (commit `4b45d6d`)
55
+ - **Fix Docker X size**: Resolved issues with the size of the X window in Docker environments. (commit `41edece`)
56
+
57
+ ## 📝 Documentation
58
+ - **Update README**: Updated the README file with new instructions and examples. (commit `8118913`)
59
+ - **Add logo**: Added a logo to the project for better branding. (commit `2a5cbb9`)
60
+
61
+ ## 🧪 CI/CD
62
+ - **Enable CI pipeline**: Added continuous integration (CI) setup for automated testing. (commit `4160aa1`)
63
+
64
+ ## 🧹 Refactor
65
+ - **Rename mouse hardware**: Refactored the naming conventions for mouse-related classes. (commit `89d6ae1`)
66
+ - **Remove record notion (temporary)**: Temporarily removed the recording feature for further refinement. (commit `fdb3e0e`)
67
+
68
+ ## 🛠 Infrastructure
69
+ - **Start adding Xvfb support**: Introduced Xvfb support for headless testing. (commit `678a8a5`)
70
+ - **Improve spec servers**: Made enhancements to the testing servers for more robust specs. (commit `51e64f4`)
71
+
72
+ ## 🏁 Project Initialization
73
+ - **Initialize project**: Set up the initial project structure. (commit `3ec91f4`)
74
+ - **Start element development**: Began the implementation of the `Element` class. (commit `adadef0`)
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
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/)
2
+ [![eth3rnit3 - chromate](https://img.shields.io/static/v1?label=eth3rnit3&message=chromate&color=a8a9ad&logo=ruby&labelColor=9b111e)](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=a8a9ad)](https://github.com/eth3rnit3/chromate/releases/)
4
+ [![License](https://img.shields.io/badge/License-MIT-a8a9ad)](#license)
4
5
  [![Ruby](https://github.com/Eth3rnit3/chromate/actions/workflows/main.yml/badge.svg)](https://github.com/Eth3rnit3/chromate/actions/workflows/main.yml)
5
6
  [![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
+ ![logo](logo.png)
7
9
 
8
10
  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
11
 
@@ -12,13 +14,30 @@ Chromate is a custom driver for Chrome using the Chrome DevTools Protocol (CDP)
12
14
  Add gem to your application's Gemfile:
13
15
 
14
16
  ```sh
15
- bundle add chromate
17
+ # Github pkgs
18
+ bundle add chromate --source https://rubygems.pkg.github.com/eth3rnit3
19
+
20
+ # Or add manualy within a block
21
+ # source "https://rubygems.pkg.github.com/eth3rnit3" do
22
+ # gem "chromate"
23
+ # end
24
+
25
+ # or
26
+
27
+ # Rubygems
28
+ bundle add chromate-rb
29
+
16
30
  ```
17
31
 
18
32
  Or install it yourself as:
19
33
 
20
34
  ```sh
21
- gem install chromate
35
+ # Github pkgs
36
+ gem install chromate --source https://rubygems.pkg.github.com/eth3rnit3
37
+
38
+ # or
39
+
40
+ gem install chromate-rb
22
41
  ```
23
42
 
24
43
  ## Usage
@@ -36,7 +55,7 @@ browser.start
36
55
  url = 'http://example.com'
37
56
  browser.navigate_to(url)
38
57
  browser.find_element('#some-element').click
39
- browser.screenshot_to_file('screenshot.png')
58
+ browser.screenshot('screenshot.png')
40
59
 
41
60
  browser.stop
42
61
  ```
@@ -106,6 +125,14 @@ ruby your_script.rb # or bundle exec rspec
106
125
 
107
126
  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
127
 
128
+ ## Disclaimer
129
+
130
+ **Chromate** is an open-source project designed to provide a solid foundation for the creation of autonomous AI agents, fostering innovation and development in the field of artificial intelligence. This project is developed with an educational and collaborative spirit, aiming to promote responsible and ethical usage.
131
+
132
+ Under no circumstances is **Chromate** intended to be used for creating automated bots, scraping tools, or any other activities that violate platform policies or applicable laws. The author disclaims any responsibility for improper or illegal use of this project.
133
+
134
+ Users are encouraged to comply with platform terms of service and to adopt practices that adhere to ethical and legal standards.
135
+
109
136
  ## Contribution
110
137
 
111
138
  Contributions are welcome! If you have suggestions for improvements or new features, please open an issue or submit a pull request on GitHub.
data/Rakefile CHANGED
@@ -12,9 +12,12 @@ RuboCop::RakeTask.new
12
12
  task default: %i[spec rubocop]
13
13
 
14
14
  require_relative "lib/chromate"
15
+ require_relative 'spec/support/modes'
15
16
 
16
17
  namespace :chromate do
17
18
  namespace :test do
19
+ include Support::Modes
20
+
18
21
  task :open do
19
22
  browser = Chromate::Browser.new(headless: false)
20
23
  browser.start
@@ -25,46 +28,75 @@ namespace :chromate do
25
28
  browser.stop
26
29
  end
27
30
 
31
+ # Xfvb mode
32
+ # docker run -it --rm -v $(pwd):/app --env CHROMATE_MODE=docker-xvfb chromate:latest bundle exec rake chromate:test:all
33
+
34
+ # BotBrowser mode
35
+ # docker run -it --rm -v $(pwd):/app --env CHROMATE_MODE=bot-browser chromate:latest bundle exec rake chromate:test:all
36
+
37
+ # Default mode
38
+ # docker run -it --rm -v $(pwd):/app chromate:latest bundle exec rake chromate:test:all
39
+ task :all do
40
+ Rake::Task["chromate:test:pixelscan"].invoke
41
+ Rake::Task["chromate:test:brotector"].invoke
42
+ Rake::Task["chromate:test:bot"].invoke
43
+ Rake::Task["chromate:test:cloudflare"].invoke
44
+ end
45
+
28
46
  task :pixelscan do
29
- browser = Chromate::Browser.new
47
+ browser = Chromate::Browser.new(browser_args)
30
48
  browser.start
31
49
  browser.navigate_to("https://pixelscan.net")
32
50
  sleep 10
33
- browser.screenshot_to_file("results/pixelscan.png")
51
+ browser.screenshot("results/pixelscan.png")
34
52
  browser.stop
35
53
  end
36
54
 
37
55
  task :brotector do
38
- require "chromate/native/mouse_controller"
39
- browser = Chromate::Browser.new
56
+ browser = Chromate::Browser.new(browser_args)
40
57
  browser.start
41
- browser.navigate_to("https://kaliiiiiiiiii.github.io/brotector?crash=false")
58
+ browser.navigate_to("https://kaliiiiiiiiii.github.io/brotector")
42
59
  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")
60
+ browser.find_element("#clickHere").click
61
+ sleep 3
62
+ browser.screenshot("results/brotector.png")
47
63
  browser.stop
48
64
  end
49
65
 
50
66
  task :bot do
51
- browser = Chromate::Browser.new
67
+ browser = Chromate::Browser.new(browser_args)
52
68
  browser.start
53
69
  browser.navigate_to("https://bot.sannysoft.com")
54
70
  sleep 2
55
- browser.screenshot_to_file("results/bot.png")
71
+ browser.screenshot("results/bot.png")
56
72
  browser.stop
57
73
  end
58
74
 
59
75
  task :cloudflare do
60
- Chromate.configure do |config|
61
- config.headless = false
62
- end
63
- browser = Chromate::Browser.new
76
+ browser = Chromate::Browser.new(browser_args)
64
77
  browser.start
65
78
  browser.navigate_to("https://2captcha.com/fr/demo/cloudflare-turnstile-challenge")
66
79
  sleep 10
67
- browser.screenshot_to_file("results/cloudflare.png")
80
+ browser.screenshot("results/cloudflare.png")
81
+ browser.stop
82
+ end
83
+
84
+ task :my_ip do
85
+ browser = Chromate::Browser.new(browser_args)
86
+ browser.start
87
+ browser.navigate_to("https://whatismyipaddress.com")
88
+ sleep 2
89
+ browser.find_element('//*[@id="qc-cmp2-ui"]/div[2]/div/button[3]').click
90
+ browser.screenshot("results/my_ip.png")
91
+ browser.stop
92
+ end
93
+
94
+ task :headers do
95
+ browser = Chromate::Browser.new(browser_args)
96
+ browser.start
97
+ browser.navigate_to("https://httpbin.org/headers")
98
+ sleep 2
99
+ browser.screenshot("results/headers.png")
68
100
  browser.stop
69
101
  end
70
102
  end
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'chromate', path: '/chromate'
4
+ gem 'webrick'
@@ -0,0 +1,28 @@
1
+ PATH
2
+ remote: /chromate
3
+ specs:
4
+ chromate (0.0.1.pre)
5
+ ffi (~> 1.17.0)
6
+ websocket-client-simple (~> 0.8.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ event_emitter (0.2.6)
12
+ ffi (1.17.0)
13
+ webrick (1.8.2)
14
+ websocket (1.2.11)
15
+ websocket-client-simple (0.8.0)
16
+ event_emitter
17
+ websocket
18
+
19
+ PLATFORMS
20
+ ruby
21
+ x86_64-linux
22
+
23
+ DEPENDENCIES
24
+ chromate!
25
+ webrick
26
+
27
+ BUNDLED WITH
28
+ 2.5.21
Binary file
@@ -0,0 +1,87 @@
1
+ require 'bundler/setup'
2
+ require 'chromate'
3
+ require '/chromate/spec/support/server'
4
+
5
+ class TestInDocker
6
+ include Support::Server
7
+
8
+ attr_reader :browser
9
+
10
+ def initialize
11
+ start_servers
12
+
13
+ @browser = Chromate::Browser.new(headless: false, xfvb: true, record: 'record.mp4', native_control: false)
14
+ @browser.start
15
+
16
+ trap('INT') { stop }
17
+ trap('TERM') { stop }
18
+
19
+ at_exit { stop }
20
+ end
21
+
22
+ def stop
23
+ @browser.stop
24
+ stop_servers
25
+ # Convert the video to a gif
26
+ pid = spawn('ffmpeg -i record.mp4 -vf "fps=10,scale=640:-1:flags=lanczos,palettegen" palette.png')
27
+ Process.wait(pid)
28
+ pid = spawn('ffmpeg -i record.mp4 -i palette.png -filter_complex "fps=10,scale=640:-1:flags=lanczos[x];[x][1:v]paletteuse" TestInDocker.gif')
29
+ Process.wait(pid)
30
+ end
31
+
32
+ def run
33
+ click_features
34
+ move_features
35
+ drag_and_drop_features
36
+ fill_form_features
37
+ shadow_dom_features
38
+ end
39
+
40
+ def click_features
41
+ url = server_urls['where_clicked']
42
+ browser.navigate_to(url)
43
+ browser.find_element('#interactive-button').click
44
+ sleep 1
45
+ end
46
+
47
+ def move_features
48
+ url = server_urls['where_moved']
49
+ browser.navigate_to(url)
50
+ browser.find_element('#red').hover
51
+ browser.find_element('#yellow').hover
52
+ browser.find_element('#green').hover
53
+ browser.find_element('#blue').hover
54
+ sleep 1
55
+ end
56
+
57
+ def drag_and_drop_features
58
+ url = server_urls['drag_and_drop']
59
+ browser.navigate_to(url)
60
+ blue_square = browser.find_element('#draggable')
61
+ green_square = browser.find_element('#dropzone')
62
+ blue_square.drop_to(green_square)
63
+ sleep 1
64
+ end
65
+
66
+ def fill_form_features
67
+ url = server_urls['fill_form']
68
+ browser.navigate_to(url)
69
+ browser.find_element('#first-name').type('John')
70
+ browser.find_element('#last-name').type('Doe')
71
+ browser.find_element('#gender').select_option('female')
72
+ browser.find_element('#option-2').click
73
+ browser.find_element('#submit-button').click
74
+ sleep 1
75
+ end
76
+
77
+ def shadow_dom_features
78
+ url = server_urls['shadow_checkbox']
79
+ browser.navigate_to(url)
80
+ shadow_container = browser.find_element('#shadow-container')
81
+ checkbox = shadow_container.find_shadow_child('#shadow-checkbox')
82
+ checkbox.click
83
+ sleep 1
84
+ end
85
+ end
86
+
87
+ TestInDocker.new.run
@@ -1,4 +1,4 @@
1
- FROM ruby:3.2-slim
1
+ FROM --platform=linux/amd64 ruby:3.2-slim
2
2
 
3
3
  RUN apt-get update && apt-get install -y \
4
4
  nano \
@@ -51,18 +51,23 @@ RUN apt-get update && apt-get install -y \
51
51
  psmisc \
52
52
  --no-install-recommends && rm -rf /var/lib/apt/lists/*
53
53
 
54
- # Donwload and install Chrome
54
+ # Préparer le système
55
+ RUN apt-get update && apt-get install -y wget gnupg2 lsb-release && rm -rf /var/lib/apt/lists/*
55
56
 
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
57
+ # Télécharger et ajouter la clé GPG
58
+ RUN wget -q -O- https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor -o /usr/share/keyrings/google-chrome.gpg
59
+
60
+ # Ajouter le dépôt Google Chrome
61
+ RUN echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/google-chrome.gpg] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list
62
+
63
+ # Mise à jour et installation de Google Chrome
64
+ RUN apt-get update && apt-get install -y google-chrome-stable
60
65
 
61
66
  ENV CHROME_BIN=/usr/bin/google-chrome
62
67
 
63
68
  RUN gem install bundler -v 2.5.21
64
69
 
65
- WORKDIR /app
70
+ WORKDIR /chromate
66
71
 
67
72
  COPY Gemfile Gemfile.lock chromate.gemspec ./
68
73
  COPY lib/chromate/version.rb ./lib/chromate/version.rb
@@ -77,9 +82,18 @@ COPY . .
77
82
 
78
83
  ENV DISPLAY=:99
79
84
 
85
+ WORKDIR /app
86
+
87
+ COPY docker_root/ /app/
88
+
80
89
  ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
81
90
 
82
91
  CMD [ "bash" ]
83
92
 
84
93
  # docker build -f dockerfiles/Dockerfile -t chromate .
94
+
95
+ # Run the container for testing chromate
96
+ # docker run -v $(pwd)/docker_root:/app -it chromate
97
+
98
+ # Run the container for development
85
99
  # docker run -v $(pwd):/app -it chromate
@@ -0,0 +1,49 @@
1
+ # Chromate Docker Configuration
2
+
3
+ This section explains how to configure and test the Chromate gem using Docker with xvfb support.
4
+
5
+ ![TestInDocker.gif](../docker_root/TestInDocker.gif)
6
+
7
+ ## Docker Setup
8
+
9
+ To simplify the setup process, Chromate includes a Dockerfile and an entrypoint script that handle the installation and configuration of necessary dependencies, including xvfb.
10
+
11
+ ### Dockerfile
12
+
13
+ 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.
14
+
15
+ ###
16
+
17
+ docker-entrypoint.sh
18
+
19
+
20
+
21
+ The entrypoint 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.
22
+
23
+ ### How to Use
24
+
25
+ 1. **Build the Docker Image**
26
+
27
+ ```sh
28
+ docker build -f dockerfiles/Dockerfile -t chromate .
29
+ ```
30
+
31
+ 2. **Run the Docker Container**
32
+
33
+ ```sh
34
+ docker run -v $(pwd)/docker_root:/app -it chromate
35
+ ```
36
+
37
+ This command mounts the current directory to `/app` inside the container and starts an interactive bash session.
38
+
39
+ 3. **Run the Test Script**
40
+
41
+ Inside the Docker container, run the test script:
42
+
43
+ ```sh
44
+ ruby app.rb
45
+ ```
46
+
47
+ ## Conclusion
48
+
49
+ 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.
@@ -0,0 +1,74 @@
1
+ # BotBrowser Documentation
2
+
3
+ BotBrowser is a specialized configuration module for Chromate that helps you manage and use a specific Chrome browser installation for bot automation purposes.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Installation](#installation)
8
+ 2. [Usage](#usage)
9
+ 3. [Configuration](#configuration)
10
+ 4. [API Reference](#api-reference)
11
+
12
+ ## Installation
13
+
14
+ First, require the BotBrowser module in your Ruby code:
15
+
16
+ ```ruby
17
+ require 'bot_browser'
18
+ ```
19
+
20
+ Then, install the browser:
21
+
22
+ ```ruby
23
+ # Install the latest version
24
+ BotBrowser.install
25
+
26
+ # Or install a specific version
27
+ BotBrowser.install('v130')
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Here's a basic example of how to use BotBrowser with Chromate:
33
+
34
+ ```ruby
35
+ require 'bot_browser'
36
+
37
+ # Install the browser if not already installed
38
+ BotBrowser.install unless BotBrowser.installed?
39
+
40
+ # Load the BotBrowser configuration
41
+ BotBrowser.load
42
+
43
+ # Create a new browser instance
44
+ browser = Chromate::Browser.new
45
+
46
+ # Use the browser as you would normally with Chromate
47
+ browser.navigate_to('https://example.com')
48
+ ```
49
+
50
+ ## Configuration
51
+
52
+ BotBrowser uses a configuration file located at `~/.botbrowser/config.yml`. This file is automatically created during installation and contains:
53
+
54
+ - `bot_browser_path`: Path to the Chrome binary
55
+ - `profile`: Path to the browser profile directory
56
+
57
+ ## API Reference
58
+
59
+ ### `BotBrowser.install(version = nil)`
60
+ Installs the Chrome browser for bot automation.
61
+ - `version`: Optional. Specific version to install. If not provided, installs the latest version.
62
+
63
+ ### `BotBrowser.uninstall`
64
+ Removes the installed browser and its configuration.
65
+
66
+ ### `BotBrowser.installed?`
67
+ Checks if the browser is installed.
68
+ - Returns: `true` if installed, `false` otherwise.
69
+
70
+ ### `BotBrowser.load`
71
+ Loads the BotBrowser configuration and sets up Chromate with the appropriate settings.
72
+ - Configures Chrome binary path
73
+ - Sets up browser profile
74
+ - Configures necessary Chrome flags for bot automation
data/docs/README.md ADDED
@@ -0,0 +1,74 @@
1
+ # Chromate Documentation Index
2
+
3
+ Welcome to the Chromate Documentation! This index provides an overview of the main classes and their detailed documentation, covering public methods, usage examples, and key features.
4
+
5
+ ## 📚 Table of Contents
6
+
7
+ 1. [Introduction](#introduction)
8
+ 2. [Classes Overview](#classes-overview)
9
+ 3. [Detailed Documentation](#detailed-documentation)
10
+ - [Chromate::Browser](#1-chromatebrowser-class)
11
+ - [Chromate::Element](#2-chromateelement-class)
12
+
13
+ ---
14
+
15
+ ## Introduction
16
+
17
+ Chromate is a Ruby-based library designed to interact with the Chrome DevTools Protocol (CDP). It allows you to control a headless Chrome browser, manipulate DOM elements, and perform automated tasks such as navigation, screenshot capture, and form submissions.
18
+
19
+ This documentation provides a comprehensive guide for the core components of Chromate:
20
+
21
+ - **Chromate::Browser**: Manages the browser instance, providing methods for starting, stopping, navigation, and executing browser actions.
22
+ - **Chromate::Element**: Represents a DOM element, enabling actions like clicking, typing, and attribute manipulation.
23
+
24
+ ## Classes Overview
25
+
26
+ | Class | Description |
27
+ | ------------------ | ----------------------------------------------------- |
28
+ | `Chromate::Browser`| A class for controlling the Chrome browser instance. |
29
+ | `Chromate::Element`| A class for interacting with individual DOM elements. |
30
+
31
+ ## Detailed Documentation
32
+
33
+ ### 1. `Chromate::Browser` Class
34
+
35
+ The `Browser` class is responsible for managing the lifecycle of a Chrome browser instance. It provides methods for navigation, screenshot capture, and DOM interaction. It also includes features for headless mode, native control, and video recording of sessions.
36
+
37
+ - **Features:**
38
+ - Start and stop the browser instance.
39
+ - Navigate to URLs, refresh, and go back in browser history.
40
+ - Capture full-page and Xvfb screenshots.
41
+ - Execute JavaScript code and interact with DOM elements.
42
+
43
+ For the full documentation and usage examples, refer to [Chromate::Browser Documentation](#chromatebrowser-class).
44
+
45
+ ### 2. `Chromate::Element` Class
46
+
47
+ The `Element` class provides a robust interface for interacting with DOM elements in the browser. It includes methods for text extraction, attribute manipulation, and user interaction simulation (click, hover, type).
48
+
49
+ - **Features:**
50
+ - Retrieve text and HTML content of an element.
51
+ - Set and get element attributes.
52
+ - Simulate user interactions (click, hover, type).
53
+ - Interact with shadow DOM elements.
54
+
55
+ For the full documentation and usage examples, refer to [Chromate::Element Documentation](#chromateelement-class).
56
+
57
+ ---
58
+
59
+ ## How to Get Started
60
+
61
+ To start using Chromate in your project, ensure that you have a working installation of Google Chrome and Ruby. Follow the setup instructions provided in the README file of the project.
62
+
63
+ Example usage:
64
+
65
+ ```ruby
66
+ require 'chromate'
67
+
68
+ browser = Chromate::Browser.new(headless: true)
69
+ browser.start
70
+ browser.navigate_to('https://example.com')
71
+ element = browser.find_element('#header')
72
+ puts element.text
73
+ browser.stop
74
+ ```