bidi2pdf 0.1.12 → 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.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/.devcontainer/Dockerfile +53 -0
  3. data/.devcontainer/devcontainer.json +51 -0
  4. data/.devcontainer/docker-compose.yml +33 -0
  5. data/.rubocop.yml +1 -1
  6. data/.ruby-gemset +1 -1
  7. data/.ruby-version +1 -1
  8. data/CHANGELOG.md +115 -4
  9. data/README.md +12 -0
  10. data/docker/Dockerfile +2 -2
  11. data/docker/Dockerfile.slim +2 -2
  12. data/docker/chrome-driver/chrome.json +874 -0
  13. data/docker/entrypoint.sh +3 -3
  14. data/lib/bidi2pdf/bidi/browser_tab.rb +52 -0
  15. data/lib/bidi2pdf/bidi/commands/capture_screenshot.rb +33 -0
  16. data/lib/bidi2pdf/bidi/commands/set_viewport.rb +32 -0
  17. data/lib/bidi2pdf/bidi/commands.rb +2 -0
  18. data/lib/bidi2pdf/bidi/event_manager.rb +2 -2
  19. data/lib/bidi2pdf/chromedriver_manager.rb +11 -0
  20. data/lib/bidi2pdf/cli.rb +11 -1
  21. data/lib/bidi2pdf/launcher.rb +5 -3
  22. data/lib/bidi2pdf/process_tree.rb +2 -2
  23. data/lib/bidi2pdf/test_helpers/images.rb +8 -0
  24. data/lib/bidi2pdf/test_helpers/pdf_file_helper.rb +5 -1
  25. data/lib/bidi2pdf/test_helpers/pdf_reader_utils.rb +1 -2
  26. data/lib/bidi2pdf/test_helpers/pdf_text_sanitizer.rb +29 -109
  27. data/lib/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rb +1 -1
  28. data/lib/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rb +46 -13
  29. data/lib/bidi2pdf/test_helpers/testcontainers/container_endpoint.rb +30 -0
  30. data/lib/bidi2pdf/test_helpers/testcontainers/shared_docker_network.rb +5 -1
  31. data/lib/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rb +33 -0
  32. data/lib/bidi2pdf/test_helpers/testcontainers.rb +1 -0
  33. data/lib/bidi2pdf/version.rb +1 -1
  34. data/lib/bidi2pdf.rb +2 -0
  35. data/sig/bidi2pdf/bidi/add_headers_interceptor.rbs +16 -9
  36. data/sig/bidi2pdf/bidi/auth_interceptor.rbs +32 -7
  37. data/sig/bidi2pdf/bidi/browser.rbs +4 -31
  38. data/sig/bidi2pdf/bidi/browser_console_logger.rbs +59 -0
  39. data/sig/bidi2pdf/bidi/browser_tab.rbs +252 -25
  40. data/sig/bidi2pdf/bidi/client.rbs +95 -43
  41. data/sig/bidi2pdf/bidi/command_manager.rbs +5 -17
  42. data/sig/bidi2pdf/bidi/commands/add_intercept.rbs +16 -8
  43. data/sig/bidi2pdf/bidi/commands/base.rbs +49 -9
  44. data/sig/bidi2pdf/bidi/commands/browser_close.rbs +3 -1
  45. data/sig/bidi2pdf/bidi/commands/browser_create_user_context.rbs +2 -0
  46. data/sig/bidi2pdf/bidi/commands/browser_remove_user_context.rbs +19 -0
  47. data/sig/bidi2pdf/bidi/commands/browsing_context_close.rbs +8 -2
  48. data/sig/bidi2pdf/bidi/commands/browsing_context_navigate.rbs +12 -6
  49. data/sig/bidi2pdf/bidi/commands/browsing_context_print.rbs +10 -5
  50. data/sig/bidi2pdf/bidi/commands/cancel_auth.rbs +8 -2
  51. data/sig/bidi2pdf/bidi/commands/capture_screenshot.rbs +31 -0
  52. data/sig/bidi2pdf/bidi/commands/cdp_get_session.rbs +17 -0
  53. data/sig/bidi2pdf/bidi/commands/create_window.rbs +4 -0
  54. data/sig/bidi2pdf/bidi/commands/get_user_contexts.rbs +2 -0
  55. data/sig/bidi2pdf/bidi/commands/network_continue.rbs +4 -0
  56. data/sig/bidi2pdf/bidi/commands/page_print.rbs +28 -0
  57. data/sig/bidi2pdf/bidi/commands/print_parameters_validator.rbs +3 -0
  58. data/sig/bidi2pdf/bidi/commands/provide_credentials.rbs +12 -6
  59. data/sig/bidi2pdf/bidi/commands/script_evaluate.rbs +4 -0
  60. data/sig/bidi2pdf/bidi/commands/session_end.rbs +2 -0
  61. data/sig/bidi2pdf/bidi/commands/session_status.rbs +3 -1
  62. data/sig/bidi2pdf/bidi/commands/session_subscribe.rbs +4 -0
  63. data/sig/bidi2pdf/bidi/commands/set_tab_cookie.rbs +51 -23
  64. data/sig/bidi2pdf/bidi/commands/set_usercontext_cookie.rbs +17 -19
  65. data/sig/bidi2pdf/bidi/commands/set_viewport.rbs +31 -0
  66. data/sig/bidi2pdf/bidi/connection_manager.rbs +2 -1
  67. data/sig/bidi2pdf/bidi/event_manager.rbs +14 -19
  68. data/sig/bidi2pdf/bidi/interceptor.rbs +5 -0
  69. data/sig/bidi2pdf/bidi/js_logger_helper.rbs +9 -0
  70. data/sig/bidi2pdf/bidi/logger_events.rbs +21 -0
  71. data/sig/bidi2pdf/bidi/navigation_failed_events.rbs +17 -0
  72. data/sig/bidi2pdf/bidi/network_event.rbs +54 -46
  73. data/sig/bidi2pdf/bidi/network_event_formatters/network_event_console_formatter.rbs +63 -0
  74. data/sig/bidi2pdf/bidi/network_event_formatters/network_event_formatter_utils.rbs +15 -0
  75. data/sig/bidi2pdf/bidi/network_event_formatters/network_event_html_formatter.rbs +18 -0
  76. data/sig/bidi2pdf/bidi/network_event_formatters.rbs +6 -0
  77. data/sig/bidi2pdf/bidi/network_events.rbs +14 -39
  78. data/sig/bidi2pdf/bidi/session.rbs +144 -31
  79. data/sig/bidi2pdf/bidi/user_context.rbs +64 -45
  80. data/sig/bidi2pdf/bidi/web_socket_dispatcher.rbs +22 -30
  81. data/sig/bidi2pdf/chromedriver_manager.rbs +57 -22
  82. data/sig/bidi2pdf/cli.rbs +22 -2
  83. data/sig/bidi2pdf/dsl.rbs +34 -0
  84. data/sig/bidi2pdf/launcher.rbs +39 -1
  85. data/sig/bidi2pdf/notifications/event.rbs +40 -0
  86. data/sig/bidi2pdf/notifications/instrumenter.rbs +21 -0
  87. data/sig/bidi2pdf/notifications/logging_subscriber.rbs +41 -0
  88. data/sig/bidi2pdf/notifications.rbs +24 -0
  89. data/sig/bidi2pdf/process_tree.rbs +2 -2
  90. data/sig/bidi2pdf/session_runner.rbs +41 -1
  91. data/sig/bidi2pdf/test_helpers/configuration.rbs +51 -0
  92. data/sig/bidi2pdf/test_helpers/images/extractor.rbs +43 -0
  93. data/sig/bidi2pdf/test_helpers/images/image_similarity_checker.rbs +35 -0
  94. data/sig/bidi2pdf/test_helpers/images/tiff_helper.rbs +70 -0
  95. data/sig/bidi2pdf/test_helpers/images.rbs +0 -0
  96. data/sig/bidi2pdf/test_helpers/matchers/contains_pdf_image.rbs +0 -0
  97. data/sig/bidi2pdf/test_helpers/matchers/contains_pdf_text.rbs +0 -0
  98. data/sig/bidi2pdf/test_helpers/matchers/have_pdf_page_count.rbs +0 -0
  99. data/sig/bidi2pdf/test_helpers/matchers/match_pdf_text.rbs +0 -0
  100. data/sig/bidi2pdf/test_helpers/pdf_file_helper.rbs +23 -0
  101. data/sig/bidi2pdf/test_helpers/pdf_reader_utils.rbs +49 -0
  102. data/sig/bidi2pdf/test_helpers/pdf_text_sanitizer.rbs +38 -0
  103. data/sig/bidi2pdf/test_helpers/spec_paths_helper.rbs +35 -0
  104. data/sig/bidi2pdf/test_helpers/testcontainers/chromedriver_container.rbs +43 -0
  105. data/sig/bidi2pdf/test_helpers/testcontainers/chromedriver_test_helper.rbs +45 -0
  106. data/sig/bidi2pdf/test_helpers/testcontainers/container_endpoint.rbs +25 -0
  107. data/sig/bidi2pdf/test_helpers/testcontainers/shared_docker_network.rbs +3 -0
  108. data/sig/bidi2pdf/test_helpers/testcontainers/testcontainers_refinement.rbs +47 -0
  109. data/sig/bidi2pdf/test_helpers/testcontainers.rbs +6 -0
  110. data/sig/bidi2pdf/test_helpers.rbs +0 -0
  111. data/sig/bidi2pdf/verbose_logger.rbs +37 -0
  112. data/sig/bidi2pdf/version.rbs +3 -0
  113. data/sig/bidi2pdf.rbs +112 -2
  114. data/tasks/generate_rbs.rake +11 -11
  115. metadata +62 -10
  116. data/sig/bidi2pdf/utils.rbs +0 -5
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bidi2pdf
4
+ module TestHelpers
5
+ module Testcontainers
6
+ # Builds a URL for reaching a container's published port from the test
7
+ # process, using the container's own host/port resolution.
8
+ class ContainerEndpoint
9
+ def initialize(container, port)
10
+ @container = container
11
+ @port = port
12
+ end
13
+
14
+ def url(scheme: "http", path: "")
15
+ "#{scheme}://#{@container.accessible_host}:#{@container.mapped_port(@port)}/#{path}"
16
+ end
17
+
18
+ # Address reachable from another container on the same Docker network (e.g. remote-chrome
19
+ # reaching nginx), by alias and internal port - as opposed to #url's host-accessible,
20
+ # externally-mapped port. Uses the same @port this instance was built with, not a
21
+ # container_ports.first guess: the two methods must agree on which port they're both
22
+ # describing for the same container, or a caller comparing #url and #alias_url for what's
23
+ # meant to be the same endpoint could silently get two different services.
24
+ def alias_url(scheme: "http", path: "")
25
+ "#{scheme}://#{@container.aliases.first}:#{@port}/#{path}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -11,7 +11,7 @@ RSpec.configure do |config|
11
11
 
