bidi2pdf 0.1.13 → 0.1.14
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 +46 -6
- data/README.md +12 -0
- 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 +52 -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/cli.rb +11 -1
- data/lib/bidi2pdf/launcher.rb +5 -3
- 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 +18 -0
- 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 +2 -0
- 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 +252 -25
- data/sig/bidi2pdf/bidi/client.rbs +95 -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 +54 -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 +57 -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/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 +112 -2
- data/tasks/generate_rbs.rake +11 -11
- metadata +59 -7
- data/sig/bidi2pdf/utils.rbs +0 -5
|
@@ -1,42 +1,269 @@
|
|
|
1
|
+
# Represents a browser tab for managing interactions and communication
|
|
2
|
+
# using the Bidi2pdf library. This class provides methods for creating
|
|
3
|
+
# browser tabs, managing cookies, navigating to URLs, executing scripts,
|
|
4
|
+
# and handling network events.
|
|
5
|
+
#
|
|
6
|
+
# @example Creating a browser tab
|
|
7
|
+
# browser_tab = Bidi2pdf::Bidi::BrowserTab.new(client, browsing_context_id, user_context_id)
|
|
8
|
+
# browser_tab.create_browser_tab
|
|
9
|
+
#
|
|
10
|
+
# @example Navigating to a URL
|
|
11
|
+
# browser_tab.navigate_to("http://example.com")
|
|
12
|
+
#
|
|
13
|
+
# @example Setting a cookie
|
|
14
|
+
# browser_tab.set_cookie(
|
|
15
|
+
# name: "session",
|
|
16
|
+
# value: "abc123",
|
|
17
|
+
# domain: "example.com"
|
|
18
|
+
# )
|
|
19
|
+
#
|
|
20
|
+
# @param [Object] client The WebSocket client for communication.
|
|
21
|
+
# @param [String] browsing_context_id The ID of the browsing context.
|
|
22
|
+
# @param [String] user_context_id The ID of the user context.
|
|
1
23
|
module Bidi2pdf
|
|
2
24
|
module Bidi
|
|
25
|
+
# Represents a browser tab for managing interactions and communication
|
|
26
|
+
# using the Bidi2pdf library. This class provides methods for creating
|
|
27
|
+
# browser tabs, managing cookies, navigating to URLs, executing scripts,
|
|
28
|
+
# handling network events, and general tab lifecycle management.
|
|
29
|
+
#
|
|
3
30
|
class BrowserTab
|
|
4
|
-
@
|
|
5
|
-
@tab_id: String?
|
|
6
|
-
@session_id: String?
|
|
7
|
-
@timeout: Integer
|
|
31
|
+
@client: untyped
|
|
8
32
|
|
|
9
|
-
|
|
10
|
-
attr_reader tab_id: String?
|
|
11
|
-
attr_reader session_id: String?
|
|
33
|
+
@browsing_context_id: untyped
|
|
12
34
|
|
|
13
|
-
|
|
14
|
-
browser: Bidi2pdf::Bidi::Browser,
|
|
15
|
-
?tab_id: String?,
|
|
16
|
-
?timeout: Integer
|
|
17
|
-
) -> void
|
|
35
|
+
@user_context_id: untyped
|
|
18
36
|
|
|
19
|
-
|
|
37
|
+
@tabs: untyped
|
|
20
38
|
|
|
21
|
-
|
|
39
|
+
@network_events: untyped
|
|
22
40
|
|
|
23
|
-
|
|
41
|
+
@logger_events: untyped
|
|
24
42
|
|
|
25
|
-
|
|
26
|
-
selector: String,
|
|
27
|
-
?visible: bool,
|
|
28
|
-
?timeout: Integer
|
|
29
|
-
) -> untyped
|
|
43
|
+
@navigation_failed_events: untyped
|
|
30
44
|
|
|
31
|
-
|
|
45
|
+
@open: untyped
|
|
32
46
|
|
|
33
|
-
|
|
47
|
+
@header_interceptor: untyped
|
|
48
|
+
|
|
49
|
+
@basic_auth_interceptor: untyped
|
|
50
|
+
|
|
51
|
+
@cdp_session: untyped
|
|
52
|
+
|
|
53
|
+
@event_handlers_registered: untyped
|
|
54
|
+
|
|
55
|
+
@listener_refs: untyped
|
|
56
|
+
|
|
57
|
+
include JsLoggerHelper
|
|
58
|
+
|
|
59
|
+
# @return [Object] The WebSocket client.
|
|
60
|
+
attr_reader client: untyped
|
|
61
|
+
|
|
62
|
+
# @return [String] The browsing context ID.
|
|
63
|
+
attr_reader browsing_context_id: untyped
|
|
64
|
+
|
|
65
|
+
# @return [String] The user context ID.
|
|
66
|
+
attr_reader user_context_id: untyped
|
|
67
|
+
|
|
68
|
+
# @return [Array<BrowserTab>] The list of tabs.
|
|
69
|
+
attr_reader tabs: untyped
|
|
70
|
+
|
|
71
|
+
# @return [NetworkEvents] The network events handler.
|
|
72
|
+
attr_reader network_events: untyped
|
|
73
|
+
|
|
74
|
+
# @return [Boolean] Whether the tab is open.
|
|
75
|
+
attr_reader open: untyped
|
|
76
|
+
|
|
77
|
+
# @return [LoggerEvents] The logger events handler.
|
|
78
|
+
attr_reader logger_events: untyped
|
|
79
|
+
|
|
80
|
+
# @return [NavigationFailedEvents] The navigation failed events handler.
|
|
81
|
+
attr_reader navigation_failed_events: untyped
|
|
82
|
+
|
|
83
|
+
# Initializes a new browser tab.
|
|
84
|
+
#
|
|
85
|
+
# @param [Object] client The WebSocket client for communication.
|
|
86
|
+
# @param [String] browsing_context_id The ID of the browsing context.
|
|
87
|
+
# @param [String] user_context_id The ID of the user context.
|
|
88
|
+
def initialize: (untyped client, untyped browsing_context_id, untyped user_context_id) -> void
|
|
89
|
+
|
|
90
|
+
# Creates a new browser tab.
|
|
91
|
+
#
|
|
92
|
+
# @return [BrowserTab] The newly created browser tab.
|
|
93
|
+
def create_browser_tab: () -> untyped
|
|
94
|
+
|
|
95
|
+
# Sets a cookie in the browser tab.
|
|
96
|
+
#
|
|
97
|
+
# @param [String] name The name of the cookie.
|
|
98
|
+
# @param [String] value The value of the cookie.
|
|
99
|
+
# @param [String] domain The domain for the cookie.
|
|
100
|
+
# @param [String] path The path for the cookie. Defaults to "/".
|
|
101
|
+
# @param [Boolean] secure Whether the cookie is secure. Defaults to true.
|
|
102
|
+
# @param [Boolean] http_only Whether the cookie is HTTP-only. Defaults to false.
|
|
103
|
+
# @param [String] same_site The SameSite attribute for the cookie. Defaults to "strict".
|
|
104
|
+
# @param [Integer] ttl The time-to-live for the cookie in seconds. Defaults to 30.
|
|
105
|
+
def set_cookie: (name: untyped, value: untyped, domain: untyped, ?path: ::String, ?secure: bool, ?http_only: bool, ?same_site: ::String, ?ttl: ::Integer) -> untyped
|
|
106
|
+
|
|
107
|
+
# Adds headers to requests in the browser tab.
|
|
108
|
+
#
|
|
109
|
+
# @param [Hash] headers The headers to add.
|
|
110
|
+
# @param [Array<String>] url_patterns The URL patterns to match.
|
|
111
|
+
# @return [AddHeadersInterceptor] The interceptor instance.
|
|
112
|
+
def add_headers: (headers: untyped, url_patterns: untyped) -> untyped
|
|
113
|
+
|
|
114
|
+
# Configures basic authentication for requests in the browser tab.
|
|
115
|
+
#
|
|
116
|
+
# @param [String] username The username for authentication.
|
|
117
|
+
# @param [String] password The password for authentication.
|
|
118
|
+
# @param [Array<String>] url_patterns The URL patterns to match.
|
|
119
|
+
# @return [AuthInterceptor] The interceptor instance.
|
|
120
|
+
def basic_auth: (username: untyped, password: untyped, url_patterns: untyped) -> untyped
|
|
121
|
+
|
|
122
|
+
# Navigates the browser tab to a specified URL.
|
|
123
|
+
#
|
|
124
|
+
# This method registers necessary event listeners and sends a navigation
|
|
125
|
+
# command to the browser tab, instructing it to load the specified URL.
|
|
126
|
+
# It validates that the URL is properly formatted before attempting navigation.
|
|
127
|
+
#
|
|
128
|
+
# @param [String] url The URL to navigate to.
|
|
129
|
+
# @raise [NavigationError] If the URL is invalid or improperly formatted.
|
|
130
|
+
# @example
|
|
131
|
+
# browser_tab.navigate_to("https://example.com")
|
|
132
|
+
def navigate_to: (untyped url, ?wait: ::String) -> untyped
|
|
133
|
+
|
|
134
|
+
# Renders HTML content in the browser tab.
|
|
135
|
+
#
|
|
136
|
+
# @param [String] html_content The HTML content to render.
|
|
137
|
+
# rubocop:disable Metrics/BlockLength
|
|
138
|
+
def render_html_content: (untyped html_content, ?wait: ::String) -> untyped
|
|
139
|
+
|
|
140
|
+
# Executes a script in the browser tab.
|
|
141
|
+
#
|
|
142
|
+
# This method allows you to execute JavaScript code within the context of the browser tab.
|
|
143
|
+
# Optionally, the script can be wrapped in a JavaScript Promise to handle asynchronous operations.
|
|
144
|
+
#
|
|
145
|
+
# @param [String] script The JavaScript code to execute.
|
|
146
|
+
# - This can be any valid JavaScript code that you want to run in the browser tab.
|
|
147
|
+
# @param [Boolean] wrap_in_promise Whether to wrap the script in a Promise. Defaults to false.
|
|
148
|
+
# - If true, the script will be wrapped in a Promise to handle asynchronous execution.
|
|
149
|
+
# - Use this option when the script involves asynchronous operations like network requests.
|
|
150
|
+
# You can use the predefined variable result to store the result of the script.
|
|
151
|
+
# @return [Object] The result of the script execution.
|
|
152
|
+
# - If the script executes successfully, the result of the last evaluated expression is returned.
|
|
153
|
+
# - If the script fails, an error or exception details may be returned.
|
|
154
|
+
def execute_script: (untyped script, ?wrap_in_promise: bool) -> untyped
|
|
155
|
+
|
|
156
|
+
# Injects a JavaScript script element into the page, either from a URL or with inline content.
|
|
157
|
+
#
|
|
158
|
+
# @param [String, nil] url The URL of the script to load (optional).
|
|
159
|
+
# @param [String, nil] content The JavaScript content to inject (optional).
|
|
160
|
+
# @param [String, nil] id The ID attribute for the script element (optional).
|
|
161
|
+
# @return [Object] The result from the script creation promise.
|
|
162
|
+
def inject_script: (?url: untyped?, ?content: untyped?, ?id: untyped?) -> untyped
|
|
163
|
+
|
|
164
|
+
# Injects a CSS style element into the page, either from a URL or with inline content.
|
|
165
|
+
#
|
|
166
|
+
# @param [String, nil] url The URL of the stylesheet to load (optional).
|
|
167
|
+
# @param [String, nil] content The CSS content to inject (optional).
|
|
168
|
+
# @param [String, nil] id The ID attribute for the style element (optional).
|
|
169
|
+
# @return [Object] The result from the style creation promise.
|
|
170
|
+
def inject_style: (?url: untyped?, ?content: untyped?, ?id: untyped?) -> untyped
|
|
171
|
+
|
|
172
|
+
# Waits until the network is idle in the browser tab.
|
|
173
|
+
#
|
|
174
|
+
# @param [Integer] timeout The timeout duration in seconds. Defaults to 10.
|
|
175
|
+
# @param [Float] poll_interval The polling interval in seconds. Defaults to 0.1.
|
|
176
|
+
def wait_until_network_idle: (?timeout: ::Integer, ?poll_interval: ::Float) -> untyped
|
|
177
|
+
|
|
178
|
+
# Waits until the page is fully loaded in the browser tab.
|
|
179
|
+
#
|
|
180
|
+
# This method executes a JavaScript script that checks if the page
|
|
181
|
+
# has finished loading.
|
|
182
|
+
#
|
|
183
|
+
# @param [String] check_script The JavaScript code to check if the page is loaded.
|
|
184
|
+
# - Defaults to a script that polls the `window.loaded` property.
|
|
185
|
+
# @return [Object] The result of the script execution.
|
|
186
|
+
# - If the page is loaded successfully, the Promise resolves with the value `'done'`.
|
|
187
|
+
# - If the script fails, an error or exception details may be returned.
|
|
188
|
+
def wait_until_page_loaded: (?check_script: untyped?) -> untyped
|
|
189
|
+
|
|
190
|
+
# Logs network traffic in the browser tab.
|
|
191
|
+
#
|
|
192
|
+
# @param [Symbol] format The format for logging (:console or :pdf). Defaults to :console.
|
|
193
|
+
# @param [String, nil] output The output file for PDF logging. Defaults to nil.
|
|
194
|
+
# @param [Hash] print_options Options for printing. Defaults to { background: true }.
|
|
195
|
+
# @yield [pdf_base64] A block to handle the PDF content.
|
|
196
|
+
def log_network_traffic: (?format: ::Symbol, ?output: untyped?, ?print_options: ::Hash[untyped, untyped]) { (?) -> untyped } -> (nil | untyped)
|
|
197
|
+
|
|
198
|
+
# Closes the browser tab and its associated resources.
|
|
199
|
+
def close: () -> (nil | untyped)
|
|
200
|
+
|
|
201
|
+
# Prints the content of the browser tab.
|
|
202
|
+
#
|
|
203
|
+
# @param [String, nil] outputfile The output file for the PDF. Defaults to nil.
|
|
204
|
+
# @param [Hash] print_options Options for printing. Defaults to { background: true }.
|
|
205
|
+
# @yield [pdf_base64] A block to handle the PDF content.
|
|
206
|
+
# @return [String, nil] The base64-encoded PDF content, or nil if outputfile or block is provided.
|
|
207
|
+
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
|
|
208
|
+
def print: (?untyped? outputfile, ?print_options: ::Hash[untyped, untyped]) ?{ (?) -> untyped } -> untyped
|
|
209
|
+
|
|
210
|
+
# Captures a screenshot of the browser tab, mirroring #print's own
|
|
211
|
+
# file/block/base64-return trichotomy.
|
|
212
|
+
#
|
|
213
|
+
# @param [String, nil] outputfile The output file for the PNG. Defaults to nil.
|
|
214
|
+
# @param [String] origin "document" (default) or "viewport" - see browsingContext.captureScreenshot.
|
|
215
|
+
# @param [String, nil] format Image format override, e.g. "image/png". Defaults to the browser's own default.
|
|
216
|
+
# @param [Hash, nil] clip A clip rectangle/element, passed through verbatim. Defaults to nil (full capture).
|
|
217
|
+
# @yield [png_base64] A block to handle the PNG content.
|
|
218
|
+
# @return [String, nil] The base64-encoded PNG content, or nil if outputfile or block is provided.
|
|
219
|
+
# rubocop:disable Metrics/AbcSize
|
|
220
|
+
def screenshot: (?untyped? outputfile, ?origin: ::String, ?format: untyped?, ?clip: untyped?) ?{ (?) -> untyped } -> untyped
|
|
221
|
+
|
|
222
|
+
# Sets the browsing context's viewport - makes a headless render deterministic across
|
|
223
|
+
# machines, unlike leaving it at the browser's own default.
|
|
224
|
+
#
|
|
225
|
+
# @param [Integer] width
|
|
226
|
+
# @param [Integer] height
|
|
227
|
+
# @param [Float, nil] device_pixel_ratio Defaults to nil (browser default).
|
|
228
|
+
def set_viewport: (width: untyped, height: untyped, ?device_pixel_ratio: untyped?) -> untyped
|
|
34
229
|
|
|
35
230
|
private
|
|
36
231
|
|
|
37
|
-
def
|
|
232
|
+
def build_command_and_extractor: (untyped print_options) -> ::Array[untyped]
|
|
233
|
+
|
|
234
|
+
def cdp_session: () -> untyped
|
|
235
|
+
|
|
236
|
+
def navigate_with_listeners: (untyped url, ?wait: ::String) -> untyped
|
|
237
|
+
|
|
238
|
+
def register_event_listeners: () -> (nil | untyped)
|
|
239
|
+
|
|
240
|
+
def handle_injection_exception: (untyped response, untyped url, untyped exception_class) -> untyped
|
|
241
|
+
|
|
242
|
+
# Generates JavaScript code for creating a script element with given parameters.
|
|
243
|
+
#
|
|
244
|
+
# @param [String, nil] url The URL of the script to load (optional).
|
|
245
|
+
# @param [String, nil] content The JavaScript content for the script (optional).
|
|
246
|
+
# @param [String, nil] id The ID attribute for the script element (optional).
|
|
247
|
+
# @return [String] JavaScript code that creates a script element.
|
|
248
|
+
def generate_script_element_code: (?url: untyped?, ?content: untyped?, ?id: untyped?) -> ::String
|
|
249
|
+
|
|
250
|
+
# Generates JavaScript code for creating a style element with given parameters.
|
|
251
|
+
#
|
|
252
|
+
# @param [String, nil] url The URL of the stylesheet to load (optional).
|
|
253
|
+
# @param [String, nil] content The CSS content for the style (optional).
|
|
254
|
+
# @param [String, nil] id The ID attribute for the style element (optional).
|
|
255
|
+
# @return [String] JavaScript code that creates a style element.
|
|
256
|
+
def generate_style_element_code: (?url: untyped?, ?content: untyped?, ?id: untyped?) -> ::String
|
|
257
|
+
|
|
258
|
+
# Closes the browsing context.
|
|
259
|
+
def close_context: () -> untyped
|
|
260
|
+
|
|
261
|
+
# Removes event listeners for the browser tab.
|
|
262
|
+
# rubocop:disable Metrics/AbcSize
|
|
263
|
+
def remove_event_listeners: () -> (nil | untyped)
|
|
38
264
|
|
|
39
|
-
|
|
265
|
+
# Closes all tabs associated with the browser tab.
|
|
266
|
+
def close_tabs: () -> untyped
|
|
40
267
|
end
|
|
41
268
|
end
|
|
42
|
-
end
|
|
269
|
+
end
|
|
@@ -1,72 +1,124 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
2
|
module Bidi
|
|
3
|
+
# Represents a WebSocket client for managing communication with a remote server
|
|
4
|
+
# using the Bidi2pdf library. This class handles the setup, connection, and
|
|
5
|
+
# communication with the WebSocket server, including sending commands and
|
|
6
|
+
# handling responses.
|
|
7
|
+
#
|
|
8
|
+
# @example Creating and starting a client
|
|
9
|
+
# client = Bidi2pdf::Bidi::Client.new("ws://example.com/socket")
|
|
10
|
+
# client.start
|
|
11
|
+
#
|
|
12
|
+
# @example Sending a command
|
|
13
|
+
# command = Bidi2pdf::Bidi::Commands::ScriptEvaluate.new context: browsing_context_id, expression: script
|
|
14
|
+
# client.send_cmd(command)
|
|
15
|
+
#
|
|
16
|
+
# @example Subscribing to events
|
|
17
|
+
# client.on_event("eventName") do |event_data|
|
|
18
|
+
# puts "Received event: #{event_data}"
|
|
19
|
+
# end
|
|
20
|
+
#
|
|
21
|
+
# @param [String] ws_url The WebSocket URL to connect to.
|
|
3
22
|
class Client
|
|
4
|
-
@next_id_mutex: Mutex
|
|
5
23
|
@ws_url: untyped
|
|
6
24
|
|
|
7
|
-
@id: untyped
|
|
8
|
-
|
|
9
|
-
@pending_responses: Hash[String, Thread::Queue]
|
|
10
|
-
|
|
11
|
-
@connected: untyped
|
|
12
|
-
|
|
13
|
-
@connection_mutex: Mutex
|
|
14
|
-
|
|
15
|
-
@send_cmd_mutex: Mutex
|
|
16
|
-
|
|
17
|
-
@connection_cv: untyped
|
|
18
|
-
|
|
19
25
|
@started: untyped
|
|
20
26
|
|
|
27
|
+
@connection_manager: untyped
|
|
28
|
+
|
|
21
29
|
@socket: untyped
|
|
22
30
|
|
|
23
31
|
@dispatcher: untyped
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
33
|
+
# @return [String] The WebSocket URL.
|
|
27
34
|
attr_reader ws_url: untyped
|
|
28
35
|
|
|
36
|
+
# Initializes a new WebSocket client.
|
|
37
|
+
#
|
|
38
|
+
# @param [String] ws_url The WebSocket URL to connect to.
|
|
29
39
|
def initialize: (untyped ws_url) -> void
|
|
30
40
|
|
|
41
|
+
# Starts the WebSocket client and establishes a connection.
|
|
42
|
+
#
|
|
43
|
+
# @return [WebSocket::Client::Simple] The WebSocket connection object.
|
|
31
44
|
def start: () -> untyped
|
|
32
45
|
|
|
46
|
+
# Checks if the WebSocket client has started.
|
|
47
|
+
#
|
|
48
|
+
# @return [Boolean] True if the client has started, false otherwise.
|
|
33
49
|
def started?: () -> untyped
|
|
34
50
|
|
|
51
|
+
# Waits until the WebSocket connection is open.
|
|
52
|
+
#
|
|
53
|
+
# @param [Integer] timeout The timeout duration in seconds.
|
|
54
|
+
# @raise [Bidi2pdf::WebsocketError] If the connection is not established within the timeout.
|
|
35
55
|
def wait_until_open: (?timeout: untyped) -> untyped
|
|
36
56
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
def
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def
|
|
57
|
+
# Sends a command to the WebSocket server.
|
|
58
|
+
#
|
|
59
|
+
# @param [Bidi2pdf::Bidi::Commands::Base] cmd The command to send.
|
|
60
|
+
# @raise [Bidi2pdf::ClientError] If the client has not started.
|
|
61
|
+
def send_cmd: (untyped cmd) -> untyped
|
|
62
|
+
|
|
63
|
+
# Sends a command to the WebSocket server and waits for a response.
|
|
64
|
+
#
|
|
65
|
+
# @param [Object] cmd The command to send.
|
|
66
|
+
# @param [Integer] timeout The timeout duration in seconds.
|
|
67
|
+
# @yield [response] A block to handle the response.
|
|
68
|
+
# @raise [Bidi2pdf::ClientError] If the client has not started.
|
|
69
|
+
def send_cmd_and_wait: (untyped cmd, ?timeout: untyped) { (?) -> untyped } -> untyped
|
|
70
|
+
|
|
71
|
+
# Registers a callback for incoming WebSocket messages.
|
|
72
|
+
#
|
|
73
|
+
# @yield [message] A block to handle the incoming message.
|
|
74
|
+
def on_message: () { (?) -> untyped } -> untyped
|
|
75
|
+
|
|
76
|
+
# Registers a callback for when the WebSocket connection is opened.
|
|
77
|
+
#
|
|
78
|
+
# @yield A block to execute when the connection is opened.
|
|
79
|
+
def on_open: () { (?) -> untyped } -> untyped
|
|
80
|
+
|
|
81
|
+
# Registers a callback for when the WebSocket connection is closed.
|
|
82
|
+
#
|
|
83
|
+
# @yield A block to execute when the connection is closed.
|
|
84
|
+
def on_close: () { (?) -> untyped } -> untyped
|
|
85
|
+
|
|
86
|
+
# Registers a callback for WebSocket errors.
|
|
87
|
+
#
|
|
88
|
+
# @yield [error] A block to handle the error.
|
|
89
|
+
def on_error: () { (?) -> untyped } -> untyped
|
|
90
|
+
|
|
91
|
+
# Subscribes to specific WebSocket events.
|
|
92
|
+
#
|
|
93
|
+
# @param [Array<String>] names The names of the events to subscribe to.
|
|
94
|
+
# @yield [event_data] A block to handle the event data.
|
|
95
|
+
def on_event: (*untyped names) { (?) -> untyped } -> untyped
|
|
96
|
+
|
|
97
|
+
# Removes a message listener.
|
|
98
|
+
#
|
|
99
|
+
# @param [Proc] block The listener block to remove.
|
|
100
|
+
def remove_message_listener: (untyped listener) -> untyped
|
|
101
|
+
|
|
102
|
+
# Removes event listeners for specific events.
|
|
103
|
+
#
|
|
104
|
+
# @param [Array<String>] names The names of the events to unsubscribe from.
|
|
105
|
+
# @param [Proc] block The listener block to remove.
|
|
106
|
+
def remove_event_listener: (*untyped names, untyped listener) -> untyped
|
|
107
|
+
|
|
108
|
+
# Closes the WebSocket connection.
|
|
109
|
+
def close: () -> (nil | untyped)
|
|
60
110
|
|
|
61
111
|
private
|
|
62
112
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
113
|
+
# Returns the WebSocket dispatcher for managing events and messages.
|
|
114
|
+
#
|
|
115
|
+
# @return [WebSocketDispatcher] The dispatcher instance.
|
|
116
|
+
def dispatcher: () -> untyped
|
|
66
117
|
|
|
118
|
+
# Handles responses to commands sent to the WebSocket server.
|
|
119
|
+
#
|
|
120
|
+
# @param [Hash] data The response data.
|
|
67
121
|
def handle_response_to_cmd: (untyped data) -> untyped
|
|
68
|
-
|
|
69
|
-
def redact_sensitive_fields: (untyped obj, ?::Array[untyped] sensitive_keys) -> untyped
|
|
70
122
|
end
|
|
71
123
|
end
|
|
72
124
|
end
|
|
@@ -3,39 +3,27 @@ module Bidi2pdf
|
|
|
3
3
|
class CommandManager
|
|
4
4
|
self.@id: untyped
|
|
5
5
|
|
|
6
|
-
self.@id_mutex: untyped
|
|
7
|
-
|
|
8
6
|
@socket: untyped
|
|
9
7
|
|
|
10
|
-
@logger: untyped
|
|
11
|
-
|
|
12
8
|
@pending_responses: untyped
|
|
13
9
|
|
|
14
|
-
@initiated_cmds: untyped
|
|
15
|
-
|
|
16
10
|
def self.initialize_counter: () -> untyped
|
|
17
11
|
|
|
18
12
|
def self.next_id: () -> untyped
|
|
19
13
|
|
|
20
|
-
def initialize: (untyped socket
|
|
14
|
+
def initialize: (untyped socket) -> void
|
|
21
15
|
|
|
22
|
-
def send_cmd: (untyped cmd, ?
|
|
16
|
+
def send_cmd: (untyped cmd, ?result_queue: untyped?) -> untyped
|
|
23
17
|
|
|
24
|
-
def send_cmd_and_wait: (untyped cmd, ?timeout: untyped)
|
|
18
|
+
def send_cmd_and_wait: (untyped cmd, ?timeout: untyped) { (?) -> untyped } -> untyped
|
|
25
19
|
|
|
26
|
-
def
|
|
27
|
-
|
|
28
|
-
def handle_response: (untyped data) -> (true | untyped | false)
|
|
20
|
+
def handle_response: (untyped data) -> untyped
|
|
29
21
|
|
|
30
22
|
private
|
|
31
23
|
|
|
32
|
-
def init_queue_for: (untyped id) -> untyped
|
|
24
|
+
def init_queue_for: (untyped id, untyped result_queue) -> untyped
|
|
33
25
|
|
|
34
26
|
def next_id: () -> untyped
|
|
35
|
-
|
|
36
|
-
def redact_sensitive_fields: (untyped obj, ?::Array[untyped] sensitive_keys) -> untyped
|
|
37
|
-
|
|
38
|
-
def raise_timeout_error: (untyped id, untyped cmd) -> untyped
|
|
39
27
|
end
|
|
40
28
|
end
|
|
41
29
|
end
|
|
@@ -2,19 +2,27 @@ module Bidi2pdf
|
|
|
2
2
|
module Bidi
|
|
3
3
|
module Commands
|
|
4
4
|
class AddIntercept
|
|
5
|
+
@context: untyped
|
|
6
|
+
|
|
7
|
+
@phases: untyped
|
|
8
|
+
|
|
9
|
+
@url_patterns: untyped
|
|
10
|
+
|
|
5
11
|
include Base
|
|
6
12
|
|
|
7
|
-
BEFORE_REQUEST:
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
BEFORE_REQUEST: "beforeRequestSent"
|
|
14
|
+
|
|
15
|
+
RESPONSE_STARTED: "responseStarted"
|
|
16
|
+
|
|
17
|
+
AUTH_REQUIRED: "authRequired"
|
|
18
|
+
|
|
19
|
+
def initialize: (context: untyped, phases: untyped, url_patterns: untyped) -> void
|
|
10
20
|
|
|
11
|
-
|
|
12
|
-
@phases: Array[String]
|
|
13
|
-
@url_patterns: Array[String]
|
|
21
|
+
def method_name: () -> "network.addIntercept"
|
|
14
22
|
|
|
15
|
-
def
|
|
23
|
+
def params: () -> untyped
|
|
16
24
|
|
|
17
|
-
def validate_phases!: () ->
|
|
25
|
+
def validate_phases!: () -> untyped
|
|
18
26
|
end
|
|
19
27
|
end
|
|
20
28
|
end
|
|
@@ -1,26 +1,66 @@
|
|
|
1
1
|
module Bidi2pdf
|
|
2
2
|
module Bidi
|
|
3
3
|
module Commands
|
|
4
|
+
# Base module for defining WebSocket commands in the Bidi2pdf library.
|
|
5
|
+
# This module provides common functionality for creating, comparing, and
|
|
6
|
+
# inspecting WebSocket command payloads.
|
|
4
7
|
module Base
|
|
5
|
-
|
|
8
|
+
# Abstract method that must be implemented in subclasses to define the
|
|
9
|
+
# WebSocket command method name.
|
|
10
|
+
#
|
|
11
|
+
# @raise [NotImplementedError] If the method is not implemented in a subclass.
|
|
12
|
+
def method_name: () -> untyped
|
|
6
13
|
|
|
7
|
-
|
|
14
|
+
# Returns the parameters for the WebSocket command.
|
|
15
|
+
#
|
|
16
|
+
# @return [Hash] The parameters for the command. Defaults to an empty hash.
|
|
17
|
+
def params: () -> ::Hash[untyped, untyped]
|
|
8
18
|
|
|
9
|
-
|
|
19
|
+
# Constructs the payload for the WebSocket command.
|
|
20
|
+
#
|
|
21
|
+
# @param [Integer] id The unique identifier for the command.
|
|
22
|
+
# @return [Hash] The payload containing the command ID, method name, and parameters.
|
|
23
|
+
def as_payload: (untyped id) -> { id: untyped, method: untyped, params: untyped }
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
# Compares the current command with another command for equality.
|
|
26
|
+
#
|
|
27
|
+
# @param [Object] other The other command to compare.
|
|
28
|
+
# @return [Boolean] True if the commands are equal, false otherwise.
|
|
29
|
+
# rubocop: disable Metrics/AbcSize
|
|
30
|
+
def ==: (untyped other) -> (false | untyped)
|
|
12
31
|
|
|
13
|
-
|
|
32
|
+
# Checks if the current command is hash-equal to another command.
|
|
33
|
+
#
|
|
34
|
+
# @param [Object] other The other command to compare.
|
|
35
|
+
# @return [Boolean] True if the commands are hash-equal, false otherwise.
|
|
36
|
+
def eql?: (untyped other) -> (false | untyped)
|
|
14
37
|
|
|
15
|
-
|
|
38
|
+
# Computes the hash value for the command.
|
|
39
|
+
#
|
|
40
|
+
# @return [Integer] The hash value based on the method name and parameters.
|
|
41
|
+
def hash: () -> untyped
|
|
16
42
|
|
|
17
|
-
|
|
43
|
+
# Returns a string representation of the command, with sensitive fields redacted.
|
|
44
|
+
#
|
|
45
|
+
# @return [String] The string representation of the command.
|
|
46
|
+
def inspect: () -> ::String
|
|
18
47
|
|
|
19
48
|
private
|
|
20
49
|
|
|
21
|
-
|
|
50
|
+
# Redacts sensitive fields in a given object.
|
|
51
|
+
#
|
|
52
|
+
# @param [Object] obj The object to redact.
|
|
53
|
+
# @param [Array<String>] sensitive_keys The list of sensitive keys to redact. Defaults to common sensitive keys.
|
|
54
|
+
# @return [Object] The object with sensitive fields redacted.
|
|
55
|
+
def redact_sensitive_fields: (untyped obj, ?::Array[untyped] sensitive_keys) -> untyped
|
|
22
56
|
|
|
23
|
-
|
|
57
|
+
# Logs and raises a timeout error for a command.
|
|
58
|
+
#
|
|
59
|
+
# @param [Integer] id The unique identifier for the command.
|
|
60
|
+
# @param [String] method The method name of the command.
|
|
61
|
+
# @param [Hash] params The parameters of the command.
|
|
62
|
+
# @raise [CmdTimeoutError] If the command times out.
|
|
63
|
+
def raise_timeout_error: (untyped id, untyped method, untyped params) -> untyped
|
|
24
64
|
end
|
|
25
65
|
end
|
|
26
66
|
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Bidi2pdf
|
|
2
|
+
module Bidi
|
|
3
|
+
module Commands
|
|
4
|
+
class BrowserRemoveUserContext
|
|
5
|
+
@user_context_id: untyped
|
|
6
|
+
|
|
7
|
+
include Base
|
|
8
|
+
|
|
9
|
+
attr_reader user_context_id: untyped
|
|
10
|
+
|
|
11
|
+
def initialize: (?user_context_id: untyped?) -> void
|
|
12
|
+
|
|
13
|
+
def params: () -> untyped
|
|
14
|
+
|
|
15
|
+
def method_name: () -> "browser.removeUserContext"
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|