11# frozen_string_literal: true
22
33module Ferrum
4- class Page
4+ class Frame
55 module Runtime
66 INTERMITTENT_ATTEMPTS = ENV . fetch ( "FERRUM_INTERMITTENT_ATTEMPTS" , 6 ) . to_i
77 INTERMITTENT_SLEEP = ENV . fetch ( "FERRUM_INTERMITTENT_SLEEP" , 0.1 ) . to_f
@@ -49,13 +49,13 @@ def evaluate_on(node:, expression:, by_value: true, wait: 0)
4949 attempts , sleep = INTERMITTENT_ATTEMPTS , INTERMITTENT_SLEEP
5050
5151 Ferrum . with_attempts ( errors : errors , max : attempts , wait : sleep ) do
52- response = command ( "DOM.resolveNode" , nodeId : node . node_id )
52+ response = @page . command ( "DOM.resolveNode" , nodeId : node . node_id )
5353 object_id = response . dig ( "object" , "objectId" )
5454 options = DEFAULT_OPTIONS . merge ( objectId : object_id )
5555 options [ :functionDeclaration ] = options [ :functionDeclaration ] % expression
5656 options . merge! ( returnByValue : by_value )
5757
58- response = command ( "Runtime.callFunctionOn" ,
58+ response = @page . command ( "Runtime.callFunctionOn" ,
5959 wait : wait , **options ) [ "result" ]
6060 . tap { |r | handle_error ( r ) }
6161
@@ -76,10 +76,10 @@ def call(*args, expression:, wait_time: nil, handle: true, **options)
7676 params [ :functionDeclaration ] = params [ :functionDeclaration ] % expression
7777 params = params . merge ( arguments : arguments )
7878 unless params [ :executionContextId ]
79- params = params . merge ( executionContextId : execution_context_id )
79+ params = params . merge ( executionContextId : execution_id )
8080 end
8181
82- response = command ( "Runtime.callFunctionOn" ,
82+ response = @page . command ( "Runtime.callFunctionOn" ,
8383 **params ) [ "result" ] . tap { |r | handle_error ( r ) }
8484
8585 handle ? handle_response ( response ) : response
@@ -115,9 +115,9 @@ def handle_response(response)
115115 # and node destroyed so we need to retrieve it each time for given id.
116116 # Though we can try to subscribe to `DOM.childNodeRemoved` and
117117 # `DOM.childNodeInserted` in the future.
118- node_id = command ( "DOM.requestNode" , objectId : object_id ) [ "nodeId" ]
119- description = command ( "DOM.describeNode" , nodeId : node_id ) [ "node" ]
120- Node . new ( self , target_id , node_id , description )
118+ node_id = @page . command ( "DOM.requestNode" , objectId : object_id ) [ "nodeId" ]
119+ description = @page . command ( "DOM.describeNode" , nodeId : node_id ) [ "node" ]
120+ Node . new ( self , @page . target_id , node_id , description )
121121 when "array"
122122 reduce_props ( object_id , [ ] ) do |memo , key , value |
123123 next ( memo ) unless ( Integer ( key ) rescue nil )
@@ -140,7 +140,7 @@ def handle_response(response)
140140 def prepare_args ( args )
141141 args . map do |arg |
142142 if arg . is_a? ( Node )
143- resolved = command ( "DOM.resolveNode" , nodeId : arg . node_id )
143+ resolved = @page . command ( "DOM.resolveNode" , nodeId : arg . node_id )
144144 { objectId : resolved [ "object" ] [ "objectId" ] }
145145 elsif arg . is_a? ( Hash ) && arg [ "objectId" ]
146146 { objectId : arg [ "objectId" ] }
@@ -154,7 +154,7 @@ def reduce_props(object_id, to)
154154 if cyclic? ( object_id ) . dig ( "result" , "value" )
155155 return "(cyclic structure)"
156156 else
157- props = command ( "Runtime.getProperties" , objectId : object_id )
157+ props = @page . command ( "Runtime.getProperties" , objectId : object_id )
158158 props [ "result" ] . reduce ( to ) do |memo , prop |
159159 next ( memo ) unless prop [ "enumerable" ]
160160 yield ( memo , prop [ "name" ] , prop [ "value" ] )
@@ -163,7 +163,7 @@ def reduce_props(object_id, to)
163163 end
164164
165165 def cyclic? ( object_id )
166- command ( "Runtime.callFunctionOn" ,
166+ @page . command ( "Runtime.callFunctionOn" ,
167167 objectId : object_id ,
168168 returnByValue : true ,
169169 functionDeclaration : <<~JS
0 commit comments