12
12
  if uses_containers
13
13
  config.shared_network = Docker::Network.create("bidi2pdf-test-net-#{SecureRandom.hex(4)}")
14
- puts "🕸️ started shared network #{config.shared_network}"
14
+ reporter.message("🕸️ started shared network #{config.shared_network}")
15
15
  end
16
16
  end
17
17
 
@@ -19,3 +19,7 @@ RSpec.configure do |config|
19
19
  config.shared_network&.remove
20
20
  end
21
21
  end
22
+
23
+ def reporter
24
+ RSpec.configuration.reporter
25
+ end
@@ -29,6 +29,39 @@ module Bidi2pdf
29
29
  self
30
30
  end
31
31
 
32
+ def container_json
33
+ @_container&.json
34
+ end
35
+
36
+ # Address of the Docker host at which this container's *mapped* ports
37
+ # are reachable from the test process.
38
+ #
39
+ # Resolution belongs to testcontainers: it honours TC_HOST, a tcp:/ssh:
40
+ # DOCKER_HOST, a native local daemon, and a sibling container reaching
41
+ # the daemon over the bridge gateway — and it derives #mapped_port from
42
+ # the same decision, so the two must stay on one path. We only add a
43
+ # fallback for the cases 0.2.0 leaves unresolved.
44
+ #
45
+ # This is not the address containers use to reach each other; for that
46
+ # the helpers join a shared network and address containers by alias.
47
+ def accessible_host
48
+ resolved_host || "localhost"
49
+ end
50
+
51
+ # testcontainers-core 0.2.0 cannot resolve a host when the test process
52
+ # runs inside a container and the container under test is on a custom
53
+ # network: #container_gateway_ip hardcodes the "bridge" network key
54
+ # (docker_container.rb:1074), so #host returns nil. On the default
55
+ # bridge it can instead reach docker_container.rb:703, which calls an
56
+ # undefined `bridge_ip`. Both are fixed on testcontainers-ruby main;
57
+ # treat either as "unresolved" and fall back.
58
+ def resolved_host
59
+ value = host
60
+ value unless value.nil? || value.empty?
61
+ rescue NoMethodError
62
+ nil
63
+ end
64
+
32
65
  def _container_create_options
