bidi2pdf 0.1.13 → 0.1.15
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/.devcontainer/Dockerfile +53 -0
- data/.devcontainer/devcontainer.json +51 -0
- data/.devcontainer/docker-compose.yml +33 -0
- data/.ruby-gemset +1 -1
- data/.ruby-version +1 -1
- data/CHANGELOG.md +93 -6
- data/README.md +80 -5
- data/docker/Dockerfile +1 -1
- data/docker/Dockerfile.slim +2 -2
- data/docker/chrome-driver/chrome.json +874 -0
- data/lib/bidi2pdf/bidi/browser_tab.rb +97 -4
- data/lib/bidi2pdf/bidi/buffered_web_socket_client.rb +178 -0
- data/lib/bidi2pdf/bidi/client.rb +12 -5
- data/lib/bidi2pdf/bidi/commands/base.rb +2 -0
- data/lib/bidi2pdf/bidi/commands/capture_screenshot.rb +33 -0
- data/lib/bidi2pdf/bidi/commands/set_viewport.rb +32 -0
- data/lib/bidi2pdf/bidi/commands.rb +2 -0
- data/lib/bidi2pdf/bidi/network_event.rb +12 -3
- data/lib/bidi2pdf/bidi/network_events.rb +9 -1
- data/lib/bidi2pdf/bidi/session.rb +1 -1
- data/lib/bidi2pdf/chromedriver_manager.rb +10 -6
- data/lib/bidi2pdf/cli.rb +11 -1
- data/lib/bidi2pdf/launcher.rb +5 -3
- data/lib/bidi2pdf/notifications/logging_subscriber.rb +2 -0
- data/lib/bidi2pdf/session_warmer.rb +377 -0
- data/lib/bidi2pdf/test_helpers/images.rb +8 -0
- data/lib/bidi2pdf/test_helpers/pdf_reader_utils.rb +1 -2
- data/lib/bidi2pdf/test_helpers/pdf_text_sanitizer.rb +1 -2
- data/lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb +1 -1
- data/lib/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rb +22 -2
- data/lib/bidi2pdf/test_helpers/testcontainers/container_endpoint.rb +30 -0
- data/lib/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rb +33 -0
- data/lib/bidi2pdf/test_helpers/testcontainers.rb +1 -0
- data/lib/bidi2pdf/version.rb +1 -1
- data/lib/bidi2pdf.rb +26 -1
- data/sig/bidi2pdf/bidi/add_headers_interceptor.rbs +16 -9
- data/sig/bidi2pdf/bidi/auth_interceptor.rbs +32 -7
- data/sig/bidi2pdf/bidi/browser.rbs +4 -31
- data/sig/bidi2pdf/bidi/browser_console_logger.rbs +59 -0
- data/sig/bidi2pdf/bidi/browser_tab.rbs +269 -25
- data/sig/bidi2pdf/bidi/buffered_web_socket_client.rbs +81 -0
- data/sig/bidi2pdf/bidi/client.rbs +103 -43
- data/sig/bidi2pdf/bidi/command_manager.rbs +5 -17
- data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +16 -8
- data/sig/bidi2pdf/bidi/commands/base.rbs +49 -9
- data/sig/bidi2pdf/bidi/commands/browser_close.rbs +3 -1
- data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +2 -0
- data/sig/bidi2pdf/bidi/commands/browser_remove_user_context.rbs +19 -0
- data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +8 -2
- data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +12 -6
- data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +10 -5
- data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +8 -2
- data/sig/bidi2pdf/bidi/commands/capture_screenshot.rbs +31 -0
- data/sig/bidi2pdf/bidi/commands/cdp_get_session.rbs +17 -0
- data/sig/bidi2pdf/bidi/commands/create_window.rbs +4 -0
- data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +2 -0
- data/sig/bidi2pdf/bidi/commands/network_continue.rbs +4 -0
- data/sig/bidi2pdf/bidi/commands/page_print.rbs +28 -0
- data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +3 -0
- data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +12 -6
- data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +4 -0
- data/sig/bidi2pdf/bidi/commands/session_end.rbs +2 -0
- data/sig/bidi2pdf/bidi/commands/session_status.rbs +3 -1
- data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +4 -0
- data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +51 -23
- data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +17 -19
- data/sig/bidi2pdf/bidi/commands/set_viewport.rbs +31 -0
- data/sig/bidi2pdf/bidi/connection_manager.rbs +2 -1
- data/sig/bidi2pdf/bidi/event_manager.rbs +14 -19
- data/sig/bidi2pdf/bidi/interceptor.rbs +5 -0
- data/sig/bidi2pdf/bidi/js_logger_helper.rbs +9 -0
- data/sig/bidi2pdf/bidi/logger_events.rbs +21 -0
- data/sig/bidi2pdf/bidi/navigation_failed_events.rbs +17 -0
- data/sig/bidi2pdf/bidi/network_event.rbs +64 -46
- data/sig/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rbs +63 -0
- data/sig/bidi2pdf/bidi/network_event_formatters/network_event_formatter_utils.rbs +15 -0
- data/sig/bidi2pdf/bidi/network_event_formatters/network_event_html_formatter.rbs +18 -0
- data/sig/bidi2pdf/bidi/network_event_formatters.rbs +6 -0
- data/sig/bidi2pdf/bidi/network_events.rbs +14 -39
- data/sig/bidi2pdf/bidi/session.rbs +144 -31
- data/sig/bidi2pdf/bidi/user_context.rbs +64 -45
- data/sig/bidi2pdf/bidi/web_socket_dispatcher.rbs +22 -30
- data/sig/bidi2pdf/chromedriver_manager.rbs +61 -22
- data/sig/bidi2pdf/cli.rbs +22 -2
- data/sig/bidi2pdf/dsl.rbs +34 -0
- data/sig/bidi2pdf/launcher.rbs +39 -1
- data/sig/bidi2pdf/notifications/event.rbs +40 -0
- data/sig/bidi2pdf/notifications/instrumenter.rbs +21 -0
- data/sig/bidi2pdf/notifications/logging_subscriber.rbs +41 -0
- data/sig/bidi2pdf/notifications.rbs +24 -0
- data/sig/bidi2pdf/process_tree.rbs +2 -2
- data/sig/bidi2pdf/session_runner.rbs +41 -1
- data/sig/bidi2pdf/session_warmer.rbs +221 -0
- data/sig/bidi2pdf/test_helpers/configuration.rbs +51 -0
- data/sig/bidi2pdf/test_helpers/images/extractor.rbs +43 -0
- data/sig/bidi2pdf/test_helpers/images/image_similarity_checker.rbs +35 -0
- data/sig/bidi2pdf/test_helpers/images/tiff_helper.rbs +70 -0
- data/sig/bidi2pdf/test_helpers/images.rbs +0 -0
- data/sig/bidi2pdf/test_helpers/matchers/contains_pdf_image.rbs +0 -0
- data/sig/bidi2pdf/test_helpers/matchers/contains_pdf_text.rbs +0 -0
- data/sig/bidi2pdf/test_helpers/matchers/have_pdf_page_count.rbs +0 -0
- data/sig/bidi2pdf/test_helpers/matchers/match_pdf_text.rbs +0 -0
- data/sig/bidi2pdf/test_helpers/pdf_file_helper.rbs +23 -0
- data/sig/bidi2pdf/test_helpers/pdf_reader_utils.rbs +49 -0
- data/sig/bidi2pdf/test_helpers/pdf_text_sanitizer.rbs +38 -0
- data/sig/bidi2pdf/test_helpers/spec_paths_helper.rbs +35 -0
- data/sig/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rbs +43 -0
- data/sig/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rbs +45 -0
- data/sig/bidi2pdf/test_helpers/testcontainers/container_endpoint.rbs +25 -0
- data/sig/bidi2pdf/test_helpers/testcontainers/shared_docker_network.rbs +3 -0
- data/sig/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rbs +47 -0
- data/sig/bidi2pdf/test_helpers/testcontainers.rbs +6 -0
- data/sig/bidi2pdf/test_helpers.rbs +0 -0
- data/sig/bidi2pdf/verbose_logger.rbs +37 -0
- data/sig/bidi2pdf/version.rbs +3 -0
- data/sig/bidi2pdf.rbs +130 -2
- data/tasks/generate_rbs.rake +11 -11
- data/tasks/release_credentials_check.rake +97 -0
- metadata +67 -10
- data/sig/bidi2pdf/utils.rbs +0 -5
|
@@ -1,52 +1,165 @@
|
|
|
1
|
+
# Represents a session for managing browser interactions and communication
|
|
2
|
+
# using the Bidi2pdf library. This class handles the setup, configuration,
|
|
3
|
+
# and execution of browser-related workflows, including session creation,
|
|
4
|
+
# WebSocket communication, and browser management.
|
|
5
|
+
#
|
|
6
|
+
# @example Creating and starting a session
|
|
7
|
+
# session = Bidi2pdf::Bidi::Session.new(session_url: "http://example.com/session", headless: true)
|
|
8
|
+
# session.start
|
|
9
|
+
#
|
|
10
|
+
# @example Retrieving user contexts
|
|
11
|
+
# session.user_contexts
|
|
12
|
+
#
|
|
13
|
+
# @example Closing the session
|
|
14
|
+
# session.close
|
|
15
|
+
#
|
|
16
|
+
# @param [String] session_url The URL for the session.
|
|
17
|
+
# @param [Boolean] headless Whether to run the browser in headless mode. Defaults to true.
|
|
18
|
+
# @param [Array<String>] chrome_args Additional Chrome arguments. Defaults to predefined arguments.
|
|
1
19
|
module Bidi2pdf
|
|
2
20
|
module Bidi
|
|
3
21
|
class Session
|
|
4
|
-
@
|
|
5
|
-
@session_id: String?
|
|
6
|
-
@contexts: Array[String]
|
|
7
|
-
@timeout: Integer
|
|
8
|
-
@event_manager: Bidi2pdf::Bidi::EventManager?
|
|
9
|
-
@network_events: Bidi2pdf::Bidi::NetworkEvents?
|
|
22
|
+
@session_uri: untyped
|
|
10
23
|
|
|
11
|
-
|
|
12
|
-
attr_reader session_id: String?
|
|
13
|
-
attr_reader contexts: Array[String]
|
|
24
|
+
@headless: untyped
|
|
14
25
|
|
|
15
|
-
|
|
16
|
-
browser: Bidi2pdf::Bidi::Browser,
|
|
17
|
-
?session_id: String?,
|
|
18
|
-
?timeout: Integer
|
|
19
|
-
) -> void
|
|
26
|
+
@started: untyped
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
@chrome_args: untyped
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
@client: untyped
|
|
24
31
|
|
|
25
|
-
|
|
32
|
+
@browser: untyped
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
@websocket_url: untyped
|
|
28
35
|
|
|
29
|
-
|
|
36
|
+
# Events to subscribe to during the session.
|
|
37
|
+
SUBSCRIBE_EVENTS: ::Array["script"]
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
# Default Chrome arguments for the session.
|
|
40
|
+
DEFAULT_CHROME_ARGS: ::Array["--allow-pre-commit-input" | "--disable-dev-shm-usage" | "--disable-gpu" | "--disable-popup-blocking" | "--disable-hang-monitor" | "--disable-background-networking" | "--disable-background-timer-throttling" | "--disable-client-side-phishing-detection" | "--disable-component-extensions-with-background-pages" | "--disable-crash-reporter" | "--disable-default-apps" | "--disable-infobars" | "--disable-ipc-flooding-protection" | "--disable-prompt-on-repost" | "--disable-renderer-backgrounding" | "--disable-search-engine-choice-screen" | "--disable-sync" | "--enable-automation" | "--export-tagged-pdf" | "--force-color-profile=srgb" | "--generate-pdf-document-outline" | "--metrics-recording-only" | "--no-first-run" | "--password-store=basic" | "--use-mock-keychain" | "--disable-backgrounding-occluded-windows" | "--disable-breakpad" | "--enable-features=PdfOopif" | "--disable-features=Translate,AcceptCHFrame,MediaRouter,OptimizationHints,ProcessPerSiteUpToMainFrameThreshold,IsolateSandboxedIframes" | "--disable-extensions"]
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
# @return [URI] The URI of the session.
|
|
43
|
+
attr_reader session_uri: untyped
|
|
34
44
|
|
|
35
|
-
|
|
45
|
+
# @return [Boolean] Whether the session has started.
|
|
46
|
+
attr_reader started: untyped
|
|
36
47
|
|
|
37
|
-
|
|
48
|
+
# @return [Array<String>] The Chrome arguments for the session.
|
|
49
|
+
attr_reader chrome_args: untyped
|
|
38
50
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
# Initializes a new session.
|
|
52
|
+
#
|
|
53
|
+
# @param [String] session_url The URL for the session.
|
|
54
|
+
# @param [Boolean] headless Whether to run the browser in headless mode. Defaults to true.
|
|
55
|
+
# @param [Array<String>] chrome_args Additional Chrome arguments. Defaults to predefined arguments.
|
|
56
|
+
def initialize: (session_url: untyped, ?headless: bool, ?chrome_args: untyped) -> void
|
|
42
57
|
|
|
43
|
-
|
|
58
|
+
# Starts the session and initializes the client.
|
|
59
|
+
#
|
|
60
|
+
# @raise [StandardError] If an error occurs during session start.
|
|
61
|
+
def start: () -> untyped
|
|
44
62
|
|
|
45
|
-
|
|
63
|
+
# Returns the WebSocket client for the session.
|
|
64
|
+
#
|
|
65
|
+
# @return [Bidi2pdf::Bidi::Client, nil] The WebSocket client, or nil if the session is not started.
|
|
66
|
+
def client: () -> untyped
|
|
67
|
+
|
|
68
|
+
# Returns the browser instance for the session.
|
|
69
|
+
#
|
|
70
|
+
# @return [Bidi2pdf::Bidi::Browser] The browser instance.
|
|
71
|
+
def browser: () -> untyped
|
|
72
|
+
|
|
73
|
+
# Closes the session and cleans up resources.
|
|
74
|
+
# rubocop:disable Metrics/AbcSize
|
|
75
|
+
def close: () -> untyped
|
|
76
|
+
|
|
77
|
+
# Retrieves user contexts for the session.
|
|
78
|
+
def user_contexts: () -> untyped
|
|
46
79
|
|
|
47
|
-
|
|
80
|
+
# Retrieves the status of the session.
|
|
81
|
+
def status: () -> untyped
|
|
82
|
+
|
|
83
|
+
# Checks if the session has started.
|
|
84
|
+
#
|
|
85
|
+
# @return [Boolean] True if the session has started, false otherwise.
|
|
86
|
+
def started?: () -> untyped
|
|
87
|
+
|
|
88
|
+
# Retrieves the WebSocket URL for the session.
|
|
89
|
+
#
|
|
90
|
+
# @return [String] The WebSocket URL.
|
|
91
|
+
def websocket_url: () -> untyped
|
|
92
|
+
|
|
93
|
+
private
|
|
48
94
|
|
|
49
|
-
|
|
95
|
+
# Sends a command to the WebSocket client.
|
|
96
|
+
#
|
|
97
|
+
# @param [Object] command The command to send.
|
|
98
|
+
# @yield [response] A block to handle the response.
|
|
99
|
+
def send_cmd: (untyped command) { (?) -> untyped } -> untyped
|
|
100
|
+
|
|
101
|
+
# Creates a new browser instance.
|
|
102
|
+
#
|
|
103
|
+
# @return [Bidi2pdf::Bidi::Browser] The browser instance.
|
|
104
|
+
# rubocop:disable Metrics/AbcSize
|
|
105
|
+
def create_browser: () -> untyped
|
|
106
|
+
|
|
107
|
+
# Creates a new WebSocket client.
|
|
108
|
+
#
|
|
109
|
+
# @return [Bidi2pdf::Bidi::Client] The WebSocket client.
|
|
110
|
+
def create_client: () -> untyped
|
|
111
|
+
|
|
112
|
+
# Creates a new session and retrieves the WebSocket URL.
|
|
113
|
+
#
|
|
114
|
+
# @return [String] The WebSocket URL.
|
|
115
|
+
def create_new_session: () -> untyped
|
|
116
|
+
|
|
117
|
+
# Builds the session request payload.
|
|
118
|
+
#
|
|
119
|
+
# @return [Hash] The session request payload.
|
|
120
|
+
def session_request: () -> { "capabilities" => { "alwaysMatch" => { "browserName" => "chrome", "goog:chromeOptions" => { "args" => untyped }, "goog:prerenderingDisabled" => true, "unhandledPromptBehavior" => { default: "ignore" }, "acceptInsecureCerts" => true, "webSocketUrl" => true } } }
|
|
121
|
+
|
|
122
|
+
# Executes an API call with the given payload.
|
|
123
|
+
#
|
|
124
|
+
# @param [Hash] payload The payload for the API call.
|
|
125
|
+
# @return [Hash] The parsed response data.
|
|
126
|
+
def exec_api_call: (untyped payload) -> untyped
|
|
127
|
+
|
|
128
|
+
# Logs an API error.
|
|
129
|
+
#
|
|
130
|
+
# @param [String] message The error message.
|
|
131
|
+
# @param [Integer] code The response code.
|
|
132
|
+
# @param [String] body The response body.
|
|
133
|
+
def log_api_error: (untyped message, untyped code, untyped body) -> untyped
|
|
134
|
+
|
|
135
|
+
# Determines the error category based on the exception.
|
|
136
|
+
#
|
|
137
|
+
# @param [Exception] exception The exception to categorize.
|
|
138
|
+
# @return [String] The error category.
|
|
139
|
+
def error_category: (untyped exception) -> untyped
|
|
140
|
+
|
|
141
|
+
# Retrieves the error description for a given error type.
|
|
142
|
+
#
|
|
143
|
+
# @param [String] type The error type.
|
|
144
|
+
# @return [String] The error description.
|
|
145
|
+
def error_description: (untyped type) -> untyped
|
|
146
|
+
|
|
147
|
+
# Builds an error response.
|
|
148
|
+
#
|
|
149
|
+
# @param [String] error The error type.
|
|
150
|
+
# @param [String] message The error message.
|
|
151
|
+
# @param [Array<String>, nil] backtrace The error backtrace.
|
|
152
|
+
# @return [Hash] The error response.
|
|
153
|
+
def build_error: (untyped error, untyped message, ?untyped? backtrace) -> { "value" => untyped }
|
|
154
|
+
|
|
155
|
+
# Handles an error response from the session.
|
|
156
|
+
#
|
|
157
|
+
# @param [Hash] value The error response value.
|
|
158
|
+
# @raise [SessionNotStartedError] If the session could not be started.
|
|
159
|
+
def handle_error: (untyped value) -> (nil | untyped)
|
|
160
|
+
|
|
161
|
+
# Cleans up resources associated with the session.
|
|
162
|
+
def cleanup: () -> untyped
|
|
50
163
|
end
|
|
51
164
|
end
|
|
52
|
-
end
|
|
165
|
+
end
|
|
@@ -1,50 +1,69 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
2
|
module Bidi
|
|
3
|
+
# Represents a user context for managing browser interactions and cookies
|
|
4
|
+
# using the Bidi2pdf library. This class provides methods for creating
|
|
5
|
+
# user contexts, setting cookies, and creating browser windows.
|
|
6
|
+
#
|
|
7
|
+
# @example Creating a user context
|
|
8
|
+
# user_context = Bidi2pdf::Bidi::UserContext.new(client)
|
|
9
|
+
#
|
|
10
|
+
# @example Setting a cookie
|
|
11
|
+
# user_context.set_cookie(
|
|
12
|
+
# name: "session",
|
|
13
|
+
# value: "abc123",
|
|
14
|
+
# domain: "example.com",
|
|
15
|
+
# source_origin: "http://example.com"
|
|
16
|
+
# )
|
|
17
|
+
#
|
|
18
|
+
# @example Creating a browser window
|
|
19
|
+
# browser_window = user_context.create_browser_window
|
|
20
|
+
#
|
|
21
|
+
# @param [Object] client The WebSocket client for communication.
|
|
3
22
|
class UserContext
|
|
4
|
-
@
|
|
5
|
-
|
|
6
|
-
@
|
|
7
|
-
|
|
8
|
-
@
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
def
|
|
23
|
+
@client: untyped
|
|
24
|
+
|
|
25
|
+
@context_id: untyped
|
|
26
|
+
|
|
27
|
+
# @return [Object] The WebSocket client.
|
|
28
|
+
attr_reader client: untyped
|
|
29
|
+
|
|
30
|
+
# Initializes a new user context.
|
|
31
|
+
#
|
|
32
|
+
# @param [Object] client The WebSocket client for communication.
|
|
33
|
+
def initialize: (untyped client) -> void
|
|
34
|
+
|
|
35
|
+
# Retrieves the user context ID, creating it if it does not exist.
|
|
36
|
+
#
|
|
37
|
+
# @return [String] The user context ID.
|
|
38
|
+
# @raise [RuntimeError] If an error occurs while creating the user context.
|
|
39
|
+
def context_id: () -> untyped
|
|
40
|
+
|
|
41
|
+
# Sets a cookie in the user context.
|
|
42
|
+
#
|
|
43
|
+
# @param [String] name The name of the cookie.
|
|
44
|
+
# @param [String] value The value of the cookie.
|
|
45
|
+
# @param [String] domain The domain for the cookie.
|
|
46
|
+
# @param [String] source_origin The source origin for the cookie.
|
|
47
|
+
# @param [String] path The path for the cookie. Defaults to "/".
|
|
48
|
+
# @param [Boolean] secure Whether the cookie is secure. Defaults to true.
|
|
49
|
+
# @param [Boolean] http_only Whether the cookie is HTTP-only. Defaults to false.
|
|
50
|
+
# @param [String] same_site The SameSite attribute for the cookie. Defaults to "strict".
|
|
51
|
+
# @param [Integer] ttl The time-to-live for the cookie in seconds. Defaults to 30.
|
|
52
|
+
def set_cookie: (name: untyped, value: untyped, domain: untyped, source_origin: untyped, ?path: ::String, ?secure: bool, ?http_only: bool, ?same_site: ::String, ?ttl: ::Integer) -> untyped
|
|
53
|
+
|
|
54
|
+
# Creates a new browser window in the user context.
|
|
55
|
+
#
|
|
56
|
+
# @return [BrowserTab] The newly created browser tab.
|
|
57
|
+
def create_browser_window: () -> untyped
|
|
58
|
+
|
|
59
|
+
# Closes the user context.
|
|
60
|
+
#
|
|
61
|
+
# This method removes the user context from the browser, effectively cleaning up
|
|
62
|
+
# any associated resources. If the user context does not exist, the method does nothing.
|
|
63
|
+
#
|
|
64
|
+
# @return [nil]
|
|
65
|
+
# @raise [RuntimeError] If an error occurs while removing the user context.
|
|
66
|
+
def close: () -> (nil | untyped)
|
|
48
67
|
end
|
|
49
68
|
end
|
|
50
|
-
end
|
|
69
|
+
end
|
|
@@ -1,53 +1,45 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
2
|
module Bidi
|
|
3
3
|
class WebSocketDispatcher
|
|
4
|
-
@
|
|
5
|
-
@socket: WebSocket::Driver
|
|
6
|
-
@connection: TCPSocket
|
|
7
|
-
@pending_requests: Hash[Integer, Concurrent::Promises::ResolvableFuture]
|
|
8
|
-
@message_id: Integer
|
|
9
|
-
@listeners: Hash[String, Array[Proc]]
|
|
10
|
-
@thread: Thread?
|
|
11
|
-
@mutex: Mutex
|
|
12
|
-
@connected: bool
|
|
13
|
-
@logger: Logger?
|
|
4
|
+
@socket: untyped
|
|
14
5
|
|
|
15
|
-
|
|
16
|
-
attr_reader connected: bool
|
|
6
|
+
@socket_events: untyped
|
|
17
7
|
|
|
18
|
-
|
|
8
|
+
@session_events: untyped
|
|
19
9
|
|
|
20
|
-
|
|
10
|
+
attr_reader socket_events: untyped
|
|
21
11
|
|
|
22
|
-
|
|
12
|
+
attr_reader session_events: untyped
|
|
23
13
|
|
|
24
|
-
def
|
|
14
|
+
def initialize: (untyped socket) -> void
|
|
25
15
|
|
|
26
|
-
def
|
|
16
|
+
def start_listening: () -> untyped
|
|
27
17
|
|
|
28
|
-
def
|
|
18
|
+
def on_message: () { (?) -> untyped } -> untyped
|
|
29
19
|
|
|
30
|
-
def
|
|
20
|
+
def on_event: (*untyped event_names) { (?) -> untyped } -> untyped
|
|
31
21
|
|
|
32
|
-
def
|
|
22
|
+
def on_open: () { (?) -> untyped } -> untyped
|
|
33
23
|
|
|
34
|
-
|
|
24
|
+
def on_close: () { (?) -> untyped } -> untyped
|
|
25
|
+
|
|
26
|
+
def on_error: () { (?) -> untyped } -> untyped
|
|
35
27
|
|
|
36
|
-
def
|
|
28
|
+
def remove_message_listener: (untyped block) -> untyped
|
|
37
29
|
|
|
38
|
-
def
|
|
30
|
+
def remove_event_listener: (untyped name, untyped listener) -> untyped
|
|
39
31
|
|
|
40
|
-
def
|
|
32
|
+
def remove_open_listener: (untyped listener) -> untyped
|
|
41
33
|
|
|
42
|
-
def
|
|
34
|
+
def remove_close_listener: (untyped listener) -> untyped
|
|
43
35
|
|
|
44
|
-
def
|
|
36
|
+
def remove_error_listener: (untyped listener) -> untyped
|
|
45
37
|
|
|
46
|
-
|
|
38
|
+
private
|
|
47
39
|
|
|
48
|
-
def
|
|
40
|
+
def setup_message_handler: () -> untyped
|
|
49
41
|
|
|
50
|
-
def
|
|
42
|
+
def setup_connection_lifecycle_handlers: () -> untyped
|
|
51
43
|
end
|
|
52
44
|
end
|
|
53
|
-
end
|
|
45
|
+
end
|
|
@@ -1,42 +1,81 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
2
|
class ChromedriverManager
|
|
3
|
-
@port:
|
|
4
|
-
|
|
3
|
+
@port: untyped
|
|
4
|
+
|
|
5
|
+
@headless: untyped
|
|
6
|
+
|
|
5
7
|
@session: untyped
|
|
6
|
-
@pid: Integer?
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
@started: untyped
|
|
10
|
+
|
|
11
|
+
@chrome_args: untyped
|
|
12
|
+
|
|
13
|
+
@shutdown_mutex: untyped
|
|
14
|
+
|
|
15
|
+
@pid: untyped
|
|
16
|
+
|
|
17
|
+
include Chromedriver::Binary::Platform
|
|
18
|
+
|
|
19
|
+
attr_reader port: untyped
|
|
20
|
+
|
|
21
|
+
attr_reader pid: untyped
|
|
22
|
+
|
|
23
|
+
attr_reader started: untyped
|
|
24
|
+
|
|
25
|
+
attr_reader headless: untyped
|
|
11
26
|
|
|
12
|
-
|
|
27
|
+
attr_reader chrome_args: untyped
|
|
13
28
|
|
|
14
|
-
|
|
29
|
+
attr_reader shutdown_mutex: untyped
|
|
15
30
|
|
|
16
|
-
|
|
31
|
+
attr_accessor reader_thread: untyped
|
|
32
|
+
|
|
33
|
+
def initialize: (?port: ::Integer, ?headless: bool, ?chrome_args: untyped) -> void
|
|
34
|
+
|
|
35
|
+
def start: () -> untyped
|
|
36
|
+
|
|
37
|
+
def session: () -> (nil | untyped)
|
|
38
|
+
|
|
39
|
+
def session_url: () -> (nil | ::String)
|
|
40
|
+
|
|
41
|
+
# rubocop: disable Metrics/AbcSize
|
|
42
|
+
def stop: (?timeout: ::Integer) -> untyped
|
|
17
43
|
|
|
18
44
|
private
|
|
19
45
|
|
|
20
|
-
|
|
21
|
-
|
|
46
|
+
def spawn_process: (untyped cmd) -> untyped
|
|
47
|
+
|
|
48
|
+
def detect_zombie_processes: (untyped old_childprocesses) -> (nil | untyped)
|
|
49
|
+
|
|
50
|
+
def term_zombie_processes: (untyped zombie_processes) -> untyped
|
|
51
|
+
|
|
52
|
+
def debug_show_all_children: () -> untyped
|
|
53
|
+
|
|
54
|
+
def close_session: () -> untyped
|
|
55
|
+
|
|
56
|
+
def term_chromedriver: () -> untyped
|
|
22
57
|
|
|
23
|
-
def
|
|
58
|
+
def kill_chromedriver: (?timeout: ::Integer) -> untyped
|
|
24
59
|
|
|
25
|
-
def
|
|
60
|
+
def build_cmd: () -> untyped
|
|
26
61
|
|
|
27
|
-
|
|
62
|
+
# Chromedriver's own internal log verbosity is independent from this app's - defaults to
|
|
63
|
+
# mirroring Bidi2pdf.logger.level for backward compatibility, but Bidi2pdf.chromedriver_log_level
|
|
64
|
+
# lets a consumer quiet chromedriver's own (often much more verbose, e.g. full BiDi command/
|
|
65
|
+
# response dumps at its own INFO level) output without changing their app's own log level.
|
|
66
|
+
def chromedriver_log_level: () -> untyped
|
|
28
67
|
|
|
29
|
-
def
|
|
68
|
+
def user_data_dir_arg: () -> (untyped | ::String)
|
|
30
69
|
|
|
31
|
-
def
|
|
70
|
+
def process_chrome_args: () -> (::Array[untyped] | untyped)
|
|
32
71
|
|
|
33
|
-
def update_chromedriver: () ->
|
|
72
|
+
def update_chromedriver: () -> untyped
|
|
34
73
|
|
|
35
|
-
# rubocop:disable Metrics/AbcSize
|
|
36
|
-
def parse_port_from_output: (
|
|
74
|
+
# rubocop: disable Metrics/AbcSize
|
|
75
|
+
def parse_port_from_output: (untyped io, ?timeout: ::Integer) -> (nil | untyped)
|
|
37
76
|
|
|
38
|
-
def process_alive?: (?pid
|
|
77
|
+
def process_alive?: (?untyped pid) -> (false | untyped)
|
|
39
78
|
|
|
40
|
-
def wait_until_chromedriver_ready: (?timeout: Integer) ->
|
|
79
|
+
def wait_until_chromedriver_ready: (?timeout: ::Integer) -> (true | untyped)
|
|
41
80
|
end
|
|
42
|
-
end
|
|
81
|
+
end
|
data/sig/bidi2pdf/cli.rbs
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
|
+
# rubocop:disable Metrics/AbcSize
|
|
2
3
|
class CLI < Thor
|
|
3
|
-
# rubocop:disable Layout/BeginEndAlignment
|
|
4
4
|
@launcher: untyped
|
|
5
5
|
|
|
6
|
+
def self.exit_on_failure?: () -> true
|
|
7
|
+
|
|
6
8
|
def render: () -> untyped
|
|
7
9
|
|
|
10
|
+
def version: () -> untyped
|
|
11
|
+
|
|
12
|
+
def template: () -> untyped
|
|
13
|
+
|
|
8
14
|
private
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
def load_config: () -> (nil | untyped)
|
|
17
|
+
|
|
18
|
+
def validate_required_options!: () -> (untyped | untyped | nil)
|
|
19
|
+
|
|
20
|
+
def validate_print_options: (untyped opts) -> untyped
|
|
21
|
+
|
|
22
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
23
|
+
def print_options: () -> untyped
|
|
24
|
+
|
|
25
|
+
def option_provided?: (untyped key) -> untyped
|
|
26
|
+
|
|
27
|
+
def assign_if_provided: (untyped hash, untyped key, ?untyped option_key) -> (untyped | nil)
|
|
28
|
+
|
|
11
29
|
def launcher: () -> untyped
|
|
12
30
|
|
|
13
31
|
def configure: () -> untyped
|
|
@@ -17,5 +35,7 @@ module Bidi2pdf
|
|
|
17
35
|
def parse_key_values: (untyped pairs) -> untyped
|
|
18
36
|
|
|
19
37
|
def parse_auth: (untyped auth_string) -> ::Array[untyped]
|
|
38
|
+
|
|
39
|
+
def merged_options: () -> untyped
|
|
20
40
|
end
|
|
21
41
|
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module Bidi2pdf
|
|
2
|
+
module DSL
|
|
3
|
+
# rubocop: disable Metrics/AbcSize
|
|
4
|
+
#
|
|
5
|
+
# Executes a block of code within the context of a browser tab.
|
|
6
|
+
#
|
|
7
|
+
# This method handles the setup and teardown of a browser session, user context,
|
|
8
|
+
# browser window, and tab. It ensures that resources are properly cleaned up
|
|
9
|
+
# after the block is executed.
|
|
10
|
+
#
|
|
11
|
+
# @param [String, nil] remote_browser_url The URL of a remote browser to connect to.
|
|
12
|
+
# If provided, the session will connect to this browser in headless mode.
|
|
13
|
+
# @param [Integer] port The port to use for the local browser session. Defaults to 0 (chooses a random port).
|
|
14
|
+
# @param [Boolean] headless Whether to run the browser in headless mode. Defaults to true.
|
|
15
|
+
# @param [Array<String>] chrome_args Additional arguments to pass to the Chrome browser.
|
|
16
|
+
# Defaults to the `DEFAULT_CHROME_ARGS` from the `Bidi2pdf::Bidi::Session` class.
|
|
17
|
+
#
|
|
18
|
+
# @yield [tab] The browser tab created within the session.
|
|
19
|
+
# @yieldparam [Object] tab The browser tab object.
|
|
20
|
+
#
|
|
21
|
+
# @example Using a local browser session
|
|
22
|
+
# Bidi2pdf::DSL.with_tab(port: 9222, headless: false) do |tab|
|
|
23
|
+
# # Perform actions with the tab
|
|
24
|
+
# end
|
|
25
|
+
#
|
|
26
|
+
# @example Using a remote browser session
|
|
27
|
+
# Bidi2pdf::DSL.with_tab(remote_browser_url: "http://remote-browser:9222/session") do |tab|
|
|
28
|
+
# # Perform actions with the tab
|
|
29
|
+
# end
|
|
30
|
+
#
|
|
31
|
+
# @return [void]
|
|
32
|
+
def self.with_tab: (?remote_browser_url: untyped?, ?port: ::Integer, ?headless: bool, ?chrome_args: untyped) { (untyped) -> untyped } -> untyped
|
|
33
|
+
end
|
|
34
|
+
end
|
data/sig/bidi2pdf/launcher.rbs
CHANGED
|
@@ -1,7 +1,39 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
|
+
# Represents a launcher for managing browser sessions and executing tasks
|
|
3
|
+
# using the Bidi2pdf library. This class handles the setup and teardown
|
|
4
|
+
# of browser sessions, as well as the execution of tasks within those sessions.
|
|
5
|
+
#
|
|
6
|
+
# @example Launching a session
|
|
7
|
+
# launcher = Bidi2pdf::Launcher.new(
|
|
8
|
+
# url: "http://example.com",
|
|
9
|
+
# inputfile: "input.pdf",
|
|
10
|
+
# output: "output.pdf",
|
|
11
|
+
# cookies: [],
|
|
12
|
+
# headers: {},
|
|
13
|
+
# auth: nil,
|
|
14
|
+
# headless: true
|
|
15
|
+
# )
|
|
16
|
+
# launcher.launch
|
|
17
|
+
# launcher.stop
|
|
18
|
+
#
|
|
19
|
+
# @param [String] url The URL to navigate to in the browser session.
|
|
20
|
+
# @param [String] inputfile The path to the input file to be processed.
|
|
21
|
+
# @param [String] output The path to the output file to be generated.
|
|
22
|
+
# @param [Array<Hash>] cookies An array of cookies to set in the browser session.
|
|
23
|
+
# @param [Hash] headers A hash of HTTP headers to include in the browser session.
|
|
24
|
+
# @param [Hash, nil] auth Authentication credentials (e.g., username and password).
|
|
25
|
+
# @param [Boolean] headless Whether to run the browser in headless mode. Defaults to true.
|
|
26
|
+
# @param [Integer] port The port to use for the browser session. Defaults to 0.
|
|
27
|
+
# @param [Boolean] wait_window_loaded Whether to wait for the window to fully load. Defaults to false.
|
|
28
|
+
# @param [Boolean] wait_network_idle Whether to wait for the network to become idle. Defaults to false.
|
|
29
|
+
# @param [Hash] print_options Options for printing the page. Defaults to an empty hash.
|
|
30
|
+
# @param [String, nil] remote_browser_url The URL of a remote browser to connect to. Defaults to nil.
|
|
31
|
+
# @param [Symbol] network_log_format The format for network logs. Defaults to :console.
|
|
2
32
|
class Launcher
|
|
3
33
|
@url: untyped
|
|
4
34
|
|
|
35
|
+
@inputfile: untyped
|
|
36
|
+
|
|
5
37
|
@port: untyped
|
|
6
38
|
|
|
7
39
|
@headless: untyped
|
|
@@ -24,8 +56,14 @@ module Bidi2pdf
|
|
|
24
56
|
|
|
25
57
|
@remote_browser_url: untyped
|
|
26
58
|
|
|
59
|
+
@custom_session: untyped
|
|
60
|
+
|
|
61
|
+
@network_log_format: untyped
|
|
62
|
+
|
|
63
|
+
@chrome_args: untyped
|
|
64
|
+
|
|
27
65
|
# rubocop:disable Metrics/ParameterLists
|
|
28
|
-
def initialize: (url: untyped, output: untyped, cookies: untyped, headers: untyped, auth: untyped, ?headless: bool, ?port: ::Integer, ?wait_window_loaded: bool, ?wait_network_idle: bool, ?print_options: ::Hash[untyped, untyped], ?remote_browser_url: untyped?) -> void
|
|
66
|
+
def initialize: (url: untyped, inputfile: untyped, output: untyped, cookies: untyped, headers: untyped, auth: untyped, ?headless: bool, ?port: ::Integer, ?wait_window_loaded: bool, ?wait_network_idle: bool, ?print_options: ::Hash[untyped, untyped], ?remote_browser_url: untyped?, ?network_log_format: ::Symbol, ?chrome_args: untyped) -> void
|
|
29
67
|
|
|
30
68
|
def launch: () -> untyped
|
|
31
69
|
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
module Bidi2pdf
|
|
2
|
+
# rubocop: disable Lint/RescueException
|
|
3
|
+
module Notifications
|
|
4
|
+
class Event
|
|
5
|
+
@name: untyped
|
|
6
|
+
|
|
7
|
+
@payload: untyped
|
|
8
|
+
|
|
9
|
+
@time: untyped
|
|
10
|
+
|
|
11
|
+
@transaction_id: untyped
|
|
12
|
+
|
|
13
|
+
@end: untyped
|
|
14
|
+
|
|
15
|
+
attr_reader name: untyped
|
|
16
|
+
|
|
17
|
+
attr_reader transaction_id: untyped
|
|
18
|
+
|
|
19
|
+
attr_accessor payload: untyped
|
|
20
|
+
|
|
21
|
+
def initialize: (untyped name, untyped start, untyped ending, untyped transaction_id, untyped payload) -> void
|
|
22
|
+
|
|
23
|
+
def record: () ?{ (untyped) -> untyped } -> untyped
|
|
24
|
+
|
|
25
|
+
def start!: () -> untyped
|
|
26
|
+
|
|
27
|
+
def finish!: () -> untyped
|
|
28
|
+
|
|
29
|
+
def duration: () -> untyped
|
|
30
|
+
|
|
31
|
+
def time: () -> (untyped | nil)
|
|
32
|
+
|
|
33
|
+
def end: () -> (untyped | nil)
|
|
34
|
+
|
|
35
|
+
private
|
|
36
|
+
|
|
37
|
+
def now: () -> untyped
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|