diff --git a/CHANGELOG.md b/CHANGELOG.md index 98747fec..cbb4ddfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ `page.on(:console)` instead - `:pending_connection_errors` and `PendingConnectionsError`, will be removed in 0.22. Pass `on_timeout: :raise` to `go_to` instead +- `flatten: false`, the option will be removed in 0.22 and every page will share the browser's websocket connection - `FERRUM_DEBUG`, will be removed in 0.22. Use `FERRUM_LOG=*` instead - `:protocol_timeout`, `browser.protocol_timeout`, `browser.protocol_timeout=` and `FERRUM_PROTOCOL_TIMEOUT`, will be removed in 0.22. They are ignored and warn, `:timeout` bounds everything else diff --git a/docs/2-customization.md b/docs/2-customization.md index 89fb864a..ca398da4 100644 --- a/docs/2-customization.md +++ b/docs/2-customization.md @@ -17,7 +17,7 @@ Ferrum::Browser.new(options) * `: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. + 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 diff --git a/lib/ferrum/browser.rb b/lib/ferrum/browser.rb index fe03ae3e..6d62b018 100644 --- a/lib/ferrum/browser.rb +++ b/lib/ferrum/browser.rb @@ -70,6 +70,8 @@ class Browser # # @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 diff --git a/lib/ferrum/browser/options.rb b/lib/ferrum/browser/options.rb index 7da0b7c8..c77928b7 100644 --- a/lib/ferrum/browser/options.rb +++ b/lib/ferrum/browser/options.rb @@ -52,6 +52,7 @@ def initialize(options = nil) @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, "Pass on_timeout: :raise to go_to instead: page.go_to(url, on_timeout: :raise)." ) @@ -171,6 +172,13 @@ 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) diff --git a/sig/ferrum/browser/options.rbs b/sig/ferrum/browser/options.rbs index 4b53f42b..2385dea1 100644 --- a/sig/ferrum/browser/options.rbs +++ b/sig/ferrum/browser/options.rbs @@ -61,7 +61,7 @@ module Ferrum attr_reader incognito: bool - attr_reader flatten: bool + %a{deprecated} attr_reader flatten: bool attr_reader ignore_default_browser_options: bool? @@ -113,6 +113,8 @@ module Ferrum def warn_protocol_timeout: () -> void + def warn_flatten: () -> void + def fetch_deprecated: (Symbol name, String instead) -> bool def read_extension: (String | Hash[Symbol, String] extension) -> String diff --git a/spec/unit/browser/options_spec.rb b/spec/unit/browser/options_spec.rb index 7d59804f..9f80c241 100644 --- a/spec/unit/browser/options_spec.rb +++ b/spec/unit/browser/options_spec.rb @@ -11,6 +11,15 @@ expect { described_class.new(protocol_timeout: 10) } .to output(/:protocol_timeout is ignored.*called from #{__FILE__}/m).to_stderr end + + it "warns that flatten: false will be removed" do + expect { described_class.new(flatten: false) } + .to output(/flatten: false will be removed in Ferrum 0.22.*called from #{__FILE__}/m).to_stderr + end + + it "stays silent when :flatten is true" do + expect { described_class.new(flatten: true) }.not_to output.to_stderr + end end describe "#protocol_timeout" do