bidi2pdf 0.1.6 → 0.1.7

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -1
  3. data/CHANGELOG.md +32 -4
  4. data/README.md +14 -0
  5. data/docker/Dockerfile +1 -1
  6. data/docker/Dockerfile.chromedriver +1 -1
  7. data/docker/Dockerfile.slim +2 -2
  8. data/lib/bidi2pdf/bidi/browser_console_logger.rb +92 -0
  9. data/lib/bidi2pdf/bidi/browser_tab.rb +391 -41
  10. data/lib/bidi2pdf/bidi/client.rb +85 -23
  11. data/lib/bidi2pdf/bidi/command_manager.rb +46 -48
  12. data/lib/bidi2pdf/bidi/commands/base.rb +39 -1
  13. data/lib/bidi2pdf/bidi/commands/browser_remove_user_context.rb +27 -0
  14. data/lib/bidi2pdf/bidi/commands/browsing_context_print.rb +4 -0
  15. data/lib/bidi2pdf/bidi/commands/print_parameters_validator.rb +5 -0
  16. data/lib/bidi2pdf/bidi/commands.rb +1 -0
  17. data/lib/bidi2pdf/bidi/event_manager.rb +1 -1
  18. data/lib/bidi2pdf/bidi/interceptor.rb +1 -1
  19. data/lib/bidi2pdf/bidi/js_logger_helper.rb +16 -0
  20. data/lib/bidi2pdf/bidi/logger_events.rb +25 -45
  21. data/lib/bidi2pdf/bidi/network_event.rb +15 -0
  22. data/lib/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rb +4 -3
  23. data/lib/bidi2pdf/bidi/network_events.rb +27 -17
  24. data/lib/bidi2pdf/bidi/session.rb +119 -12
  25. data/lib/bidi2pdf/bidi/user_context.rb +62 -0
  26. data/lib/bidi2pdf/bidi/web_socket_dispatcher.rb +7 -7
  27. data/lib/bidi2pdf/chromedriver_manager.rb +48 -21
  28. data/lib/bidi2pdf/cli.rb +10 -2
  29. data/lib/bidi2pdf/dsl.rb +33 -0
  30. data/lib/bidi2pdf/launcher.rb +30 -0
  31. data/lib/bidi2pdf/notifications/event.rb +52 -0
  32. data/lib/bidi2pdf/notifications/instrumenter.rb +65 -0
  33. data/lib/bidi2pdf/notifications/logging_subscriber.rb +136 -0
  34. data/lib/bidi2pdf/notifications.rb +78 -0
  35. data/lib/bidi2pdf/session_runner.rb +35 -3
  36. data/lib/bidi2pdf/verbose_logger.rb +79 -0
  37. data/lib/bidi2pdf/version.rb +1 -1
  38. data/lib/bidi2pdf.rb +99 -7
  39. data/sig/bidi2pdf/bidi/client.rbs +1 -1
  40. metadata +39 -4
  41. data/lib/bidi2pdf/utils.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 541e9193b3285383b2a82065b173af87c68edeb08ec157125761f44285118dff
4
- data.tar.gz: ab12e33ad21e8377ef964aa12d0d9b0ba757ee941c217febe6d46fb1cc381d5e
3
+ metadata.gz: 766b41f0ee642cd7316d0f72d8dd707b0f45aae4a315a46c2b27fb6bb2d176a6
4
+ data.tar.gz: aeec0549f82ff7bdd68d1aa658ea6ad2033e5310fd5936f40b94007b4ae6c38f
5
5
  SHA512:
6
- metadata.gz: 91be15b3310098c7f16153331fa0a27a8b869dfebc9f3720a7da26d2c59b8444f266e21e93d74891b423e50d8223b01b2198f230753d38ad523b8c846c12150f
7
- data.tar.gz: 504516ecc1eac40e6c6e159c5f14aafdeb9d23bc587fcf6914ab60d8676a930a7866d6d0c07998398359c402780584f1e5b317c274dd6f3dba0ba50c1a73cbe6
6
+ metadata.gz: cc7f1da58549b642521808b9ea2acc4b04068bdb7c877cf52943d2ae69bb989f2ade02601b8bfd0e409440ad8644206bba1e6e16603eb56099b8963a2136e350
7
+ data.tar.gz: 6258250ac5de22034cbb7816d3ff33c62680747a3eaee171fdd784d309bf1cd7880ca60e45342da8ee9195814ef1c78ca9b45b2c435f9fcbc4aaa43a8d7f95e6
data/.rubocop.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  AllCops:
2
2
  NewCops: enable
