bidi2pdf 0.1.11 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f566dbc37d780cfb8596d673639ab1ed944cf9306107a7ff65d0712d74fd9276
4
- data.tar.gz: 58273f6e806ea14372ae37f942c05582b80effe6a16cf172b965ea4f45e18108
3
+ metadata.gz: 50d4ec887f857a06009238d753ce6185f82afc416b54d63d38004cbc7ddc1d1f
4
+ data.tar.gz: 7790352b50f7f4b0af65a6ec7fb42b324430b4963f088fe909cef77c4acd2af6
5
5
  SHA512:
6
- metadata.gz: 1ec28d088c92fb1d48b42a68f51613045c13ad3d115c8fcd208ea37268ccc1520bf33af1070df513eaa50001259438222af0413f378195539b3eb3e2c95ef292
7
- data.tar.gz: e52a3b58e025f726d46c1a512a54e932e744181a021e3e2b3c02b6f12f5d13b8a3d3d285568ce09e98f61476c37eb2ba13cb2b1920f75f443a076931f6dd067c
6
+ metadata.gz: 118ea121a673b57dec8de4af3c2b95e28cd24b817a8042de91a2760fa16a004b38c94525cdd5f8acb324832d0a13f216c2a11c2d2e303fd636bf90dfa5121e05
7
+ data.tar.gz: a5f5ceaa9811449fb41bdccde0c9d4f5a74bf5cfb216c159874a20b4e6dcc0caf9719468c2b44e94a827b7ca12af3f80ddc40bb39d8814026791c97c49f7f768
data/CHANGELOG.md CHANGED
@@ -10,6 +10,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
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
+
13
41
  ## [0.1.11] - 2025-07-09
14
42
 
15
43
  ### 🐛 Fixed
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
1
  [![Build Status](https://github.com/dieter-medium/bidi2pdf/actions/workflows/ruby.yml/badge.svg)](https://github.com/dieter-medium/bidi2pdf/blob/main/.github/workflows/ruby.yml)
2
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/maintainability)](https://codeclimate.com/github/dieter-medium/bidi2pdf/maintainability)
3
3
  [![Gem Version](https://badge.fury.io/rb/bidi2pdf.svg)](https://badge.fury.io/rb/bidi2pdf)
4
- [![Test Coverage](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/test_coverage)](https://codeclimate.com/github/dieter-medium/bidi2pdf/test_coverage)
5
4
  [![Open Source Helpers](https://www.codetriage.com/dieter-medium/bidi2pdf/badges/users.svg)](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
- def render_html_content(html_content)
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
- navigate_with_listeners data_url
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}"
@@ -32,8 +32,8 @@ module Bidi2pdf
32
32
  text.gsub("\uFB01", "fi")
33
33
  .gsub("\uFB02", "fl")
34
34
  .gsub("-\n", "")
35
- .gsub(/["]/, '"')
36
- .gsub(/[']/, "'")
35
+ .gsub('"', '"')
36
+ .gsub("'", "'")
37
37
  .gsub("…", "...")
38
38
  .gsub("—", "--")
39
39
  .gsub("–", "-")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bidi2pdf
4
- VERSION = "0.1.11"
4
+ VERSION = "0.1.12"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bidi2pdf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dieter S.