Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Metrics/AbcSize:
Max: 66

Metrics/ClassLength:
Max: 320
Max: 300
Exclude:
- spec/**/*

Expand Down
48 changes: 48 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
## [Unreleased](https://github.com/rubycdp/ferrum/compare/v0.21.0...main) ##

### Added

### Changed
- `User-Agent` and `Accept-Language` set through `headers` are only sent with requests, they no longer change what
`navigator` reports. Use `network.emulate(user_agent:, accept_language:)` to override both

### Deprecated

### Fixed

### Removed
- `target.window?` and `windows` of a context and of the browser, use `target.opener_id`, `await_page { ... }` or
`pages(&:opener_id)`
- `:js_errors`, uncaught exceptions are in `page.console` with `source: :exception`, and `page.on(:console)` yields them
- `:pending_connection_errors` and `PendingConnectionsError`, use `go_to!`, it raises `NavigationTimeoutError`
- `current_url` and `current_title` of pages and frames, use `url` and `title`, or `frame.page.url` for the top window
from a frame
- `cookies.all`, use `to_a`, or `map(&:name)` for the names
- `flatten: false`, every page shares the browser's websocket connection
- `FERRUM_DEBUG`, use `FERRUM_LOG=*`
- `:protocol_timeout`, `browser.protocol_timeout`, `browser.protocol_timeout=` and `FERRUM_PROTOCOL_TIMEOUT`, they were
ignored, `:timeout` bounds everything else
- `wait:` of `click`, `mouse.up` and `mouse.down`, use `navigation_wait:`. `FERRUM_CLICK_WAIT` and `FERRUM_GOTO_WAIT`,
use `FERRUM_NAVIGATION_WAIT`
- `mode:` and `keys:` of `node.click`, use `button: :right` or `count: 2`, and `modifiers:`
- Positional `mouse.scroll_by(x, y)` and `scroll_to(x, y)`, pass `x:` and `y:`
- `accessibility.enable` and `disable`, use `accessibility.enabled = true/false`
- `goto`, `go`, `reload` and `reload!`, use `go_to`, `refresh` and `refresh!`
- `frame.set_content`, use `content=`
- `node.scroll_into_view`, `node.axnode` and `node[name]`, use `scroll`, `ax_node` and `property(name)`
- `contexts.each { |id, context| }`, `each` yields the context, use `context.id` for the id
- `request_id` of intercepted and auth requests, `post_data` of requests, and `timestamp` and `monotonic_time` of
`Network::Error`, use `id`, `body` and `time`
- `disable_javascript`, `bypass_csp(enabled:)`, `network.cache(disable:)`, `offline_mode` and
`emulate_network_conditions`, use `javascript = false`, `bypass_csp =`, `cache =`, `offline = true` and `throttle`
- `body`, use `html`. `type` and `type?` of `Network::Request` and `type` of `Network::Response`, use `resource_type`
and `resource_type?`
- `Ferrum::NotImplementedError`, nothing raises it since `node.hover` works
- Passing a Hash with an `"objectId"` key to `evaluate` as a remote object, it is passed as a plain Hash now. Pass the
`Ferrum::RemoteObject` from `evaluate_handle`
- `node.find_position`, use `pinpoint`, its offsets are measured from the center unless `position: :top`
- `wait_for_navigation`, `wait_for_navigation!`, `wait_for_reload`, `wait_for_selector`, `network.wait_for_idle`,
`wait_for_idle!`, `downloads.wait` and `node.wait_for_stop_moving`, use `await_navigation`, `wait_css`, `wait_xpath`,
`wait_idle`, `page.await_download` and `wait_still`. Positional `network.idle?(n)`, pass `connections:`


## [0.21.0](https://github.com/rubycdp/ferrum/compare/v0.20.2...v0.21.0) (November 24, 2026) ##

### Added
Expand Down
7 changes: 1 addition & 6 deletions docs/11-cookies.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ browser.cookies.to_a # => [#<Ferrum::Cookies::Cookie:0x0000558624b37a40 @attribu
browser.cookies.select { |cookie| cookie.domain == ".google.com" }
```

#### all : `Hash<String, Cookie>`

Deprecated, will be removed in 0.22. Cookies keyed by name, so of the cookies sharing a name only one is kept. Use
`to_a`, or `map(&:name)` for the names.

#### \[\](name, domain: `String`, path: `String`) : `Cookie` | `nil`

The first cookie with the given name. A name can be used by several cookies, on different domains or paths, `domain`
Expand Down Expand Up @@ -119,7 +114,7 @@ browser.cookies.load
#### each(urls: `Array<String>`) : `Enumerator<Cookie>`

The cookies sent to the page's URL and the URLs of its frames, or to the given URLs. Nothing before the page has
loaded a URL. `all` is deprecated here too.
loaded a URL.

```ruby
page.cookies.map(&:name) # => ["session"]
Expand Down
8 changes: 3 additions & 5 deletions docs/12-headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ Set given headers. Eventually clear all headers and set given ones.