3
- TargetRubyVersion: 3.0
3
+ TargetRubyVersion: 3.3
4
4
 
5
5
  Style/StringLiterals:
6
6
  EnforcedStyle: double_quotes
@@ -44,6 +44,9 @@ Layout/ArrayAlignment:
44
44
  Layout/LineLength:
45
45
  Enabled: false
46
46
 
47
+ Layout/LineEndStringConcatenationIndentation:
48
+ Enabled: false
49
+
47
50
  RSpec/MultipleMemoizedHelpers:
48
51
  Max: 10
49
52
 
data/CHANGELOG.md CHANGED
@@ -7,11 +7,37 @@ All notable changes to this project will be documented in this file.
7
7
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8
8
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
9
9
 
10
- [unreleased]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.5..HEAD
11
-
12
10
  <!-- generated by git-cliff end -->
13
11
 
14
- ## [0.1.6]
12
+ ## [0.1.7] - 2025-04-17
13
+
14
+ ### 🎨 Refactored
15
+
16
+ - Move notification releated classes to new folder by @dieter-medium
17
+
18
+ ### 🔄 Changed
19
+
20
+ - Refactore custom check script in wait_until_page_loaded by @dieter-medium
21
+ - Add logger support to NetworkEventConsoleFormatter by @dieter-medium
22
+ - Refactore browser console logger support for enhanced logging by @dieter-medium
23
+
24
+ ### 🚀 Added
25
+
26
+ - Add support for predefined paper formats by @dieter-medium
27
+ - Add support for websocket-native for performance boost by @dieter-medium
28
+ - Add logging for print events by @dieter-medium
29
+ - Add configurable logging and notification service by @dieter-medium
30
+ - Introduce VerboseLogger for configurable debug levels by @dieter-medium
31
+ - Instrument Bidi2pdf methods with notification service for enhanced logging by @dieter-medium
32
+ - Introduce notifications system with event instrumentation and logging compatible to rails by @dieter-medium
33
+ - Enhance ChromedriverManager with chrome_args and improve session handling by @dieter-medium
34
+ - Add wait_until_page_loaded method for improved page load handling by @dieter-medium
35
+ - Enhance Chromedriver process management with platform-specific options by @dieter-medium
36
+ - Implement BrowserRemoveUserContext command and enhance user context cleanup by @dieter-medium
37
+ - Add style injection functionality to BrowserTab class by @dieter-medium
38
+ - Add script injection functionality to BrowserTab class by @dieter-medium
39
+
40
+ ## [0.1.6] - 2025-04-12
15
41
 
16
42
  ### ⚠️ Breaking Changes
17
43
 
@@ -117,7 +143,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
117
143
 
118
144
  - Initial release
119
145
 
120
- [unreleased]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.6..HEAD
146
+ [unreleased]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.7..HEAD
147
+
148
+ [unreleased]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.6..v0.1.7
121
149
 
122
150
  [0.1.6]: https://github.com/dieter-medium/bidi2pdf/compare/v0.1.5..v0.1.6
123
151
 
