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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Changed
- `Driver#current_url` and `Driver#title` read Ferrum's `url` and `title` of the window, not `current_url` and
`current_title` deprecated in Ferrum 0.21 [rubycdp/ferrum#687]
- `:js_errors` is handled by Cuprite instead of being passed to Ferrum, which deprecates it. Behavior is the same
[rubycdp/ferrum#688]

### Fixed

Expand Down
4 changes: 3 additions & 1 deletion docs/2-customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ end
```

Cuprite accepts all [Ferrum options](/docs/ferrum/customization), such as
`:headless`, `:timeout`, `:js_errors`, `:browser_path`, `:browser_options`,
`:headless`, `:timeout`, `:browser_path`, `:browser_options`,
`:url`, `:proxy`, `:dockerize` and others.

Cuprite-specific options are:

* options `Hash`
* `:js_errors` (Boolean) - Re-raise JavaScript errors from the page as `Ferrum::JavaScriptError` in Ruby, `false`
by default. See [JavaScript errors](/docs/cuprite/javascript#javascript-errors).
* `:screen_size` (Array) - Size used by `maximize_window`, `[1366, 768]` by default.
* `:raise_on_unhandled_modal` (Boolean) - What to do when a JavaScript dialog is opened but not handled by
`accept_*`/`dismiss_*`. When `false` (default) a warning is printed, when `true`
Expand Down
3 changes: 2 additions & 1 deletion lib/capybara/cuprite/browser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ class Browser < Ferrum::Browser
def initialize(options = nil)
device = options&.dig(:emulate)
options = Devices.fetch(device).except(:user_agent).merge(options) if device
super
super(options&.except(:js_errors))

@options.raise_on_js_errors = options&.dig(:js_errors)
@options.raise_on_unhandled_modal = options&.dig(:raise_on_unhandled_modal)
@options.url_blacklist = prepare_wildcards(options&.dig(:url_blacklist))
@options.url_whitelist = prepare_wildcards(options&.dig(:url_whitelist))
Expand Down
2 changes: 1 addition & 1 deletion lib/capybara/cuprite/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ferrum
class Browser
class Options
attr_writer :window_size
attr_accessor :url_blacklist, :url_whitelist, :raise_on_unhandled_modal
attr_accessor :url_blacklist, :url_whitelist, :raise_on_unhandled_modal, :raise_on_js_errors

def mobile
@options.fetch(:mobile, nil)
Expand Down
9 changes: 9 additions & 0 deletions lib/capybara/cuprite/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ def set_viewport(width: 0, height: 0, scale_factor: @options.scale_factor, mobil

private

def subscribe
super
return unless @options.raise_on_js_errors

on("Runtime.exceptionThrown") do |params|
Thread.main.raise Ferrum::JavaScriptError, params["exceptionDetails"]
end
end

def prepare_page
super
execute(EXTENSION_JS)
Expand Down
Loading