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.
45 46 47 48 49 |
# File 'lib/puppeteer/execution_context.rb', line 45 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/puppeteer/execution_context.rb', line 54 def evaluate_with(client:, context_id:) result = begin client.('Runtime.evaluate', expression: expression_with_source_url, contextId: context_id, returnByValue: @return_by_value, awaitPromise: true, userGesture: true, ) rescue Puppeteer::Connection::ProtocolError => err raise @execution_context.send(:rewrite_evaluation_error, err) end # }).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 |