diff --git a/lib/ferrum/frame/runtime.rb b/lib/ferrum/frame/runtime.rb index 48752138..3a0079e4 100644 --- a/lib/ferrum/frame/runtime.rb +++ b/lib/ferrum/frame/runtime.rb @@ -158,7 +158,13 @@ def handle_response(response) # `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) + node = Node.new(self, @page.target_id, node_id, description) + + # Ensure node has not been disconnected between execution and + # response handling (addresses timing issues). + raise NodeNotFoundError, "Node is disconnected" unless node.evaluate('this.isConnected') + + node when "array" reduce_props(object_id, []) do |memo, key, value| next(memo) unless Integer(key, exception: false)