kleya 0.0.1 → 0.0.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 272b77784c8f74811be0db9402ff4694220c0a212ca4d6af53e6b61ff2398df0
4
- data.tar.gz: bb4451a8bb5bea56482ef1c48ae02b321da627218569fcca09ecd5c3d0b18b69
3
+ metadata.gz: eff98e2f9f6d36b1f9813df9531b6649f5791a7ebba7ba2597420165b17b1d1b
4
+ data.tar.gz: caafa5e7331acdfff97559ff5074d0fea116646a5913b53d6b3f142165682779
5
5
  SHA512:
6
- metadata.gz: 74262f4d700dc1d2d1c3e5e224801e8e95bdb55d47326167ba6a4d8154139e89a08d92a2a8ddd95b3e4af2ef01d5bf0ff12d5529213f57f963771864ffb363c4
7
- data.tar.gz: e1635c52e75051a00528aa59f4b70d58a28d7993ab1f1d414f60de869ed569198b3ccd726182393fc5169d31d1af4317aa0ab2a7d1b67c4f6c8b0a3d8db524da
6
+ metadata.gz: 9b3c354440ef1e46573c81ef777297185ce85bdced9ac521e52e170476c0fd8e0ac71400952d19bc82b71a865de27d5607ecf1f9501ff2803f78569308424971
7
+ data.tar.gz: 2cf4bcd76e4a2de54dd4b2a7363c10bfeb93195fdaa7d4a4c7846ffe1e372e45a512d5e9243da08eeb40053e95295dc1feae3e361f2e7260fefd8e4b9ea68367
data/README.md CHANGED
@@ -56,7 +56,7 @@ browser.quit
56
56
 
57
57
  Kleya includes convenient viewport presets for social media platforms and common devices. You can pass any of the following values when initializing a browser instance.
58
58
 
59
- - `desktop`: default (1920x1080)
59
+ - `desktop` default (1920x1080)
60
60
 
61
61
  - `x` (1200x675)
62
62
  - `facebook` (1200x630)
@@ -109,9 +109,10 @@ Kleya.capture('https://www.hellotext.com')
109
109
 
110
110
  Alongside the options you pass for the instance, there's some extra configurable settings you can tweak to your usecase.
111
111
 
112
- - `format`: specifies the format of the image captures, i.e `jpeg` or `png`.
113
- - `encoding`: specifies the encoding of the image, possible options is `binary` or `base64` (default). Regardless, the `Kleya::Artifact` object responds to `#binary` and `base64` when needed.
114
- - `quality`: an integer between 1 - 100 that determines the quality of the final image, higher quality images result in bigger sizes and may not work correctly in some situations such as the Open Graph (OG) protocol, you can tweak and test this. Defaults to `90`.
112
+ - `format` specifies the format of the image captures, i.e `jpeg` or `png`.
113
+ - `encoding` specifies the encoding of the image, possible options is `binary` or `base64` (default). Regardless, the `Kleya::Artifact` object responds to `#binary` and `base64` when needed.
114
+ - `quality` an integer between 1 - 100 that determines the quality of the final image, higher quality images result in bigger sizes and may not work correctly in some situations such as the Open Graph (OG) protocol, you can tweak and test this. Defaults to `90`.
115
+ - `area` specifies the area of the browser to capture, defaults to `viewport` for capturing only the visible part of the page. Supported values are `viewport` and `page` for full-page screenshots.
115
116
 
116
117
  ```ruby
117
118
  artifact = browser.capture('https://example.com', format: :jpeg, quality: 85, encoding: :base64)
@@ -181,12 +182,10 @@ end
181
182
  ## Roadmap
182
183
 
183
184
  - Wait strategies (`wait_for: '.element'`, `wait_until: :network_idle`)
184
- - Full page screenshots (not just viewport)
185
185
  - Built-in retry mechanism with configurable delays
186
186
 
187
187
  - Memory usage optimization for large batches
188
188
  - Request blocking (ads, analytics, fonts)
189
- - Custom user agents for mobile rendering
190
189
 
191
190
  - CLI tool for quick captures (`kleya capture https://example.com`)