33
66
  opts = super
34
67
  network_name = network&.info&.[]("Name")
@@ -10,6 +10,7 @@ module Bidi2pdf
10
10
  module TestHelpers
11
11
  module Testcontainers
12
12
  require_relative "testcontainers/testcontainers_refinement"
13
+ require_relative "testcontainers/container_endpoint"
13
14
  require_relative "testcontainers/chromedriver_container"
14
15
  require_relative "testcontainers/chromedriver_test_helper"
15
16
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bidi2pdf
4
- VERSION = "0.1.12"
4
+ VERSION = "0.1.14"
5
5
  end
data/lib/bidi2pdf.rb CHANGED
@@ -51,6 +51,8 @@ module Bidi2pdf
51
51
 
52
52
  class PrintError < Error; end
53
53
 
54
+ class ScreenshotError < Error; end
55
+
54
56
  class ScriptInjectionError < Error; end
55
57
 
56
58
  class StyleInjectionError < Error; end
@@ -1,20 +1,27 @@
1
1
  module Bidi2pdf
2
2
  module Bidi
3
3
  class AddHeadersInterceptor
4
- @id: String
5
- @client: untyped
6
- @headers: Hash[String, String]
4
+ @headers: untyped
7
5
 
8
- attr_reader id: String
9
- attr_reader headers: Hash[String, String]
6
+ @url_patterns: untyped
10
7
 
