From d6c21061730439e096e2873faf19b059298d8e4c Mon Sep 17 00:00:00 2001 From: Dmitry Vorotilin Date: Tue, 24 Nov 2026 15:15:10 +0300 Subject: [PATCH] ref(api): return nil from commands without a result, the node from node commands Commands returned true, self or Chrome's raw response at random. They return nil now, Node, Mouse and Keyboard commands keep returning their receiver so they chain, and node.remove, select_file and execute join them. Queries and navigation keep their results. --- CHANGELOG.md | 5 +++++ README.md | 2 +- docs/11-cookies.md | 32 ++++++++++++++++---------------- docs/12-headers.md | 6 +++--- docs/13-javascript.md | 8 ++++---- docs/18-node.md | 6 +++--- docs/21-workers.md | 2 +- docs/7-network.md | 2 +- lib/ferrum/browser.rb | 6 ++++++ lib/ferrum/console.rb | 4 ++-- lib/ferrum/context.rb | 2 +- lib/ferrum/contexts.rb | 5 +++-- lib/ferrum/cookies.rb | 16 ++++++++-------- lib/ferrum/dialog.rb | 6 ++++++ lib/ferrum/downloads.rb | 3 ++- lib/ferrum/frame/runtime.rb | 4 ++-- lib/ferrum/headers.rb | 10 +++++----- lib/ferrum/network.rb | 11 +++++++---- lib/ferrum/node.rb | 10 ++++++---- lib/ferrum/page.rb | 19 +++++++++++-------- lib/ferrum/page/cookies.rb | 13 +++++++------ lib/ferrum/page/navigation.rb | 3 +++ lib/ferrum/worker.rb | 4 ++-- sig/ferrum/browser.rbs | 4 ++-- sig/ferrum/console.rbs | 2 +- sig/ferrum/context.rbs | 2 +- sig/ferrum/contexts.rbs | 2 +- sig/ferrum/cookies.rbs | 8 ++++---- sig/ferrum/dialog.rbs | 4 ++-- sig/ferrum/downloads.rbs | 2 +- sig/ferrum/frame/runtime.rbs | 2 +- sig/ferrum/headers.rbs | 6 +++--- sig/ferrum/network.rbs | 6 +++--- sig/ferrum/node.rbs | 6 +++--- sig/ferrum/page.rbs | 10 ++++++---- sig/ferrum/page/cookies.rbs | 6 +++--- sig/ferrum/page/navigation.rbs | 2 +- sig/ferrum/worker.rbs | 2 +- spec/browser_spec.rb | 4 +++- spec/context_spec.rb | 3 ++- spec/contexts_spec.rb | 3 ++- spec/network_spec.rb | 4 ++-- spec/page_spec.rb | 6 +++--- 43 files changed, 150 insertions(+), 113 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6b8d7c02..255384d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,11 @@ node without a box ### Changed +- Commands without a result return `nil` instead of `true`, `self` or Chrome's raw response: `set_viewport`, `resize`, + `stop`, `close`, `activate`, `execute`, `remove_script_on_new_document`, `dialog.accept`/`dismiss`, `network.intercept`, + `clear` and `emulate`, `headers.add`/`set`/`clear`, `cookies.set`/`remove`/`clear`/`load`, `downloads.set_behavior`, + `console.clear`, `browser.close`/`reset`, `context.dispose`, `contexts.dispose` and `worker.close`. `node.remove`, + `select_file` and `execute` return the node, like the other node commands - `node.click(offset:)` and `hover(offset:)` measure `x` and `y` from the center by default, pass `position: :top` for the top-left corner - `browser.contexts.each` and the `Enumerable` methods yield contexts instead of `[id, context]` pairs diff --git a/README.md b/README.md index 3d6f6485..58512ebb 100644 --- a/README.md +++ b/README.md @@ -121,7 +121,7 @@ want to keep a value in the browser and pass it back in later, and `Ferrum::Node#evaluate` to run a script with `this` bound to an element: ```ruby -page.execute("window.scrollBy(0, 100)") # => true +page.execute("window.scrollBy(0, 100)") list = page.evaluate_handle("document.querySelectorAll('li')") page.evaluate("Array.from(nodes).map(n => n.textContent)", nodes: list) diff --git a/docs/11-cookies.md b/docs/11-cookies.md index c539921c..7cfec2d1 100644 --- a/docs/11-cookies.md +++ b/docs/11-cookies.md @@ -46,7 +46,7 @@ browser.cookies["NID"] # => true +browser.cookies.set(name: "stealth", value: "omg", domain: "google.com") ``` * value `Cookie` ```ruby nid_cookie = browser.cookies["NID"] # => -browser.cookies.set(nid_cookie) # => true +browser.cookies.set(nid_cookie) ``` -#### remove(\*\*options) : `true` +#### remove(\*\*options) Removes the cookies with the given name, on the exact domain, the `:base_url` host by default, or the ones sent to the URL. @@ -84,16 +84,16 @@ URL. * :path `String` ```ruby -browser.cookies.remove(name: "stealth", domain: "google.com") # => true -browser.cookies.remove(name: "sso_token", url: "https://sso.example.com") # => true +browser.cookies.remove(name: "stealth", domain: "google.com") +browser.cookies.remove(name: "sso_token", url: "https://sso.example.com") ``` -#### clear : `true` +#### clear Removes all cookies in the context. ```ruby -browser.cookies.clear # => true +browser.cookies.clear ``` #### store(path) : `Integer` @@ -104,12 +104,12 @@ Stores all cookies in the context in a file, `cookies.yml` by default. browser.cookies.store # => 15657 ``` -#### load(path) : `true` +#### load(path) Loads the cookies from a file, `cookies.yml` by default, and sets them in the context. ```ruby -browser.cookies.load # => true +browser.cookies.load ``` ## Page cookies @@ -134,27 +134,27 @@ The page's first cookie with the given name, narrowed down like the context's. page.cookies["NID"] # => ``` -#### set(value) : `Boolean` +#### set(value) Sets a cookie, takes the same options as the context's `set`. Without `:domain` or `:url` it's set for the page's host, or the `:base_url` host before the page has loaded anything. ```ruby -page.cookies.set(name: "stealth", value: "omg") # => true +page.cookies.set(name: "stealth", value: "omg") ``` -#### remove(\*\*options) : `true` +#### remove(\*\*options) Removes the cookies with the given name, on the page's host unless `:domain` or `:url` is given. ```ruby -page.cookies.remove(name: "stealth") # => true +page.cookies.remove(name: "stealth") ``` -#### clear : `true` +#### clear Removes the page's cookies, the ones `each` yields. Cookies on other domains stay. ```ruby -page.cookies.clear # => true +page.cookies.clear ``` diff --git a/docs/12-headers.md b/docs/12-headers.md index 12d437a1..cf5147f7 100644 --- a/docs/12-headers.md +++ b/docs/12-headers.md @@ -10,7 +10,7 @@ sidebar_position: 12 Get all headers -#### set(headers) : `Boolean` +#### set(headers) Set given headers. Eventually clear all headers and set given ones. @@ -22,12 +22,12 @@ back the browser's user agent or language once the header that changed it is gon two headers are only sent with requests, like any other, and `navigator` and the client hints stay as they are. Use `network.emulate(user_agent:, accept_language:)` to override both the header and what the page reports. -#### add(headers) : `Boolean` +#### add(headers) Adds given headers to already set ones. * headers `Hash` key-value pairs for example `"Referer" => "http://example.com"` -#### clear : `Boolean` +#### clear Clear all headers, and the user agent or language they set. diff --git a/docs/13-javascript.md b/docs/13-javascript.md index 7efb93e3..4d36ba9f 100644 --- a/docs/13-javascript.md +++ b/docs/13-javascript.md @@ -44,12 +44,12 @@ list = page.evaluate_handle("document.querySelectorAll('li')") page.evaluate("Array.from(nodes).map(n => n.textContent)", nodes: list) ``` -#### execute(expression, \*args, timeout: nil, \*\*named) : `Boolean` +#### execute(expression, \*args, timeout: nil, \*\*named) Run JavaScript for its side effects. The script is used as a function body, so statements need no wrapping. ```ruby -page.execute("window.scrollBy(0, 100)") # => true +page.execute("window.scrollBy(0, 100)") ``` `Ferrum::Node` has the same three methods, with `this` bound to the element. Arrow functions don't get `this`, so use a @@ -117,12 +117,12 @@ page.evaluate("window.secret") # => nil world.evaluate("document.title") # => same as page.evaluate("document.title") ``` -#### remove_script_on_new_document(identifier) : `Boolean` +#### remove_script_on_new_document(identifier) Stops running a script added with `evaluate_on_new_document` in new documents. ```ruby -page.remove_script_on_new_document(id) # => true +page.remove_script_on_new_document(id) ``` #### add_extension(extension) diff --git a/docs/18-node.md b/docs/18-node.md index 3424c24c..bf0322d0 100644 --- a/docs/18-node.md +++ b/docs/18-node.md @@ -183,7 +183,7 @@ page.at_css("#footer").scroll.in_viewport? # => true page.at_css("#row").in_viewport?(of: page.at_css("#table")) # => true ``` -#### select_file(value) : `Hash` +#### select_file(value) : `Node` Sets files on a file input. @@ -285,7 +285,7 @@ page.at_xpath("//*[select]").select(["1", "2"]) #### evaluate(expression, \*positional, \*\*keywords) : `Object` #### evaluate_handle(expression, \*positional, \*\*keywords) : `RemoteObject` | `Node` | `Object` -#### execute(expression, \*positional, \*\*keywords) : `true` +#### execute(expression, \*positional, \*\*keywords) : `Node` Run JavaScript with `this` bound to the node. `evaluate` returns the result, `evaluate_handle` returns a handle that stays in the browser instead of a serialized value (a `Node` for a node, the value itself for a primitive), `execute` @@ -329,7 +329,7 @@ page.at_css("input").pinpoint(x: 5, y: 5) # => [131.7, 406.4] page.at_css("input").pinpoint(x: 5, y: 5, position: :top) # => [55.2, 395.9] ``` -#### remove : `Hash` +#### remove : `Node` Removes the node from the DOM. diff --git a/docs/21-workers.md b/docs/21-workers.md index ab1fa7e0..c9d9d388 100644 --- a/docs/21-workers.md +++ b/docs/21-workers.md @@ -105,7 +105,7 @@ worker.evaluate("1 + 1") # => 2 Subscribe to the worker's own network interception events, same as `page.on(:request)` -- see the `intercept` method in [Network](/docs/ferrum/network), or to its new console messages. -#### close : `Boolean` +#### close Closes the underlying CDP target and the worker's own connection. diff --git a/docs/7-network.md b/docs/7-network.md index 2ee4dffb..1428cae1 100644 --- a/docs/7-network.md +++ b/docs/7-network.md @@ -233,7 +233,7 @@ page.go_to("https://github.com/") # => Ferrum::StatusError (Request to https://g page.network.offline = false ``` -#### emulate(\*\*options) : `Network` +#### emulate(\*\*options) Overrides the user agent, the accept language, the platform and the client hints the page reports, in the request headers and in `navigator`. The options you don't pass keep their previous values, `nil` brings one back to the browser's default. diff --git a/lib/ferrum/browser.rb b/lib/ferrum/browser.rb index 8b7787db..60689a5c 100644 --- a/lib/ferrum/browser.rb +++ b/lib/ferrum/browser.rb @@ -199,6 +199,8 @@ def create_page(new_context: false, proxy: nil) # # Closes browser tabs opened by the `Browser` instance. # + # @return [nil] + # # @raise [TimeoutError] # # @example @@ -214,6 +216,7 @@ def create_page(new_context: false, proxy: nil) # def reset contexts.reset + nil end # @@ -258,8 +261,11 @@ def crash # # You should clean up resources/connections in ruby world manually, it's only a CDP command. # + # @return [nil] + # def close command("Browser.close") + nil end # diff --git a/lib/ferrum/console.rb b/lib/ferrum/console.rb index 7e199c1d..14941c9d 100644 --- a/lib/ferrum/console.rb +++ b/lib/ferrum/console.rb @@ -80,11 +80,11 @@ def empty? # # Forgets the collected messages. # - # @return [self] + # @return [nil] # def clear @mutex.synchronize { @messages.clear } - self + nil end # diff --git a/lib/ferrum/context.rb b/lib/ferrum/context.rb index 63f0e957..6b4a9444 100644 --- a/lib/ferrum/context.rb +++ b/lib/ferrum/context.rb @@ -319,7 +319,7 @@ def close_targets_connection # Disposes this browser context and all of its targets. The browser's # implicit context cannot be disposed, see {#implicit?}. # - # @return [Boolean, nil] + # @return [nil] # # @raise [TimeoutError] def dispose diff --git a/lib/ferrum/contexts.rb b/lib/ferrum/contexts.rb index 8babbff3..a91b5ed0 100644 --- a/lib/ferrum/contexts.rb +++ b/lib/ferrum/contexts.rb @@ -115,7 +115,7 @@ def create(**options) # # @param [String] context_id # - # @return [Boolean, nil] + # @return [nil] # # @raise [TimeoutError, BrowserError] def dispose(context_id) @@ -129,7 +129,8 @@ def dispose(context_id) ensure @contexts.delete(context_id) end - true + + nil end # Closes the WebSocket connection of every target in every context, diff --git a/lib/ferrum/cookies.rb b/lib/ferrum/cookies.rb index c08effc2..7e69df6b 100644 --- a/lib/ferrum/cookies.rb +++ b/lib/ferrum/cookies.rb @@ -77,7 +77,7 @@ def each # @option options [String] :samesite # Specifies whether the cookie is `SameSite`, also accepted as `:same_site`. # - # @return [true] + # @return [nil] # # @raise [BrowserError] if neither `:domain`, `:url` nor `:base_url` is set. # @@ -95,7 +95,7 @@ def set(options) cookie[:domain] ||= default_domain unless cookie[:url] write(cookie) - true + nil end # @@ -116,7 +116,7 @@ def set(options) # @option options [String] :path # The exact path of the cookie. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -135,13 +135,13 @@ def remove(name:, **options) end cookies.each { |cookie| write(cookie.attributes.merge("expires" => 1)) } - true + nil end # # Removes all cookies in the context. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -150,7 +150,7 @@ def remove(name:, **options) # def clear @client.command("Storage.clearCookies", timeout: @client.timeout, browserContextId: @context_id) - true + nil end # @@ -170,7 +170,7 @@ def store(path = "cookies.yml") # # Loads all cookies from the file and sets them in the context. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -180,7 +180,7 @@ def store(path = "cookies.yml") def load(path = "cookies.yml") cookies = YAML.load_file(path) cookies.each { |c| set(c) } - true + nil end private diff --git a/lib/ferrum/dialog.rb b/lib/ferrum/dialog.rb index 2a5e054a..371f121f 100644 --- a/lib/ferrum/dialog.rb +++ b/lib/ferrum/dialog.rb @@ -31,6 +31,8 @@ def handled? # # @param [String, nil] prompt_text # + # @return [nil] + # # @raise [TimeoutError] # # @example @@ -50,11 +52,14 @@ def accept(prompt_text = nil) options.merge!(promptText: response) if response @handled = true @page.command("Page.handleJavaScriptDialog", slowmoable: true, **options) + nil end # # Dismiss dialog. # + # @return [nil] + # # @raise [TimeoutError] # # @example @@ -71,6 +76,7 @@ def accept(prompt_text = nil) def dismiss @handled = true @page.command("Page.handleJavaScriptDialog", slowmoable: true, accept: false) + nil end # diff --git a/lib/ferrum/downloads.rb b/lib/ferrum/downloads.rb index 41ed9b43..f497b86a 100644 --- a/lib/ferrum/downloads.rb +++ b/lib/ferrum/downloads.rb @@ -111,7 +111,7 @@ def wait(timeout = WAIT_TIMEOUT) # @param [:deny, :allow, :allowAndName, :default] behavior # Whether/how to allow downloads. # - # @return [void] + # @return [nil] # # @raise [ArgumentError] # @raise [Ferrum::Error] @@ -128,6 +128,7 @@ def set_behavior(save_path:, behavior: :allow) downloadPath: save_path, behavior: behavior, eventsEnabled: true) + nil end # diff --git a/lib/ferrum/frame/runtime.rb b/lib/ferrum/frame/runtime.rb index 20510ead..d12e2c17 100644 --- a/lib/ferrum/frame/runtime.rb +++ b/lib/ferrum/frame/runtime.rb @@ -223,7 +223,7 @@ def evaluate_handle(expression, *positional, **keywords) # @param (see #evaluate) # @option (see #evaluate) # - # @return [Boolean] + # @return [nil] # Always `true`. # # @raise [TimeoutError] @@ -237,7 +237,7 @@ def evaluate_handle(expression, *positional, **keywords) # def execute(expression, *positional, **keywords) run(expression, positional, keywords, mode: :none) - true + nil end # diff --git a/lib/ferrum/headers.rb b/lib/ferrum/headers.rb index ee6a7844..5e43a3b6 100644 --- a/lib/ferrum/headers.rb +++ b/lib/ferrum/headers.rb @@ -34,7 +34,7 @@ def get # @param [Hash{String => String}] headers # key-value pairs for example `"User-Agent" => "Browser"`. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -47,7 +47,7 @@ def set(headers) # # Clear all headers, and the user agent and language they set. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -55,7 +55,7 @@ def clear reset_overrides @headers = {} @page.command("Network.setExtraHTTPHeaders", headers: @headers) - true + nil end # @@ -64,7 +64,7 @@ def clear # @param [Hash{String => String}] headers # key-value pairs for example `"Referer" => "http://example.com"`. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -76,7 +76,7 @@ def add(headers) @page.network.emulate(**overrides) end @page.command("Network.setExtraHTTPHeaders", headers: @headers) - true + nil end private diff --git a/lib/ferrum/network.rb b/lib/ferrum/network.rb index 81345c05..911e8544 100644 --- a/lib/ferrum/network.rb +++ b/lib/ferrum/network.rb @@ -222,7 +222,7 @@ def status # @param [:traffic, :cache] type # The type of traffic to clear. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -242,7 +242,7 @@ def clear(type) @page.command("Network.clearBrowserCache") end - true + nil end # @@ -297,6 +297,8 @@ def whitelist=(patterns) # @param [Symbol, nil] resource_type # One of the [resource types](https://chromedevtools.github.io/devtools-protocol/tot/Network#type-ResourceType) # + # @return [nil] + # # @raise [TimeoutError] # # @example @@ -327,6 +329,7 @@ def intercept(pattern: "*", resource_type: nil, request_stage: nil, handle_auth_ pattern[:resourceType] = resource_type if resource_type pattern[:requestStage] = request_stage if request_stage @page.command("Fetch.enable", patterns: [pattern], handleAuthRequests: handle_auth_requests) + nil end # @@ -576,7 +579,7 @@ def offline_mode # `:full_version`, `:bitness`, `:wow64` and `:form_factors` are optional # too. # - # @return [self] + # @return [nil] # # @raise [ArgumentError] on any other option, or a `:metadata` that is # missing a key or has an unknown one. @@ -607,7 +610,7 @@ def emulate(**overrides) params[:userAgentMetadata] = camelize(@overrides[:metadata]) if @overrides[:metadata] @page.command("Network.setUserAgentOverride", **params) - self + nil end # diff --git a/lib/ferrum/node.rb b/lib/ferrum/node.rb index 400dfb93..4a62d29d 100644 --- a/lib/ferrum/node.rb +++ b/lib/ferrum/node.rb @@ -455,7 +455,7 @@ def in_viewport?(of: nil) # @param [String, Array] value # Path or paths to the file(s) to upload. # - # @return [Hash{String => Object}] + # @return [self] # # @raise [TimeoutError] # @@ -469,6 +469,7 @@ def select_file(value) backendNodeId: backend_node_id, files: Array(value) ) + self end # @@ -750,7 +751,7 @@ def evaluate_handle(expression, *positional, **keywords) # @param (see Frame::Runtime#evaluate) # @option (see Frame::Runtime#evaluate) # - # @return [Boolean] + # @return [self] # Always `true`. # # @raise [TimeoutError] @@ -760,7 +761,7 @@ def evaluate_handle(expression, *positional, **keywords) # def execute(expression, *positional, **keywords) @runtime.evaluate_in(self, expression, positional, keywords, mode: :none) - true + self end # @@ -906,7 +907,7 @@ def axnode # # Removes the node from the DOM. # - # @return [Hash{String => Object}] + # @return [self] # # @raise [TimeoutError] # @@ -915,6 +916,7 @@ def axnode # def remove page.command("DOM.removeNode", nodeId: node_id) + self end # Whether the node still exists in the DOM. diff --git a/lib/ferrum/page.rb b/lib/ferrum/page.rb index 2be6e5c6..7d864f95 100644 --- a/lib/ferrum/page.rb +++ b/lib/ferrum/page.rb @@ -144,7 +144,7 @@ def initialize(client, context_id:, target_id:, proxy: nil) # # Closes the page's target and its underlying client connection. # - # @return [Boolean] + # @return [nil] # # @example # page.close # => true @@ -152,8 +152,7 @@ def initialize(client, context_id:, target_id:, proxy: nil) def close client.notify("Target.closeTarget", targetId: @target_id) close_connection - - true + nil end # @@ -180,7 +179,10 @@ def close_connection # a desktop and leaves touch emulation as is. Turning touch off resets hover and pointer to the detected input # devices, which undoes `--blink-settings` overrides until the next navigation # + # @return [nil] + # # @raise [TimeoutError] + # def set_viewport(width: 0, height: 0, scale_factor: 0, mobile: nil) command("Emulation.setTouchEmulationEnabled", enabled: mobile, maxTouchPoints: 1) unless mobile.nil? @@ -192,6 +194,7 @@ def set_viewport(width: 0, height: 0, scale_factor: 0, mobile: nil) deviceScaleFactor: scale_factor, mobile: mobile || false ) + nil end # @@ -206,7 +209,7 @@ def set_viewport(width: 0, height: 0, scale_factor: 0, mobile: nil) # mode. When `true`, `width` and `height` are read from # {#document_size} instead of the given arguments. # - # @return [Hash{String => Object}] + # @return [nil] # # @raise [TimeoutError] # @@ -471,20 +474,20 @@ def evaluate_on_new_document(source, world_name: nil, run_immediately: false) # # @param [String] identifier # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # def remove_script_on_new_document(identifier) command("Page.removeScriptToEvaluateOnNewDocument", identifier: identifier) - true + nil end # # Activates (focuses) the target for the given page. # When you have multiple tabs you work with, and you need to switch a given one. # - # @return [Boolean] + # @return [nil] # # @raise [TimeoutError] # @@ -493,7 +496,7 @@ def remove_script_on_new_document(identifier) # def activate command("Target.activateTarget", targetId: target_id) - true + nil end # diff --git a/lib/ferrum/page/cookies.rb b/lib/ferrum/page/cookies.rb index 686e83a4..3bc1b886 100644 --- a/lib/ferrum/page/cookies.rb +++ b/lib/ferrum/page/cookies.rb @@ -53,7 +53,7 @@ def each(urls: nil) # # @param [Hash{Symbol => Object}, Ferrum::Cookies::Cookie] options # - # @return [Boolean] + # @return [nil] # # @raise [TimeoutError] # @@ -64,7 +64,8 @@ def set(options) cookie = cookie_params(options) cookie[:domain] ||= default_domain unless cookie[:url] - @page.command("Network.setCookie", **cookie)["success"] + @page.command("Network.setCookie", **cookie) + nil end # @@ -84,7 +85,7 @@ def set(options) # @option options [String] :path # The exact path of the cookie. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -99,14 +100,14 @@ def remove(name:, **options) @page.command("Network.deleteCookies", **options) - true + nil end # # Removes the page's cookies, the ones {#each} yields. Cookies on other # domains stay, `context.cookies.clear` removes them too. # - # @return [true] + # @return [nil] # # @raise [TimeoutError] # @@ -118,7 +119,7 @@ def clear @page.command("Network.deleteCookies", name: cookie.name, domain: cookie.domain, path: cookie.path) end - true + nil end private diff --git a/lib/ferrum/page/navigation.rb b/lib/ferrum/page/navigation.rb index 2da37cf1..3745ec11 100644 --- a/lib/ferrum/page/navigation.rb +++ b/lib/ferrum/page/navigation.rb @@ -179,6 +179,8 @@ def reload!(timeout: nil) # # Stop all navigations and loading pending resources on the page. # + # @return [nil] + # # @raise [TimeoutError] # # @example @@ -187,6 +189,7 @@ def reload!(timeout: nil) # def stop command("Page.stopLoading", slowmoable: true) + nil end # diff --git a/lib/ferrum/worker.rb b/lib/ferrum/worker.rb index 04c4cf9a..11eb45e4 100644 --- a/lib/ferrum/worker.rb +++ b/lib/ferrum/worker.rb @@ -79,7 +79,7 @@ def main_frame # Closes the worker in the browser, and its connection. Chrome refuses # `Target.closeTarget` for a dedicated worker, so it closes itself instead. # - # @return [Boolean] + # @return [nil] def close if type == "worker" client.notify("Runtime.evaluate", expression: "self.close()") @@ -88,7 +88,7 @@ def close end close_connection - true + nil end # Closes the WebSocket connection only, without asking the browser to diff --git a/sig/ferrum/browser.rbs b/sig/ferrum/browser.rbs index 98645e2b..d479bb59 100644 --- a/sig/ferrum/browser.rbs +++ b/sig/ferrum/browser.rbs @@ -39,7 +39,7 @@ module Ferrum def command: (String method, ?timeout: (::Numeric | Deadline)?, **untyped params) -> Hash[String, untyped] - def reset: () -> void + def reset: () -> nil def restart: () -> void @@ -47,7 +47,7 @@ module Ferrum def crash: () -> Hash[String, untyped] - def close: () -> Hash[String, untyped] + def close: () -> nil def version: () -> Browser::VersionInfo diff --git a/sig/ferrum/console.rbs b/sig/ferrum/console.rbs index 47d8934a..6141b344 100644 --- a/sig/ferrum/console.rbs +++ b/sig/ferrum/console.rbs @@ -23,7 +23,7 @@ module Ferrum def empty?: () -> bool - def clear: () -> self + def clear: () -> nil def on: () { (Console::Message) -> void } -> ::Integer diff --git a/sig/ferrum/context.rbs b/sig/ferrum/context.rbs index 98f46f09..2e38c1c0 100644 --- a/sig/ferrum/context.rbs +++ b/sig/ferrum/context.rbs @@ -55,7 +55,7 @@ module Ferrum def close_targets_connection: () -> void - def dispose: () -> bool? + def dispose: () -> nil def target: (String target_id) -> Target? diff --git a/sig/ferrum/contexts.rbs b/sig/ferrum/contexts.rbs index d2f621d9..885adf63 100644 --- a/sig/ferrum/contexts.rbs +++ b/sig/ferrum/contexts.rbs @@ -30,7 +30,7 @@ module Ferrum def create: (**untyped options) -> Context - def dispose: (String context_id) -> bool? + def dispose: (String context_id) -> nil def close_connections: () -> void diff --git a/sig/ferrum/cookies.rbs b/sig/ferrum/cookies.rbs index 81d0c134..c8907617 100644 --- a/sig/ferrum/cookies.rbs +++ b/sig/ferrum/cookies.rbs @@ -10,15 +10,15 @@ module Ferrum def each: () { (Cookies::Cookie) -> void } -> void | () -> Enumerator[Cookies::Cookie, void] - def set: ((Cookies::Cookie | Hash[Symbol | String, untyped]) options) -> true + def set: ((Cookies::Cookie | Hash[Symbol | String, untyped]) options) -> nil - def remove: (name: String, ?domain: String?, ?url: String?, ?path: String?) -> true + def remove: (name: String, ?domain: String?, ?url: String?, ?path: String?) -> nil - def clear: () -> true + def clear: () -> nil def store: (?String path) -> ::Integer - def load: (?String path) -> true + def load: (?String path) -> nil private diff --git a/sig/ferrum/dialog.rbs b/sig/ferrum/dialog.rbs index f7697ab4..15a78fb7 100644 --- a/sig/ferrum/dialog.rbs +++ b/sig/ferrum/dialog.rbs @@ -13,9 +13,9 @@ module Ferrum def handled?: () -> bool - def accept: (?String? prompt_text) -> Hash[String, untyped] + def accept: (?String? prompt_text) -> nil - def dismiss: () -> Hash[String, untyped] + def dismiss: () -> nil def match?: (Regexp regexp) -> bool end diff --git a/sig/ferrum/downloads.rbs b/sig/ferrum/downloads.rbs index cad35f0f..e834f747 100644 --- a/sig/ferrum/downloads.rbs +++ b/sig/ferrum/downloads.rbs @@ -20,7 +20,7 @@ module Ferrum %a{deprecated} def wait: (?(::Numeric | Deadline) timeout) ?{ () -> void } -> void - def set_behavior: (save_path: String, ?behavior: :deny | :allow | :allowAndName | :default) -> void + def set_behavior: (save_path: String, ?behavior: :deny | :allow | :allowAndName | :default) -> nil def subscribe: () -> void diff --git a/sig/ferrum/frame/runtime.rbs b/sig/ferrum/frame/runtime.rbs index 47ded0ae..e834308f 100644 --- a/sig/ferrum/frame/runtime.rbs +++ b/sig/ferrum/frame/runtime.rbs @@ -24,7 +24,7 @@ module Ferrum def evaluate_handle: (untyped expression, *untyped positional, **untyped keywords) -> untyped - def execute: (untyped expression, *untyped positional, **untyped keywords) -> true + def execute: (untyped expression, *untyped positional, **untyped keywords) -> nil def evaluate_in: (Node | RemoteObject object, untyped expression, ::Array[untyped] positional, ::Hash[::Symbol, untyped] keywords, ?mode: ::Symbol) -> untyped diff --git a/sig/ferrum/headers.rbs b/sig/ferrum/headers.rbs index d0c672cd..9f362231 100644 --- a/sig/ferrum/headers.rbs +++ b/sig/ferrum/headers.rbs @@ -10,11 +10,11 @@ module Ferrum def get: () -> ::Hash[String, String] - def set: (::Hash[String, String] headers) -> true + def set: (::Hash[String, String] headers) -> nil - def clear: () -> true + def clear: () -> nil - def add: (::Hash[String, String] headers) -> true + def add: (::Hash[String, String] headers) -> nil private diff --git a/sig/ferrum/network.rbs b/sig/ferrum/network.rbs index 61863cd0..9c409d99 100644 --- a/sig/ferrum/network.rbs +++ b/sig/ferrum/network.rbs @@ -43,7 +43,7 @@ module Ferrum def status: () -> untyped - def clear: (untyped `type`) -> true + def clear: (untyped `type`) -> nil def blacklist=: (untyped patterns) -> untyped @@ -53,7 +53,7 @@ module Ferrum alias allowlist= whitelist= - def intercept: (?pattern: ::String, ?resource_type: untyped?) -> untyped + def intercept: (?pattern: ::String, ?resource_type: untyped?) -> nil def authorize: (user: untyped, password: untyped, ?type: ::Symbol) ?{ () -> untyped } -> untyped @@ -77,7 +77,7 @@ module Ferrum %a{deprecated} def offline_mode: () -> true - def emulate: (?user_agent: String?, ?accept_language: String?, ?platform: String?, ?metadata: ::Hash[Symbol, untyped]?) -> self + def emulate: (?user_agent: String?, ?accept_language: String?, ?platform: String?, ?metadata: ::Hash[Symbol, untyped]?) -> nil private diff --git a/sig/ferrum/node.rbs b/sig/ferrum/node.rbs index 470e667e..e859a257 100644 --- a/sig/ferrum/node.rbs +++ b/sig/ferrum/node.rbs @@ -67,7 +67,7 @@ module Ferrum def in_viewport?: (?of: Node?) -> bool - def select_file: ((String | ::Array[String]) value) -> ::Hash[String, untyped] + def select_file: ((String | ::Array[String]) value) -> self def at_xpath: (String selector) -> Node? @@ -97,7 +97,7 @@ module Ferrum def evaluate_handle: (untyped expression, *untyped positional, **untyped keywords) -> untyped - def execute: (untyped expression, *untyped positional, **untyped keywords) -> true + def execute: (untyped expression, *untyped positional, **untyped keywords) -> self def ==: (untyped other) -> bool @@ -113,7 +113,7 @@ module Ferrum %a{deprecated} def axnode: () -> Accessibility::AXNode? - def remove: () -> ::Hash[String, untyped] + def remove: () -> self def exists?: () -> bool diff --git a/sig/ferrum/page.rbs b/sig/ferrum/page.rbs index 3e478f7a..f4f07878 100644 --- a/sig/ferrum/page.rbs +++ b/sig/ferrum/page.rbs @@ -52,13 +52,15 @@ module Ferrum def context: () -> Context? - def close: () -> bool + def close: () -> nil + + def activate: () -> nil def close_connection: () -> void - def set_viewport: (?width: ::Integer, ?height: ::Integer, ?scale_factor: ::Float, ?mobile: bool?) -> Hash[String, untyped] + def set_viewport: (?width: ::Integer, ?height: ::Integer, ?scale_factor: ::Float, ?mobile: bool?) -> nil - def resize: (?width: ::Numeric?, ?height: ::Numeric?, ?fullscreen: bool) -> Hash[String, untyped] + def resize: (?width: ::Numeric?, ?height: ::Numeric?, ?fullscreen: bool) -> nil def position: () -> Hash[String, ::Integer] @@ -80,7 +82,7 @@ module Ferrum def evaluate_on_new_document: (String source, ?world_name: String?, ?run_immediately: bool) -> String - def remove_script_on_new_document: (String identifier) -> true + def remove_script_on_new_document: (String identifier) -> nil def window_id: () -> ::Integer diff --git a/sig/ferrum/page/cookies.rbs b/sig/ferrum/page/cookies.rbs index 29a64429..b4ec0548 100644 --- a/sig/ferrum/page/cookies.rbs +++ b/sig/ferrum/page/cookies.rbs @@ -10,11 +10,11 @@ module Ferrum def each: (?urls: ::Array[String]?) { (Ferrum::Cookies::Cookie) -> void } -> void | (?urls: ::Array[String]?) -> Enumerator[Ferrum::Cookies::Cookie, void] - def set: ((Ferrum::Cookies::Cookie | Hash[Symbol | String, untyped]) options) -> bool + def set: ((Ferrum::Cookies::Cookie | Hash[Symbol | String, untyped]) options) -> nil - def remove: (name: String, ?domain: String?, ?url: String?, ?path: String?) -> true + def remove: (name: String, ?domain: String?, ?url: String?, ?path: String?) -> nil - def clear: () -> true + def clear: () -> nil private diff --git a/sig/ferrum/page/navigation.rbs b/sig/ferrum/page/navigation.rbs index dfead3fc..5278f651 100644 --- a/sig/ferrum/page/navigation.rbs +++ b/sig/ferrum/page/navigation.rbs @@ -17,7 +17,7 @@ module Ferrum %a{deprecated} def reload!: (?timeout: (::Numeric | Deadline)?) -> true - def stop: () -> Hash[String, untyped] + def stop: () -> nil def back: (?timeout: (::Numeric | Deadline)?) -> true? diff --git a/sig/ferrum/worker.rbs b/sig/ferrum/worker.rbs index 29c3869c..16e1b711 100644 --- a/sig/ferrum/worker.rbs +++ b/sig/ferrum/worker.rbs @@ -28,7 +28,7 @@ module Ferrum def main_frame: () -> nil - def close: () -> true + def close: () -> nil def close_connection: () -> void diff --git a/spec/browser_spec.rb b/spec/browser_spec.rb index 234a94e8..fb9bda25 100644 --- a/spec/browser_spec.rb +++ b/spec/browser_spec.rb @@ -1268,7 +1268,9 @@ def closed_by_peer?(socket) describe "#activate" do it "brings the page to the front" do - expect(browser.activate).to be(true) + browser.activate + + expect(browser.evaluate("document.visibilityState")).to eq("visible") end end end diff --git a/spec/context_spec.rb b/spec/context_spec.rb index fce2a5dc..d0bc9f90 100644 --- a/spec/context_spec.rb +++ b/spec/context_spec.rb @@ -357,7 +357,8 @@ context = browser.contexts.create page = context.create_page - expect(context.dispose).to be(true) + context.dispose + expect(browser.contexts[context.id]).to be_nil expect(browser.command("Target.getBrowserContexts")["browserContextIds"]).not_to include(context.id) target_ids = browser.command("Target.getTargets")["targetInfos"].map { |info| info["targetId"] } diff --git a/spec/contexts_spec.rb b/spec/contexts_spec.rb index 295260f1..8675938d 100644 --- a/spec/contexts_spec.rb +++ b/spec/contexts_spec.rb @@ -133,7 +133,8 @@ context = browser.contexts.create context.create_page - expect(browser.contexts.dispose(context.id)).to be(true) + browser.contexts.dispose(context.id) + expect(browser.contexts[context.id]).to be_nil expect(browser.command("Target.getBrowserContexts")["browserContextIds"]).not_to include(context.id) end diff --git a/spec/network_spec.rb b/spec/network_spec.rb index 8aa31f3f..016f7e5e 100644 --- a/spec/network_spec.rb +++ b/spec/network_spec.rb @@ -733,8 +733,8 @@ end end - it "returns the network" do - expect(page.network.emulate(platform: "Win32")).to be(page.network) + it "returns nil" do + expect(page.network.emulate(platform: "Win32")).to be_nil end it "raises on an unknown option" do diff --git a/spec/page_spec.rb b/spec/page_spec.rb index 9e95d8b7..908dc860 100644 --- a/spec/page_spec.rb +++ b/spec/page_spec.rb @@ -6,7 +6,7 @@ page.go_to target_id = page.target_id - expect(page.close).to be(true) + page.close wait_for { browser.targets.key?(target_id) }.to be(false) end @@ -216,7 +216,7 @@ page.go_to("/simple") expect(page.evaluate("window.secret")).to eq("top") - expect(page.remove_script_on_new_document(id)).to be(true) + page.remove_script_on_new_document(id) page.refresh expect(page.evaluate("window.secret")).to be_nil @@ -231,7 +231,7 @@ other.activate wait_for { page.evaluate("document.visibilityState") }.to eq("hidden") - expect(page.activate).to be(true) + page.activate wait_for { page.evaluate("document.visibilityState") }.to eq("visible") end