data/README.md CHANGED
@@ -2,6 +2,7 @@
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
4
  [![Test Coverage](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/test_coverage)](https://codeclimate.com/github/dieter-medium/bidi2pdf/test_coverage)
5
+ [![Open Source Helpers](https://www.codetriage.com/dieter-medium/bidi2pdf/badges/users.svg)](https://www.codetriage.com/dieter-medium/bidi2pdf)
5
6
 
6
7
  ---
7
8
 
@@ -149,12 +150,25 @@ tab.navigate_to "https://example.com"
149
150
  # Alternative: send html code to the browser
150
151
  # tab.render_html_content("<html>...</html>")
151
152
 
153
+ # Inject JavaScript if, needed
154
+ # as an url
155
+ # tab.inject_script "https://example.com/script.js"
156
+ # or inline
157
+ # tab.inject_script "console.log('Hello from injected script!')"
158
+
159
+ # Inject CSS if needed
160
+ # as an url
161
+ # tab.inject_style url: "https://example.com/simple.css"
162
+ # or inline
163
+ # tab.inject_style content: "body { background-color: red; }"
164
+
152
165
  tab.wait_until_network_idle
153
166
  tab.print("my.pdf")
154
167
 
155
168
  # 5. Cleanup
156
169
  tab.close
157
170
  window.close
171
+ context.close
158
172
  session.close
159
173
  ```
160
174
 
data/docker/Dockerfile CHANGED
@@ -3,7 +3,7 @@ FROM ruby:3.3
3
3
  ENV DEBIAN_FRONTEND=noninteractive
4
4
 
5
5
  # Install dependencies
6
- RUN apt-get update && apt-get upgrade &&\
6
+ RUN apt-get update && apt-get upgrade -y &&\
7
7
  apt-get install -y --no-install-recommends\
8
8
  chromium chromium-driver\
9
9
  libglib2.0-0 \
@@ -5,7 +5,7 @@ ARG CHROMEDRIVER_PORT=3000
5
5
  ENV DEBIAN_FRONTEND=noninteractive
6
6
 
7
7
  # Install dependencies
8
- RUN apt-get update && apt-get upgrade && \
8
+ RUN apt-get update && apt-get upgrade -y && \
9
9
  apt-get install -y --no-install-recommends\
10
10
  chromium \
11
11
  libglib2.0-0 \
@@ -3,7 +3,7 @@ FROM ruby:3.3-slim AS builder
3
3
  ENV DEBIAN_FRONTEND=noninteractive
4
4
 
5
5
  # Install dependencies
6
- RUN apt-get update && apt-get upgrade && \
6
+ RUN apt-get update && apt-get upgrade -y && \
7
7
  apt-get install -y --no-install-recommends \
8
8
  chromium \
9
9
  libglib2.0-0 \
@@ -36,7 +36,7 @@ FROM ruby:3.3-slim
36
36
  ENV DEBIAN_FRONTEND=noninteractive
37
37
 
38
38
  # Install dependencies
39
- RUN apt-get update && apt-get upgrade &&\
39
+ RUN apt-get update && apt-get upgrade -y &&\
40
40
  apt-get install -y --no-install-recommends\
41
41
  chromium chromium-driver\
42
42
  libglib2.0-0 \
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "js_logger_helper"
4
+
5
+ module Bidi2pdf
6
+ module Bidi
7
+ class BrowserConsoleLoggerSuggar
8
+ attr_reader :browser_console_logger
9
+
10
+ def initialize(browser_console_logger)
11
+ @browser_console_logger = browser_console_logger
12
+ end
13
+
14
+ def with_level(level)
15
+ @level = level
16
+ self
17
+ end
18
+
19
+ def with_prefix(prefix)
20
+ @prefix = prefix
21
+ self
22
+ end
23
+
24
+ def with_timestamp(timestamp)
25
+ @timestamp = timestamp
26
+ self
27
+ end
28
+
29
+ def with_text(text)
30
+ @text = text
31
+ self
32
+ end
33
+
34
+ def with_args(args)
35
+ @args = args
36
+ self
37
+ end
38
+
39
+ def with_stack_trace(stack_trace)
40
+ @stack_trace = stack_trace
41
+ self
42
+ end
43
+
44
+ def log_event
45
+ browser_console_logger.log_message(@level, @prefix, @text)
46
+ browser_console_logger.log_args(@prefix, @args)
47
+ browser_console_logger.log_stack_trace(@prefix, @stack_trace) if @stack_trace && @level == :error
48
+ end
49
+
50
+ def prefix
51
+ @prefix ||= "[#{BrowserConsoleLogger.format_timestamp(@timestamp)}][Browser Console Log]"
52
+ end
53
+ end
54
+
55
+ class BrowserConsoleLogger
56
+ include JsLoggerHelper
57
+
58
+ attr_accessor :logger
59
+
60
+ def initialize(logger)
61
+ @logger = logger
62
+ end
63
+
64
+ def builder
65
+ BrowserConsoleLoggerSuggar.new(self)
66
+ end
67
+
68
+ def log_message(level, prefix, text)
69
+ return unless text
70
+
71
+ logger.send(level, "#{prefix} #{text}")
72
+ end
73
+
74
+ def log_args(prefix, args)
75
+ return if args.empty?
76
+
77
+ logger.debug("#{prefix} Args: #{args.inspect}")
78
+ end
79
+
80
+ def log_stack_trace(prefix, trace)
81
+ formatted_trace = format_stack_trace(trace)
82
+ logger.error("#{prefix} Stack trace captured:\n#{formatted_trace}")
83
+ end
84
+
85
+ def self.format_timestamp(timestamp)
86
+ return "N/A" unless timestamp
87
+
88
+ Time.at(timestamp.to_f / 1000).utc.strftime("%Y-%m-%d %H:%M:%S.%L UTC")
89
+ end
90
+ end
91
+ end
92
+ end