11
- def initialize: (String id, Hash[String, String] headers, untyped client) -> void
8
+ @context: untyped
12
9
 
13
- def handle_event: (Hash[String, untyped] response) -> (nil | untyped)
10
+ include Interceptor
14
11
 
15
- private
12
+ def self.phases: () -> ::Array[untyped]
16
13
 
17
- attr_reader client: untyped
14
+ def self.events: () -> ::Array["network.beforeRequestSent"]
15
+
16
+ attr_reader headers: untyped
17
+
18
+ attr_reader url_patterns: untyped
19
+
20
+ attr_reader context: untyped
21
+
22
+ def initialize: (headers: untyped, url_patterns: untyped, context: untyped) -> void
23
+
24
+ def process_interception: (untyped _event_response, untyped _navigation_id, untyped network_id, untyped _url) -> untyped
18
25
  end
19
26
  end
20
27
  end
@@ -1,17 +1,42 @@
1
1
  module Bidi2pdf
2
2
  module Bidi
3
3
  class AuthInterceptor
4
- @credentials: Hash[Symbol, String]?
4
+ @url_patterns: untyped
5
5
 
6
- def initialize: (?credentials: Hash[Symbol, String]?) -> void
6
+ @context: untyped
7
7
 
8
- def intercept: (untyped request) -> untyped
8
+ @username: untyped
9
9
 
10
- private
10
+ @password: untyped
11
+
12
+ @network_ids: untyped
13
+
14
+ include Interceptor
15
+
16
+ def self.phases: () -> ::Array[untyped]
17
+
18
+ def self.events: () -> ::Array["network.authRequired"]
19
+
20
+ attr_reader headers: untyped
21
+
22
+ attr_reader url_patterns: untyped
11
23
 
12
- def add_auth_header: (untyped request) -> void
24
+ attr_reader context: untyped
25
+
26
+ attr_reader username: untyped
27
+
28
+ attr_reader password: untyped
29
+
30
+ attr_reader network_ids: untyped
31
+
32
+ def initialize: (username: untyped, password: untyped, url_patterns: untyped, context: untyped) -> void
33
+
34
+ def process_interception: (untyped _event_response, untyped navigation_id, untyped network_id, untyped url) -> untyped
35
+
36
+ private
13
37
 
14
- def auth_header_value: () -> String?
38
+ # rubocop:disable Naming/PredicateMethod
39
+ def handled_bad_credentials: (untyped navigation_id, untyped network_id, untyped url) -> (false | true)
15
40
  end
16
41
  end
17
- end
42
+ end
@@ -1,38 +1,11 @@
1
1
  module Bidi2pdf
2
2
  module Bidi
3
3
  class Browser
