Class: Puppeteer::ExecutionContext::JavaScriptExpression
- Inherits:
-
Object
- Object
- Puppeteer::ExecutionContext::JavaScriptExpression
- Defined in:
- lib/puppeteer/execution_context.rb
Instance Method Summary collapse
- #evaluate_with(client:, context_id:) ⇒ Object|JSHandle
-
#initialize(execution_context, expression, return_by_value) ⇒ JavaScriptExpression
constructor
A new instance of JavaScriptExpression.
Constructor Details
#initialize(execution_context, expression, return_by_value) ⇒ JavaScriptExpression
Returns a new instance of JavaScriptExpression.
44 45 46 47 48 |
# File 'lib/puppeteer/execution_context.rb', line 44 def initialize(execution_context, expression, return_by_value) @execution_context = execution_context @expression = expression @return_by_value = return_by_value end |
Instance Method Details
#evaluate_with(client:, context_id:) ⇒ Object|JSHandle
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/puppeteer/execution_context.rb', line 53 def evaluate_with(client:, context_id:) result = client.('Runtime.evaluate', expression: expression_with_source_url, contextId: context_id, returnByValue: @return_by_value, awaitPromise: true, userGesture: true, ) # }).catch(rewriteError); exception_details = result['exceptionDetails'] if exception_details raise EvaluationError.new("Evaluation failed: #{exception_details}") end remote_object = Puppeteer::RemoteObject.new(result['result']) if @return_by_value remote_object.value else Puppeteer::JSHandle.create( context: @execution_context, remote_object: remote_object, ) end end |