* headers `Hash` key-value pairs for example `"User-Agent" => "Browser"`

`User-Agent` and `Accept-Language` also change what `navigator` reports, through
[network.emulate](https://github.com/rubycdp/ferrum#network). Other headers leave it alone, and `set` and `clear` bring
back the browser's user agent or language once the header that changed it is gone. This is deprecated: from 0.22 the
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.
`User-Agent` and `Accept-Language` are only sent with requests, like any other header, `navigator` and the client
hints stay as they are. Use [network.emulate(user_agent:, accept_language:)](https://github.com/rubycdp/ferrum#network)
to override both the header and what the page reports.

#### add(headers)

Expand Down
3 changes: 1 addition & 2 deletions docs/15-frames.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ frame.main? # => false

#### page : `Page`

The page the frame belongs to, use `frame.page.url` and `frame.page.title` for the top window. `current_url` and
`current_title` are deprecated and will be removed in 0.22.
The page the frame belongs to, use `frame.page.url` and `frame.page.title` for the top window.

```ruby
page.go_to("https://www.w3schools.com/tags/tag_frame.asp")
Expand Down
11 changes: 1 addition & 10 deletions docs/2-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ Ferrum::Browser.new(options)
* `:incognito` (Boolean) - Create an incognito profile for the browser startup window, `true` by default.
* `:dockerize` (Boolean) - Provide CLI flags to the browser to run it in a container, `false` by default.
* `:xvfb` (Boolean) - Run browser in a virtual framebuffer, `false` by default.
* `:flatten` (Boolean) - Use one websocket connection to the browser and all the pages in flatten mode,
`true` by default. When set to `false`, each page/target opens its own dedicated websocket connection instead
of sharing the browser's connection. Passing `false` is deprecated, the option will be removed in 0.22.
* `:window_size` (Array) - The dimensions of the browser window in which to
test, expressed as a 2-element array, e.g. [1024, 768]. Default: [1024, 768]
* `:extensions` (Array[String | Hash]) - An array of paths to files or JS
Expand All @@ -32,11 +29,6 @@ Ferrum::Browser.new(options)
commands, like `evaluate` or `at_css`, waits for the browser's answer. A call that runs out raises
`Ferrum::TimeoutError`. Pass `timeout:` to `go_to`, `refresh` or `await_navigation` to change it for one
call, or wrap calls in `Ferrum::Deadline.within` to bound them together, see [Timeouts](#timeouts).
* `:js_errors` (Boolean) - Deprecated, will be removed in 0.22. When true, JavaScript errors get re-raised in
Ruby. Uncaught exceptions are in the [console](/docs/ferrum/javascript#console), use
`page.console.select { |m| m.source == :exception }` or `page.on(:console)` instead.
* `:pending_connection_errors` (Boolean) - Deprecated, will be removed in 0.22. Use `page.go_to!(url)` to raise
when the page doesn't load in time.
* `:browser_path` (String) - Path to Chrome binary, or to an Opera or Edge one, you can also set ENV
variable as `BROWSER_PATH=some/path/chrome bundle exec rspec`.
* `:browser_options` (Hash) - Additional command line options,
Expand Down Expand Up @@ -82,8 +74,7 @@ FERRUM_LOG=0 # nothing, even with :logger
```

Items with a dot are CDP method patterns, a leading `-` leaves things out and wins over the rest, and a response is
kept or dropped with the command it answers. Without `FERRUM_LOG`, `:logger` gets everything. `FERRUM_DEBUG` still
works as `FERRUM_LOG=*`, but is deprecated and will be removed in 0.22.
kept or dropped with the command it answers. Without `FERRUM_LOG`, `:logger` gets everything.

`FERRUM_LOG_FORMAT` picks how CDP messages look. `json` writes each message as JSON alone, one per line and never
colored, for tools such as `jq`. `annotated` puts the command id and method in front of each CDP message, one line
Expand Down
5 changes: 1 addition & 4 deletions docs/4-finders.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,9 @@ page.go_to("https://google.com/")
page.title # => "Google"
```

`current_url` and `current_title` are deprecated and will be removed in 0.22, use `url` and `title`.

#### html : `String`

Returns the HTML of the whole document, `<html>` included. `body` is deprecated and will be removed in 0.22, it never
returned only `<body>`.
Returns the HTML of the whole document, `<html>` included.

```ruby
page.go_to("https://google.com/")
Expand Down
2 changes: 0 additions & 2 deletions docs/7-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ page.network.offline = false

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.
Setting `User-Agent` or `Accept-Language` with [headers](https://github.com/rubycdp/ferrum#headers) goes through
here too, the last one set wins. That is deprecated and stops in 0.22.

* options `Hash`
* :user_agent `String` the `User-Agent` header and `navigator.userAgent`
Expand Down
26 changes: 0 additions & 26 deletions lib/ferrum/accessibility.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,32 +105,6 @@ def enabled=(enabled)
@page.command(enabled ? "Accessibility.enable" : "Accessibility.disable")
end

#
# @deprecated Will be removed in Ferrum 0.22. Use `enabled = true`.
#
# @return [self]
#
# @raise [TimeoutError]
#
def enable
Utils::Deprecate.warn("accessibility.enable will be removed in Ferrum 0.22. Use enabled = true instead.",
user_code: true)
tap { self.enabled = true }
end

#
# @deprecated Will be removed in Ferrum 0.22. Use `enabled = false`.
#
# @return [self]
#
# @raise [TimeoutError]
#
def disable
Utils::Deprecate.warn("accessibility.disable will be removed in Ferrum 0.22. Use enabled = false instead.",
user_code: true)
tap { self.enabled = false }
end

private

def build(nodes)
Expand Down
33 changes: 8 additions & 25 deletions lib/ferrum/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,28 @@ class Browser
extend Forwardable

delegate %i[default_context] => :contexts
delegate %i[targets create_target page pages windows await_page await_page! workers service_workers
delegate %i[targets create_target page pages await_page await_page! workers service_workers
attach_target cookies] => :default_context
delegate %i[go_to go_to! goto go back back! forward forward! refresh refresh! reload reload! stop
delegate %i[go_to go_to! back back! forward forward! refresh refresh! stop
await_navigation await_navigation! await_download await_download! wait_until wait_until!
wait_for_reload wait_for_navigation wait_for_navigation!
at_css at_xpath css xpath wait_css wait_css! wait_xpath wait_xpath! wait_for_selector
current_url current_title url title
html body doctype content=
at_css at_xpath css xpath wait_css wait_css! wait_xpath wait_xpath!
url title html doctype content=
headers network console accessibility downloads tracing
mouse keyboard
screenshot pdf mhtml viewport_size device_pixel_ratio document_size
start_screencast stop_screencast
frames frame_by main_frame
evaluate evaluate_handle execute isolated_world
add_script_tag add_style_tag bypass_csp bypass_csp=
add_script_tag add_style_tag bypass_csp=
evaluate_on_new_document remove_script_on_new_document
on off position position= window_bounds window_bounds= activate
playback_rate playback_rate=
disable_javascript javascript= javascript? set_viewport resize] => :page
javascript= javascript? set_viewport resize] => :page

attr_reader :client, :process, :contexts, :options

delegate %i[timeout timeout= protocol_timeout protocol_timeout= base_url base_url= default_user_agent
default_user_agent= extensions add_extension] => :options
delegate %i[timeout timeout= base_url base_url= default_user_agent default_user_agent= extensions
add_extension] => :options

#
# Initializes the browser.
Expand All @@ -70,11 +68,6 @@ class Browser
# @option options [Boolean] :xvfb (false)
# Run browser in a virtual framebuffer.
#
# @option options [Boolean] :flatten (true)
# Use one websocket connection to the browser and all the pages in flatten mode.
# Passing `false` is deprecated, the option will be removed in Ferrum 0.22
# and every page will share the browser's connection.
#
# @option options [(Integer, Integer)] :window_size ([1024, 768])
# The dimensions of the browser window in which to test, expressed as a
# 2-element array, e.g. `[1024, 768]`.
Expand All @@ -98,16 +91,6 @@ class Browser
# `FERRUM_DEFAULT_TIMEOUT` sets the default. Pass `timeout:` to `go_to`, `refresh` or `await_navigation` to
# change it for one call, or wrap calls in {Deadline.within} to bound them together.
#
# @option options [Boolean] :js_errors
# Deprecated, will be removed in Ferrum 0.22. When true, JavaScript
# errors get re-raised in Ruby. Uncaught exceptions are in the console,
# use `page.console.select { |m| m.source == :exception }` or
# `page.on(:console)` instead.
#
# @option options [Boolean] :pending_connection_errors (false)
# Deprecated, will be removed in Ferrum 0.22. Makes `go_to` raise
# {PendingConnectionsError} on timeout, use `go_to!` instead.
#
# @option options [String] :browser_path
# Path to Chrome binary, you can also set ENV variable as
# `BROWSER_PATH=some/path/chrome bundle exec rspec`.
Expand Down
68 changes: 3 additions & 65 deletions lib/ferrum/browser/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,11 @@ class Options
DEFAULT_TIMEOUT = ENV.fetch("FERRUM_DEFAULT_TIMEOUT", 5).to_f
PROCESS_TIMEOUT = ENV.fetch("FERRUM_PROCESS_TIMEOUT", 10).to_i

PROTOCOL_TIMEOUT_REMOVED = "is ignored and will be removed in Ferrum 0.22. Internal commands have a fixed " \
"timeout, :timeout bounds everything else."

if ENV.key?("FERRUM_DEBUG")
Utils::Deprecate.warn("FERRUM_DEBUG will be removed in Ferrum 0.22. Use FERRUM_LOG=* instead.")
end
if ENV.key?("FERRUM_PROTOCOL_TIMEOUT")
Utils::Deprecate.warn("FERRUM_PROTOCOL_TIMEOUT #{PROTOCOL_TIMEOUT_REMOVED}")
end

attr_reader :window_size, :logger, :log, :ws_max_receive_size,
:js_errors, :base_url, :slowmo, :pending_connection_errors,
:base_url, :slowmo,
:url, :ws_url, :env, :process_timeout, :browser_path,
:save_path, :proxy, :port, :host, :headless, :incognito, :dockerize, :browser_options,
:ignore_default_browser_options, :xvfb, :flatten, :extensions
:ignore_default_browser_options, :xvfb, :extensions
attr_accessor :timeout, :default_user_agent

def initialize(options = nil)
Expand All @@ -41,21 +31,10 @@ def initialize(options = nil)
@port = @options.fetch(:port, BROWSER_PORT)
@host = @options.fetch(:host, BROWSER_HOST)
@timeout = @options.fetch(:timeout, DEFAULT_TIMEOUT)
warn_protocol_timeout if @options.key?(:protocol_timeout)
@window_size = @options.fetch(:window_size, WINDOW_SIZE)
@js_errors = fetch_deprecated(
:js_errors,
"Uncaught exceptions are in the console, use page.console.select { |m| m.source == :exception } " \
"or page.on(:console)."
)
@headless = @options.fetch(:headless, true)
@incognito = @options.fetch(:incognito, true)
@dockerize = @options.fetch(:dockerize, false)
@flatten = @options.fetch(:flatten, true)
warn_flatten unless @flatten
@pending_connection_errors = fetch_deprecated(
:pending_connection_errors, "Use page.go_to!(url) to raise when the page doesn't load in time."
)
@process_timeout = @options.fetch(:process_timeout, PROCESS_TIMEOUT)
@slowmo = @options[:slowmo].to_f

Expand All @@ -77,29 +56,6 @@ def initialize(options = nil)
@browser_options = @options.fetch(:browser_options, {}).freeze
end

#
# Deprecated, will be removed in Ferrum 0.22. Internal commands have a fixed timeout.
#
# @return [Integer]
# {Client::PROTOCOL_TIMEOUT}.
#
def protocol_timeout
warn_protocol_timeout
Client::PROTOCOL_TIMEOUT
end

#
# Deprecated, will be removed in Ferrum 0.22. The value is ignored.
#
# @param [Numeric] value
#
# @return [Numeric]
#
def protocol_timeout=(value)
warn_protocol_timeout
value
end

#
# Sets the base URL relative navigations are resolved against.
#
Expand Down Expand Up @@ -168,30 +124,12 @@ def to_h

private

def warn_protocol_timeout
Utils::Deprecate.warn(":protocol_timeout #{PROTOCOL_TIMEOUT_REMOVED}", user_code: true)
end

def warn_flatten
Utils::Deprecate.warn(
"flatten: false will be removed in Ferrum 0.22. Every page will share the browser's websocket connection.",
user_code: true
)
end

def fetch_deprecated(name, instead)
return false unless @options.key?(name)

Utils::Deprecate.warn(":#{name} will be removed in Ferrum 0.22. #{instead}", user_code: true)
@options[name]
end

def read_extension(extension)
(extension.is_a?(Hash) && extension[:source]) || File.read(extension)
end

def parse_logger(logger)
value = ENV.fetch("FERRUM_LOG") { "*" if ENV.key?("FERRUM_DEBUG") }
value = ENV.fetch("FERRUM_LOG", nil)
settings = value ? Log.parse(value) : {}
logger ||= $stdout.tap { |s| s.sync = true } if value && settings
return [logger, nil] unless logger && settings
Expand Down
Loading
Loading