bidi2pdf 0.1.10 → 0.1.12
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 +4 -4
- data/CHANGELOG.md +47 -3
- data/README.md +0 -1
- data/lib/bidi2pdf/bidi/browser_tab.rb +48 -6
- data/lib/bidi2pdf/chromedriver_manager.rb +20 -3
- data/lib/bidi2pdf/dsl.rb +1 -1
- data/lib/bidi2pdf/test_helpers/pdf_text_sanitizer.rb +2 -2
- data/lib/bidi2pdf/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50d4ec887f857a06009238d753ce6185f82afc416b54d63d38004cbc7ddc1d1f
|
4
|
+
data.tar.gz: 7790352b50f7f4b0af65a6ec7fb42b324430b4963f088fe909cef77c4acd2af6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 118ea121a673b57dec8de4af3c2b95e28cd24b817a8042de91a2760fa16a004b38c94525cdd5f8acb324832d0a13f216c2a11c2d2e303fd636bf90dfa5121e05
|
7
|
+
data.tar.gz: a5f5ceaa9811449fb41bdccde0c9d4f5a74bf5cfb216c159874a20b4e6dcc0caf9719468c2b44e94a827b7ca12af3f80ddc40bb39d8814026791c97c49f7f768
|
data/CHANGELOG.md
CHANGED
@@ -6,10 +6,53 @@ All notable changes to this project will be documented in this file.
|
|
6
6
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
7
7
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
8
8
|
|
9
|
-
[unreleased]: https://github.com///compare/v0.1.
|
9
|
+
[unreleased]: https://github.com///compare/v0.1.11..HEAD
|
10
10
|
|
11
11
|
<!-- generated by git-cliff end -->
|
12
12
|
|
13
|
+
## [0.1.12] - 2025-09-02
|
14
|
+
|
15
|
+
### 🔄 Changed
|
16
|
+
|
17
|
+
- Merge pull request #37 from dieter-medium/dependabot/bundler/main/ruby-vips-2.2.5
|
18
|
+
- Merge pull request #34 from dieter-medium/enhance-timeout-error-handling-during-navigate
|
19
|
+
- Merge pull request #33 from dieter-medium/dependabot/bundler/main/rubocop-1.79.2
|
20
|
+
- Merge pull request #32 from dieter-medium/dependabot/bundler/main/rubocop-1.79.1
|
21
|
+
- Merge pull request #31 from dieter-medium/dependabot/bundler/main/json-2.13.2
|
22
|
+
- Merge branch 'main' into dependabot/bundler/main/json-2.13.2
|
23
|
+
- Merge pull request #30 from dieter-medium/dependabot/bundler/main/rubocop-1.79.0
|
24
|
+
- Merge pull request #29 from dieter-medium/remove-codeclimate
|
25
|
+
- Merge pull request #27 from dieter-medium/dependabot/bundler/main/json-2.13.0
|
26
|
+
- Merge branch 'main' into dependabot/bundler/main/json-2.13.0
|
27
|
+
- Merge pull request #28 from dieter-medium/dependabot/bundler/main/thor-1.4.0
|
28
|
+
- Merge pull request #26 from dieter-medium/dependabot/bundler/main/rubocop-1.78.0
|
29
|
+
|
30
|
+
### 🔧 Build
|
31
|
+
|
32
|
+
- Bump ruby-vips from 2.2.4 to 2.2.5
|
33
|
+
- Bump rubocop from 1.77.0 to 1.79.2
|
34
|
+
- Bump json from 2.12.2 to 2.13.2
|
35
|
+
- Bump thor from 1.3.2 to 1.4.0
|
36
|
+
|
37
|
+
### 🚀 Added
|
38
|
+
|
39
|
+
- Improve navigation timeout error handling
|
40
|
+
|
41
|
+
## [0.1.11] - 2025-07-09
|
42
|
+
|
43
|
+
### 🐛 Fixed
|
44
|
+
|
45
|
+
- Add chrome_args to ChromedriverManager initialization
|
46
|
+
|
47
|
+
### 🔧 Build
|
48
|
+
|
49
|
+
- Bump rubocop from 1.76.2 to 1.77.0
|
50
|
+
- Bump ruby-vips from 2.2.3 to 2.2.4
|
51
|
+
|
52
|
+
### 🚀 Added
|
53
|
+
|
54
|
+
- Enhance ChromeDriver command arguments
|
55
|
+
|
13
56
|
## [0.1.10] - 2025-06-18
|
14
57
|
|
15
58
|
### 💄 Style
|
@@ -254,9 +297,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
254
297
|
|
255
298
|
- Initial release
|
256
299
|
|
257
|
-
|
300
|
+
### 🔄 Released
|
258
301
|
|
259
|
-
- [unreleased](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.
|
302
|
+
- [unreleased](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.11..HEAD)
|
303
|
+
- [0.1.11](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.10..V0.1.11)
|
260
304
|
- [0.1.10](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.9..V0.1.10)
|
261
305
|
- [0.1.9](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.8..v0.1.9)
|
262
306
|
- [0.1.8](https://github.com/dieter-medium/bidi2pdf/compare/v0.1.7..v0.1.8)
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
[](https://github.com/dieter-medium/bidi2pdf/blob/main/.github/workflows/ruby.yml)
|
2
2
|
[](https://codeclimate.com/github/dieter-medium/bidi2pdf/maintainability)
|
3
3
|
[](https://badge.fury.io/rb/bidi2pdf)
|
4
|
-
[](https://codeclimate.com/github/dieter-medium/bidi2pdf/test_coverage)
|
5
4
|
[](https://www.codetriage.com/dieter-medium/bidi2pdf)
|
6
5
|
|
7
6
|
---
|
@@ -172,7 +172,7 @@ module Bidi2pdf
|
|
172
172
|
# @raise [NavigationError] If the URL is invalid or improperly formatted.
|
173
173
|
# @example
|
174
174
|
# browser_tab.navigate_to("https://example.com")
|
175
|
-
def navigate_to(url)
|
175
|
+
def navigate_to(url, wait: "complete")
|
176
176
|
begin
|
177
177
|
URI.parse(url)
|
178
178
|
rescue URI::InvalidURIError => e
|
@@ -180,14 +180,15 @@ module Bidi2pdf
|
|
180
180
|
end
|
181
181
|
|
182
182
|
Bidi2pdf.notification_service.instrument("navigate_to.bidi2pdf", url: url) do
|
183
|
-
navigate_with_listeners url
|
183
|
+
navigate_with_listeners url, wait: wait
|
184
184
|
end
|
185
185
|
end
|
186
186
|
|
187
187
|
# Renders HTML content in the browser tab.
|
188
188
|
#
|
189
189
|
# @param [String] html_content The HTML content to render.
|
190
|
-
|
190
|
+
# rubocop:disable Metrics/BlockLength
|
191
|
+
def render_html_content(html_content, wait: "complete")
|
191
192
|
Bidi2pdf.notification_service.instrument("render_html_content.bidi2pdf", url: "data:text/html") do |instrumentation_payload|
|
192
193
|
base64_encoded = Base64.strict_encode64(html_content)
|
193
194
|
|
@@ -195,10 +196,51 @@ module Bidi2pdf
|
|
195
196
|
|
196
197
|
data_url = "data:text/html;charset=utf-8;base64,#{base64_encoded}"
|
197
198
|
|
198
|
-
|
199
|
+
begin
|
200
|
+
navigate_with_listeners data_url, wait: wait
|
201
|
+
rescue Bidi2pdf::CmdTimeoutError
|
202
|
+
Bidi2pdf.logger.info "Waiting for page to load seemed to have timed out. Checking if page is ready via javascript..."
|
203
|
+
|
204
|
+
# check if the page is still loading
|
205
|
+
execute_script <<~JS, wrap_in_promise: false
|
206
|
+
const desiredState = "interactive";#{" "}
|
207
|
+
const timeoutMs = 30000;#{" "}
|
208
|
+
const intervalMs = 50;
|
209
|
+
|
210
|
+
result = new Promise((resolveReady, rejectReady) => {
|
211
|
+
const start = Date.now();
|
212
|
+
|
213
|
+
const reachedDesired = (state) =>
|
214
|
+
desiredState === "interactive"
|
215
|
+
? state === "interactive" || state === "complete"
|
216
|
+
: state === "complete";
|
217
|
+
|
218
|
+
const check = () => {
|
219
|
+
const state = document.readyState;
|
220
|
+
if (reachedDesired(state)) {
|
221
|
+
resolveReady(state); // resolves to "interactive" or "complete"
|
222
|
+
return;
|
223
|
+
}
|
224
|
+
if (Date.now() - start >= timeoutMs) {
|
225
|
+
rejectReady(new Error(`Timeout waiting for document.readyState="${desiredState}". Last state="${state}".`));
|
226
|
+
return;
|
227
|
+
}
|
228
|
+
|
229
|
+
console.warn(`Waiting for document.readyState="${desiredState}". Last state="${state}".`);
|
230
|
+
|
231
|
+
setTimeout(check, intervalMs);
|
232
|
+
};
|
233
|
+
|
234
|
+
// Immediate check in case the page is already loaded
|
235
|
+
check();
|
236
|
+
});
|
237
|
+
JS
|
238
|
+
end
|
199
239
|
end
|
200
240
|
end
|
201
241
|
|
242
|
+
# rubocop:enable Metrics/BlockLength
|
243
|
+
|
202
244
|
# Executes a script in the browser tab.
|
203
245
|
#
|
204
246
|
# This method allows you to execute JavaScript code within the context of the browser tab.
|
@@ -434,10 +476,10 @@ module Bidi2pdf
|
|
434
476
|
end
|
435
477
|
end
|
436
478
|
|
437
|
-
def navigate_with_listeners(url)
|
479
|
+
def navigate_with_listeners(url, wait: "complete")
|
438
480
|
register_event_listeners
|
439
481
|
|
440
|
-
cmd = Bidi2pdf::Bidi::Commands::BrowsingContextNavigate.new url: url, context: browsing_context_id
|
482
|
+
cmd = Bidi2pdf::Bidi::Commands::BrowsingContextNavigate.new url: url, context: browsing_context_id, wait: wait
|
441
483
|
|
442
484
|
client.send_cmd_and_wait(cmd) do |response|
|
443
485
|
Bidi2pdf.logger.debug "Navigated to page url: #{url} response: #{response}"
|
@@ -181,16 +181,33 @@ module Bidi2pdf
|
|
181
181
|
|
182
182
|
def build_cmd
|
183
183
|
bin = Chromedriver::Binary::ChromedriverDownloader.driver_path
|
184
|
-
user_data_dir = File.join(Dir.tmpdir, "bidi2pdf", "user_data", SecureRandom.hex(8))
|
185
184
|
|
186
185
|
cmd = [bin]
|
187
186
|
cmd << "--port=#{@port}" unless @port.zero?
|
188
187
|
cmd << "--headless" if @headless
|
189
|
-
|
190
|
-
cmd <<
|
188
|
+
|
189
|
+
cmd << user_data_dir_arg
|
190
|
+
cmd.concat(process_chrome_args)
|
191
|
+
|
191
192
|
cmd.join(" ")
|
192
193
|
end
|
193
194
|
|
195
|
+
def user_data_dir_arg
|
196
|
+
provided = @chrome_args&.find { |arg| arg.include?("--user-data-dir") }
|
197
|
+
return provided if provided
|
198
|
+
|
199
|
+
user_data_dir = File.join(Dir.tmpdir, "bidi2pdf", "user_data", SecureRandom.hex(8))
|
200
|
+
"--user-data-dir #{user_data_dir}"
|
201
|
+
end
|
202
|
+
|
203
|
+
def process_chrome_args
|
204
|
+
return [] unless @chrome_args
|
205
|
+
|
206
|
+
%w[--lang --accept-lang].map do |arg_name|
|
207
|
+
@chrome_args.find { |chrome_arg| chrome_arg.include?(arg_name) }
|
208
|
+
end.compact
|
209
|
+
end
|
210
|
+
|
194
211
|
def update_chromedriver
|
195
212
|
Chromedriver::Binary::ChromedriverDownloader.update
|
196
213
|
end
|
data/lib/bidi2pdf/dsl.rb
CHANGED
@@ -50,7 +50,7 @@ module Bidi2pdf
|
|
50
50
|
chrome_args: chrome_args
|
51
51
|
)
|
52
52
|
else
|
53
|
-
manager = Bidi2pdf::ChromedriverManager.new(port: port, headless: headless)
|
53
|
+
manager = Bidi2pdf::ChromedriverManager.new(port: port, headless: headless, chrome_args: chrome_args)
|
54
54
|
manager.start
|
55
55
|
manager.session
|
56
56
|
end
|
data/lib/bidi2pdf/version.rb
CHANGED