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 @@ -34,6 +34,8 @@
`go_to` instead

### Fixed
- `evaluate` of a result nested about 100 levels deep raised an opaque `BrowserError` about Chrome's CBOR stack limit,
it raises `ResultTooDeepError` now, a `BrowserError` that says to return less or use `evaluate_handle`
- `worker.close` never closed a dedicated worker, Chrome refuses to close it from outside, it closes itself now
- `page.on(:request, &:continue)` never continued the request, it called `continue(index, total)` and the error was
dropped. Symbol procs and lambdas taking one argument get only the object now, for `:request`, `:response`, `:auth`
Expand Down
9 changes: 9 additions & 0 deletions lib/ferrum/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,15 @@ def data
end
end

# Raised when an evaluated script returns a value nested too deeply for
# Chrome to serialize, around 100 levels.
class ResultTooDeepError < BrowserError
def initialize(response)
super(response.merge("message" => "The result is nested too deeply to be serialized, return less of it or " \
"use evaluate_handle"))
end
end

# Raised when the browser reports that a DOM node no longer exists.
class NodeNotFoundError < BrowserError; end

Expand Down
10 changes: 10 additions & 0 deletions lib/ferrum/frame/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ def call_function(declaration, values, target, serialization, timeout)
functionDeclaration: declaration, arguments: prepare_args(values), **target)
rescue TimeoutError
raise ScriptTimeoutError
rescue BrowserError => e
raise_deep_error(e)
end

# A promise, or a plain object that may be one, such as the promises of
Expand All @@ -380,6 +382,14 @@ def await_promise(promise, serialization, timeout)
response["result"]
rescue TimeoutError
raise ScriptTimeoutError
rescue BrowserError => e
raise_deep_error(e)
end

def raise_deep_error(error)
raise error unless error.message.to_s.include?("CBOR: stack limit exceeded")

raise ResultTooDeepError, error.response
end

def call_target(on)
Expand Down
4 changes: 4 additions & 0 deletions sig/ferrum/errors.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ module Ferrum
def data: () -> untyped
end

class ResultTooDeepError < BrowserError
def initialize: (Hash[String, untyped] response) -> void
end

class NodeNotFoundError < BrowserError
end

Expand Down
2 changes: 2 additions & 0 deletions sig/ferrum/frame/runtime.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ module Ferrum

def handle_remote_object: (untyped result) -> untyped

def raise_deep_error: (BrowserError error) -> bot

def handle_response: (Hash[String, untyped] response) -> untyped

def deserialize: (Hash[String, untyped] serialized, ?Hash[Integer, Hash[String, untyped]] references, ?Array[Integer] path, ?Hash[Integer, untyped] converted) -> untyped
Expand Down
6 changes: 6 additions & 0 deletions spec/frame/runtime_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,12 @@
end
end

it "raises ResultTooDeepError for a result nested over Chrome's limit" do
code = "(() => { let o = {}; let c = o; for (let i = 0; i < 200; i++) { c.a = {}; c = c.a } return o })()"

expect { browser.evaluate(code) }.to raise_error(Ferrum::ResultTooDeepError, /nested too deeply/)
end

context "with a cyclic structure" do
let(:cyclic) { Ferrum::CyclicObject.instance }

Expand Down
Loading