192
191
  - Debug mode with browser preview
data/lib/kleya/browser.rb CHANGED
@@ -30,6 +30,7 @@ module Kleya
30
30
  # @option options [Symbol] :format (:jpeg) image format (:jpeg, :png)
31
31
  # @option options [Integer] :quality (90) JPEG quality (1-100)
32
32
  # @option options [Symbol] :encoding (:base64) output encoding
33
+ # @option options [Symbol] :area (:viewport) the area to capture (:viewport, :page)
33
34
  # @return [Artifact] the screenshot artifact
34
35
  # @example Taking a X-optimized screenshot
35
36
  # browser = Kleya::Browser.new(
@@ -43,12 +44,9 @@ module Kleya
43
44
  format = options[:format] || :jpeg
44
45
  quality = options[:quality] || 90
45
46
  encoding = options[:encoding] || :base64
47
+ full = options[:area] == :page
46
48
 
47
- data = browser.screenshot(
48
- format: format,
49
- quality: quality,
50
- encoding: encoding
51
- )
49
+ data = browser.screenshot(format:, quality:, encoding:, full:)
52
50
 
53
51
  Artifact.new(data:, url:, viewport: @viewport, format:, quality:, encoding:)
54
52
  rescue Ferrum::TimeoutError
data/test/browser_test.rb CHANGED
@@ -61,7 +61,7 @@ class BrowserTest < Minitest::Test
61
61
  @mock_ferrum.expect :goto, nil, ['https://example.com']
62
62
  # The screenshot method receives keyword arguments as a hash
63
63
  @mock_ferrum.expect :screenshot, 'fake_image_data' do |args|
64
- args == { format: :jpeg, quality: 90, encoding: :base64 }
64
+ args == { format: :jpeg, quality: 90, encoding: :base64, full: false }
65
65
  end
66
66
 
67
67
  artifact = browser.capture('https://example.com')
@@ -84,7 +84,7 @@ class BrowserTest < Minitest::Test
84
84
  @mock_ferrum.expect :goto, nil, ['https://example.com']
85
85
  # The screenshot method receives keyword arguments as a hash
86
86
  @mock_ferrum.expect :screenshot, 'fake_png_data' do |args|
87
- args == { format: :png, quality: 100, encoding: :binary }
87
+ args == { format: :png, quality: 100, encoding: :binary, full: false }
88
88
  end
89
89
 
90
90
  artifact = browser.capture('https://example.com',
@@ -100,6 +100,25 @@ class BrowserTest < Minitest::Test
100
100
 
101
101
  @mock_ferrum.verify
102
102
  end
103
+
104
+ def test_capture_with_full_area
105
+ browser = Kleya::Browser.new
106
+
107
+ Ferrum::Browser.stub :new, @mock_ferrum do
108
+ @mock_ferrum.expect :goto, nil, ['https://example.com']
109
+ # The screenshot method receives keyword arguments as a hash
110
+ @mock_ferrum.expect :screenshot, 'fake_full_image_data' do |args|
111
+ args == { format: :jpeg, quality: 90, encoding: :base64, full: true }
112
+ end
113
+
114
+ artifact = browser.capture('https://example.com', area: :page)
115
+
116
+ assert_instance_of Kleya::Artifact, artifact
117
+ assert_equal('fake_full_image_data', artifact.instance_variable_get(:@data))
118
+ end
119
+
120
+ @mock_ferrum.verify
121
+ end
103
122
 
104
123
  def test_capture_handles_timeout_error
105
124
  browser = Kleya::Browser.new
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kleya
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hellotext
8
8
  - Ahmed Khattab
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-21 00:00:00.000000000 Z
11
+ date: 2025-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest