bidi2pdf 0.1.4 → 0.1.6
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 +46 -1
- data/README.md +168 -55
- data/docker/Dockerfile +11 -3
- data/docker/Dockerfile.chromedriver +4 -2
- data/docker/Dockerfile.slim +75 -0
- data/lib/bidi2pdf/bidi/browser_tab.rb +47 -7
- data/lib/bidi2pdf/bidi/commands/set_tab_cookie.rb +9 -1
- data/lib/bidi2pdf/bidi/logger_events.rb +86 -0
- data/lib/bidi2pdf/bidi/network_event.rb +25 -7
- data/lib/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rb +109 -0
- data/lib/bidi2pdf/bidi/network_event_formatters/network_event_formatter_utils.rb +53 -0
- data/lib/bidi2pdf/bidi/network_event_formatters/network_event_html_formatter.rb +125 -0
- data/lib/bidi2pdf/bidi/network_event_formatters.rb +11 -0
- data/lib/bidi2pdf/bidi/network_events.rb +24 -5
- data/lib/bidi2pdf/bidi/session.rb +1 -1
- data/lib/bidi2pdf/cli.rb +28 -5
- data/lib/bidi2pdf/dsl.rb +45 -0
- data/lib/bidi2pdf/launcher.rb +7 -3
- data/lib/bidi2pdf/session_runner.rb +21 -4
- data/lib/bidi2pdf/version.rb +1 -1
- data/lib/bidi2pdf.rb +7 -2
- metadata +9 -2
data/lib/bidi2pdf/launcher.rb
CHANGED
@@ -7,9 +7,10 @@ require_relative "bidi/session"
|
|
7
7
|
module Bidi2pdf
|
8
8
|
class Launcher
|
9
9
|
# rubocop:disable Metrics/ParameterLists
|
10
|
-
def initialize(url:, output:, cookies:, headers:, auth:, headless: true, port: 0, wait_window_loaded: false,
|
11
|
-
wait_network_idle: false, print_options: {}, remote_browser_url: nil)
|
10
|
+
def initialize(url:, inputfile:, output:, cookies:, headers:, auth:, headless: true, port: 0, wait_window_loaded: false,
|
11
|
+
wait_network_idle: false, print_options: {}, remote_browser_url: nil, network_log_format: :console)
|
12
12
|
@url = url
|
13
|
+
@inputfile = inputfile
|
13
14
|
@port = port
|
14
15
|
@headless = headless
|
15
16
|
@output = output
|
@@ -22,6 +23,7 @@ module Bidi2pdf
|
|
22
23
|
@print_options = print_options || {}
|
23
24
|
@remote_browser_url = remote_browser_url
|
24
25
|
@custom_session = nil
|
26
|
+
@network_log_format = network_log_format
|
25
27
|
end
|
26
28
|
|
27
29
|
# rubocop:enable Metrics/ParameterLists
|
@@ -30,13 +32,15 @@ module Bidi2pdf
|
|
30
32
|
runner = SessionRunner.new(
|
31
33
|
session: session,
|
32
34
|
url: @url,
|
35
|
+
inputfile: @inputfile,
|
33
36
|
output: @output,
|
34
37
|
cookies: @cookies,
|
35
38
|
headers: @headers,
|
36
39
|
auth: @auth,
|
37
40
|
wait_window_loaded: @wait_window_loaded,
|
38
41
|
wait_network_idle: @wait_network_idle,
|
39
|
-
print_options: @print_options
|
42
|
+
print_options: @print_options,
|
43
|
+
network_log_format: @network_log_format
|
40
44
|
)
|
41
45
|
runner.run
|
42
46
|
end
|
@@ -2,10 +2,12 @@
|
|
2
2
|
|
3
3
|
module Bidi2pdf
|
4
4
|
class SessionRunner
|
5
|
-
|
6
|
-
|
5
|
+
# rubocop: disable Metrics/ParameterLists
|
6
|
+
def initialize(session:, url:, inputfile:, output:, cookies: {}, headers: {}, auth: {}, wait_window_loaded: false,
|
7
|
+
wait_network_idle: false, print_options: {}, network_log_format: :console)
|
7
8
|
@session = session
|
8
9
|
@url = url
|
10
|
+
@inputfile = inputfile
|
9
11
|
@output = output
|
10
12
|
@cookies = cookies || {}
|
11
13
|
@headers = headers || {}
|
@@ -13,8 +15,11 @@ module Bidi2pdf
|
|
13
15
|
@wait_window_loaded = wait_window_loaded
|
14
16
|
@wait_network_idle = wait_network_idle
|
15
17
|
@print_options = print_options || {}
|
18
|
+
@network_log_format = network_log_format
|
16
19
|
end
|
17
20
|
|
21
|
+
# rubocop: enable Metrics/ParameterLists
|
22
|
+
|
18
23
|
def run
|
19
24
|
@session.start
|
20
25
|
@session.client.on_close { Bidi2pdf.logger.info "WebSocket closed" }
|
@@ -71,17 +76,27 @@ module Bidi2pdf
|
|
71
76
|
)
|
72
77
|
end
|
73
78
|
|
79
|
+
# rubocop: disable Metrics/AbcSize
|
74
80
|
def run_flow
|
75
81
|
@session.status
|
76
82
|
@session.user_contexts
|
77
83
|
|
78
|
-
@
|
84
|
+
if @url
|
85
|
+
@tab.navigate_to(@url)
|
86
|
+
else
|
87
|
+
Bidi2pdf.logger.info "Loading HTML file #{@inputfile}"
|
88
|
+
data = File.read(@inputfile)
|
89
|
+
@tab.render_html_content(data)
|
90
|
+
end
|
79
91
|
|
80
92
|
if @wait_network_idle
|
81
93
|
Bidi2pdf.logger.info "Waiting for network idle"
|
82
|
-
@tab.
|
94
|
+
@tab.wait_until_network_idle
|
83
95
|
end
|
84
96
|
|
97
|
+
log_output_file = (@output || "report").sub(/\.pdf$/, "-network.pdf") # only need, when html output
|
98
|
+
@tab.log_network_traffic format: @network_log_format, output: log_output_file
|
99
|
+
|
85
100
|
if @wait_window_loaded
|
86
101
|
Bidi2pdf.logger.info "Waiting for window to be loaded"
|
87
102
|
@tab.execute_script <<-EOF_SCRIPT
|
@@ -95,6 +110,8 @@ module Bidi2pdf
|
|
95
110
|
@window.close
|
96
111
|
end
|
97
112
|
|
113
|
+
# rubocop: enable Metrics/AbcSize
|
114
|
+
|
98
115
|
def uri
|
99
116
|
@uri ||= URI(@url)
|
100
117
|
end
|
data/lib/bidi2pdf/version.rb
CHANGED
data/lib/bidi2pdf.rb
CHANGED
@@ -4,6 +4,7 @@ require_relative "bidi2pdf/utils"
|
|
4
4
|
require_relative "bidi2pdf/process_tree"
|
5
5
|
require_relative "bidi2pdf/launcher"
|
6
6
|
require_relative "bidi2pdf/bidi/session"
|
7
|
+
require_relative "bidi2pdf/dsl"
|
7
8
|
|
8
9
|
require "logger"
|
9
10
|
|
@@ -22,13 +23,17 @@ module Bidi2pdf
|
|
22
23
|
|
23
24
|
class CmdTimeoutError < ClientError; end
|
24
25
|
|
26
|
+
class PrintError < Error; end
|
27
|
+
|
25
28
|
@logger = Logger.new($stdout)
|
26
|
-
@
|
29
|
+
@network_events_logger = Logger.new($stdout)
|
30
|
+
@logger.level = Logger::INFO
|
31
|
+
@network_events_logger.level = Logger::FATAL
|
27
32
|
|
28
33
|
@default_timeout = 60
|
29
34
|
|
30
35
|
class << self
|
31
|
-
attr_accessor :logger, :default_timeout
|
36
|
+
attr_accessor :logger, :default_timeout, :network_events_logger
|
32
37
|
|
33
38
|
# Allow configuration through a block
|
34
39
|
def configure
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bidi2pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dieter S.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-04-
|
11
|
+
date: 2025-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|
@@ -310,6 +310,7 @@ files:
|
|
310
310
|
- cliff.toml
|
311
311
|
- docker/Dockerfile
|
312
312
|
- docker/Dockerfile.chromedriver
|
313
|
+
- docker/Dockerfile.slim
|
313
314
|
- docker/docker-compose.yml
|
314
315
|
- docker/entrypoint.sh
|
315
316
|
- docker/nginx/default.conf
|
@@ -346,13 +347,19 @@ files:
|
|
346
347
|
- lib/bidi2pdf/bidi/connection_manager.rb
|
347
348
|
- lib/bidi2pdf/bidi/event_manager.rb
|
348
349
|
- lib/bidi2pdf/bidi/interceptor.rb
|
350
|
+
- lib/bidi2pdf/bidi/logger_events.rb
|
349
351
|
- lib/bidi2pdf/bidi/network_event.rb
|
352
|
+
- lib/bidi2pdf/bidi/network_event_formatters.rb
|
353
|
+
- lib/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rb
|
354
|
+
- lib/bidi2pdf/bidi/network_event_formatters/network_event_formatter_utils.rb
|
355
|
+
- lib/bidi2pdf/bidi/network_event_formatters/network_event_html_formatter.rb
|
350
356
|
- lib/bidi2pdf/bidi/network_events.rb
|
351
357
|
- lib/bidi2pdf/bidi/session.rb
|
352
358
|
- lib/bidi2pdf/bidi/user_context.rb
|
353
359
|
- lib/bidi2pdf/bidi/web_socket_dispatcher.rb
|
354
360
|
- lib/bidi2pdf/chromedriver_manager.rb
|
355
361
|
- lib/bidi2pdf/cli.rb
|
362
|
+
- lib/bidi2pdf/dsl.rb
|
356
363
|
- lib/bidi2pdf/launcher.rb
|
357
364
|
- lib/bidi2pdf/process_tree.rb
|
358
365
|
- lib/bidi2pdf/session_runner.rb
|