4
- @url: String
5
- @chromedriver_manager: Bidi2pdf::ChromedriverManager
6
- @browser: untyped
7
- @timeout: Integer
8
- @debug: bool
4
+ @client: untyped
9
5
 
10
- attr_reader browser: untyped
11
- attr_reader timeout: Integer
6
+ def initialize: (untyped client) -> void
12
7
 
13
- def initialize: (
14
- url: String,
15
- chromedriver_manager: Bidi2pdf::ChromedriverManager,
16
- ?timeout: Integer,
17
- ?debug: bool
18
- ) -> void
19
-
20
- def navigate: (?reload: bool) -> void
21
-
22
- def current_url: -> String
23
-
24
- def wait_until: [T] (
25
- ?timeout: Integer,
26
- ?message: String
27
- ) { () -> T? } -> T
28
-
29
- def close: () -> void
30
-
31
- private
32
-
33
- def connect: () -> untyped
34
-
35
- def setup_browser: () -> untyped
8
+ def create_user_context: () -> untyped
36
9
  end
37
10
  end
38
- end
11
+ end
@@ -0,0 +1,59 @@
1
+ module Bidi2pdf
2
+ module Bidi
3
+ class BrowserConsoleLoggerSuggar
4
+ @browser_console_logger: untyped
5
+
6
+ @level: untyped
7
+
8
+ @prefix: untyped
9
+
10
+ @timestamp: untyped
11
+
12
+ @text: untyped
13
+
14
+ @args: untyped
15
+
16
+ @stack_trace: untyped
17
+
18
+ attr_reader browser_console_logger: untyped
19
+
20
+ def initialize: (untyped browser_console_logger) -> void
21
+
22
+ def with_level: (untyped level) -> self
23
+
24
+ def with_prefix: (untyped prefix) -> self
25
+
26
+ def with_timestamp: (untyped timestamp) -> self
27
+
28
+ def with_text: (untyped text) -> self
29
+
30
+ def with_args: (untyped args) -> self
31
+
32
+ def with_stack_trace: (untyped stack_trace) -> self
33
+
34
+ def log_event: () -> untyped
35
+
36
+ def prefix: () -> untyped
37
+ end
38
+
39
+ class BrowserConsoleLogger
40
+ @logger: untyped
41
+
42
+ include JsLoggerHelper
43
+
44
+ attr_accessor logger: untyped
45
+
46
+ def initialize: (untyped logger) -> void
47
+
48
+ def builder: () -> untyped
49
+
50
+ def log_message: (untyped level, untyped prefix, untyped text) -> (nil | untyped)
51
+
52
+ def log_args: (untyped prefix, untyped args) -> (nil | untyped)
53
+
54
+ def log_stack_trace: (untyped prefix, untyped trace) -> untyped
55
+
56
+ def self.format_timestamp: (untyped timestamp) -> ("N/A" | untyped)
57
+ end
58
+ end
59
+ end
@@ -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
- @browser: Bidi2pdf::Bidi::Browser
5
- @tab_id: String?
6
- @session_id: String?
7
- @timeout: Integer
31
+ @client: untyped
8
32
 
9
- attr_reader browser: Bidi2pdf::Bidi::Browser
10
- attr_reader tab_id: String?
11
- attr_reader session_id: String?
33
+ @browsing_context_id: untyped
12
34
 
13
- def initialize: (
14
- browser: Bidi2pdf::Bidi::Browser,
15
- ?tab_id: String?,
16
- ?timeout: Integer
17
- ) -> void
35
+ @user_context_id: untyped
18
36
 
19
- def navigate_to: (String url) -> void
37
+ @tabs: untyped
20
38
 
21
- def execute_script: [T] (String script, *untyped args) -> T
39
+ @network_events: untyped
22
40
 
23
- def wait_for_navigation: (?timeout: Integer) -> void
41
+ @logger_events: untyped
24
42
 
25
- def wait_for_element: (
26
- selector: String,
27
- ?visible: bool,
28
- ?timeout: Integer
29
- ) -> untyped
43
+ @navigation_failed_events: untyped
30
44
 
31
- def capture_screenshot: (?path: String?) -> String
45
+ @open: untyped
32
46
 
33
- def close: () -> void
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 ensure_tab_active: () -> void
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
- def connect_to_tab: () -> String?
265
+ # Closes all tabs associated with the browser tab.
266
+ def close_tabs: () -> untyped
40
267
  end
41
268
  end
42
- end
269
+ end