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.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +32 -4
- data/README.md +14 -0
- data/docker/Dockerfile +1 -1
- data/docker/Dockerfile.chromedriver +1 -1
- data/docker/Dockerfile.slim +2 -2
- data/lib/bidi2pdf/bidi/browser_console_logger.rb +92 -0
- data/lib/bidi2pdf/bidi/browser_tab.rb +391 -41
- data/lib/bidi2pdf/bidi/client.rb +85 -23
- data/lib/bidi2pdf/bidi/command_manager.rb +46 -48
- data/lib/bidi2pdf/bidi/commands/base.rb +39 -1
- data/lib/bidi2pdf/bidi/commands/browser_remove_user_context.rb +27 -0
- data/lib/bidi2pdf/bidi/commands/browsing_context_print.rb +4 -0
- data/lib/bidi2pdf/bidi/commands/print_parameters_validator.rb +5 -0
- data/lib/bidi2pdf/bidi/commands.rb +1 -0
- data/lib/bidi2pdf/bidi/event_manager.rb +1 -1
- data/lib/bidi2pdf/bidi/interceptor.rb +1 -1
- data/lib/bidi2pdf/bidi/js_logger_helper.rb +16 -0
- data/lib/bidi2pdf/bidi/logger_events.rb +25 -45
- data/lib/bidi2pdf/bidi/network_event.rb +15 -0
- data/lib/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rb +4 -3
- data/lib/bidi2pdf/bidi/network_events.rb +27 -17
- data/lib/bidi2pdf/bidi/session.rb +119 -12
- data/lib/bidi2pdf/bidi/user_context.rb +62 -0
- data/lib/bidi2pdf/bidi/web_socket_dispatcher.rb +7 -7
- data/lib/bidi2pdf/chromedriver_manager.rb +48 -21
- data/lib/bidi2pdf/cli.rb +10 -2
- data/lib/bidi2pdf/dsl.rb +33 -0
- data/lib/bidi2pdf/launcher.rb +30 -0
- data/lib/bidi2pdf/notifications/event.rb +52 -0
- data/lib/bidi2pdf/notifications/instrumenter.rb +65 -0
- data/lib/bidi2pdf/notifications/logging_subscriber.rb +136 -0
- data/lib/bidi2pdf/notifications.rb +78 -0
- data/lib/bidi2pdf/session_runner.rb +35 -3
- data/lib/bidi2pdf/verbose_logger.rb +79 -0
- data/lib/bidi2pdf/version.rb +1 -1
- data/lib/bidi2pdf.rb +99 -7
- data/sig/bidi2pdf/bidi/client.rbs +1 -1
- metadata +39 -4
- data/lib/bidi2pdf/utils.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 766b41f0ee642cd7316d0f72d8dd707b0f45aae4a315a46c2b27fb6bb2d176a6
|
4
|
+
data.tar.gz: aeec0549f82ff7bdd68d1aa658ea6ad2033e5310fd5936f40b94007b4ae6c38f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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.
|
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.
|
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
|
[](https://codeclimate.com/github/dieter-medium/bidi2pdf/maintainability)
|
3
3
|
[](https://badge.fury.io/rb/bidi2pdf)
|
4
4
|
[](https://codeclimate.com/github/dieter-medium/bidi2pdf/test_coverage)
|
5
|
+
[](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
data/docker/Dockerfile.slim
CHANGED
@@ -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
|