Module: Obxcura::Frame::Runtime
- Included in:
- Obxcura::Frame
- Defined in:
- lib/obxcura/frame/runtime.rb
Overview
Runtime: executing JavaScript in the frame's context. This is the side that reaches the Client and puts CDP commands on the wire; everything in DOM is built on top of #evaluate.
Ruby values cross into JS as real arguments (Runtime.callFunctionOn), not by being string-interpolated into source. Node-handle resolution, cyclic-node detection and a retry loop are deliberately left out.
Instance Method Summary collapse
-
#call_on(object_id, function_declaration, args = [], timeout: nil) ⇒ Object?
Call a function declaration bound to a specific remote object (its
this). -
#evaluate(expression, *args) ⇒ Object?
Evaluate a JS expression and return its value (awaits promises).
-
#evaluate_func(expression, *args, timeout: nil) ⇒ Object?
Call a JS function declaration with the given arguments, bound to the live global object.
Instance Method Details
#call_on(object_id, function_declaration, args = [], timeout: nil) ⇒ Object?
Call a function declaration bound to a specific remote object (its this).
Used by #evaluate_func (bound to globalThis) and by Node reads (bound
to the node's handle).
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/obxcura/frame/runtime.rb', line 57 def call_on(object_id, function_declaration, args = [], timeout: nil) handle_result(command( "Runtime.callFunctionOn", { functionDeclaration: function_declaration, objectId: object_id, arguments: args.map { |value| { value: value } }, awaitPromise: true, returnByValue: true }, timeout: timeout )) end |
#evaluate(expression, *args) ⇒ Object?
Evaluate a JS expression and return its value (awaits promises).
Extra args are passed to the page as real values, reachable in the
expression as arguments[0], arguments[1], ... Without args it's a
single Runtime.evaluate (the hot path); with args it goes through
Runtime.callFunctionOn so nothing is interpolated into source.
26 27 28 29 30 |
# File 'lib/obxcura/frame/runtime.rb', line 26 def evaluate(expression, *args) return handle_result(evaluate_command(expression)) if args.empty? evaluate_func("function() { return (#{expression}); }", *args) end |
#evaluate_func(expression, *args, timeout: nil) ⇒ Object?
Call a JS function declaration with the given arguments, bound to the live
global object. Unlike #evaluate, expression is the function itself.
42 43 44 |
# File 'lib/obxcura/frame/runtime.rb', line 42 def evaluate_func(expression, *args, timeout: nil) call_on(global_object_id, expression, args, timeout: timeout) end |