Skip to content
Open
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 Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gem "rspec", "~> 3.8"
gem "rspec-wait"
gem "rubocop", "~> 1.22"
gem "rubocop-rake", require: false
gem "sinatra", "~> 3.2"
gem "sinatra", "~> 4.0"
gem "yard", "~> 0.9", require: false

gemspec
9 changes: 2 additions & 7 deletions lib/ferrum/frame/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,8 @@ def handle_response(response)

case response["subtype"]
when "node"
# We cannot store object_id in the node because page can be reloaded
# and node destroyed so we need to retrieve it each time for given id.
# Though we can try to subscribe to `DOM.childNodeRemoved` and
# `DOM.childNodeInserted` in the future.
node_id = @page.command("DOM.requestNode", objectId: object_id)["nodeId"]
description = @page.command("DOM.describeNode", nodeId: node_id)["node"]
Node.new(self, @page.target_id, node_id, description)
description = @page.command("DOM.describeNode", objectId: object_id)["node"]
Node.new(self, @page.target_id, description, object_id: object_id)
when "array"
reduce_props(object_id, []) do |memo, key, value|
next(memo) unless Integer(key, exception: false)
Expand Down
20 changes: 17 additions & 3 deletions lib/ferrum/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,28 @@ class Node
MOVING_WAIT_DELAY = ENV.fetch("FERRUM_NODE_MOVING_WAIT", 0.01).to_f
MOVING_WAIT_ATTEMPTS = ENV.fetch("FERRUM_NODE_MOVING_ATTEMPTS", 50).to_i

attr_reader :page, :target_id, :node_id, :description, :tag_name
attr_reader :page, :target_id, :description, :tag_name

def initialize(frame, target_id, node_id, description)
def initialize(frame, target_id, description, object_id: nil, node_id: nil)
@page = frame.page
@target_id = target_id
@node_id = node_id
@description = description
@tag_name = description["nodeName"].downcase
@object_id = object_id
@node_id = node_id
end

# Frontend nodeId is resolved lazily, on first actual need (focus, click, scroll_into_view, etc.)
# Though we can try to subscribe to `DOM.childNodeRemoved` and `DOM.childNodeInserted` in the future.
def node_id
@node_id ||= begin
id = page.command("DOM.requestNode", objectId: @object_id)["nodeId"]
raise NodeNotFoundError, "node is not trackable" if id.zero?

id
rescue NoExecutionContextError
raise NodeNotFoundError, "node is not trackable"
end
end

def node?
Expand Down
2 changes: 1 addition & 1 deletion lib/ferrum/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def subscribe
def prepare_page
command("Page.enable")
command("Runtime.enable")
command("DOM.enable")
command("DOM.enable", includeWhitespace: "all")
command("CSS.enable")
command("Log.enable")
command("Network.enable")
Expand Down
7 changes: 5 additions & 2 deletions sig/ferrum/node.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module Ferrum

MOVING_WAIT_ATTEMPTS: untyped

@node_id: untyped
@object_id: untyped

attr_reader page: untyped

attr_reader target_id: untyped

attr_reader node_id: untyped

attr_reader description: untyped

attr_reader tag_name: untyped
Expand All @@ -26,6 +27,8 @@ module Ferrum

def focusable?: () -> untyped

def node_id: -> untyped

def wait_for_stop_moving: (?delay: untyped, ?attempts: untyped) -> untyped

def moving?: (?delay: untyped) -> untyped
Expand Down
Loading