Class: Ferrum::RemoteObject
- Inherits:
-
Object
- Object
- Ferrum::RemoteObject
- Includes:
- Evaluatable
- Defined in:
- lib/ferrum/remote_object.rb,
sig/ferrum/remote_object.rbs
Overview
An opaque reference to a JavaScript value living in the browser, returned by Frame::Runtime#evaluate_handle. Unlike Frame::Runtime#evaluate, which serializes the result into Ruby, a handle keeps the value in the page so it can be passed straight back into a later evaluation without a round trip through JSON.
Instance Attribute Summary collapse
-
#description ⇒ String?
readonly
The browser's own description of the value.
-
#remote_id ⇒ String
readonly
The CDP remote object id.
-
#subtype ⇒ String?
readonly
The JavaScript subtype, e.g.
-
#type ⇒ String
readonly
The JavaScript type, e.g.
Instance Method Summary collapse
-
#initialize(runtime, page, result) ⇒ RemoteObject
constructor
A new instance of RemoteObject.
- #inspect ⇒ String
-
#release ⇒ void
Releases the browser-side reference.
-
#value ⇒ Object
Serializes the handle into a plain Ruby value, resolving nodes into Node objects the same way Frame::Runtime#evaluate does.
Methods included from Evaluatable
#evaluate, #evaluate_handle, #execute
Constructor Details
#initialize(runtime, page, result) ⇒ RemoteObject
Returns a new instance of RemoteObject.
43 44 45 46 47 48 49 50 |
# File 'lib/ferrum/remote_object.rb', line 43 def initialize(runtime, page, result) @runtime = runtime @page = page @remote_id = result["objectId"] @type = result["type"] @subtype = result["subtype"] @description = result["description"] end |
Instance Attribute Details
#description ⇒ String? (readonly)
Returns the browser's own description of the value.
31 32 33 |
# File 'lib/ferrum/remote_object.rb', line 31 def description @description end |
#remote_id ⇒ String (readonly)
Returns the CDP remote object id.
22 23 24 |
# File 'lib/ferrum/remote_object.rb', line 22 def remote_id @remote_id end |
#subtype ⇒ String? (readonly)
Returns the JavaScript subtype, e.g. "array" or "map".
28 29 30 |
# File 'lib/ferrum/remote_object.rb', line 28 def subtype @subtype end |
#type ⇒ String (readonly)
Returns the JavaScript type, e.g. "object" or "function".
25 26 27 |
# File 'lib/ferrum/remote_object.rb', line 25 def type @type end |
Instance Method Details
#inspect ⇒ String
79 80 81 82 |
# File 'lib/ferrum/remote_object.rb', line 79 def inspect %(#<#{self.class} @remote_id=#{@remote_id.inspect} @type=#{@type.inspect} ) + %(@subtype=#{@subtype.inspect} @description=#{@description.inspect}>) end |
#release ⇒ void
This method returns an undefined value.
Releases the browser-side reference. The handle is unusable afterwards.
71 72 73 74 75 76 |
# File 'lib/ferrum/remote_object.rb', line 71 def release @page.command("Runtime.releaseObject", objectId: @remote_id) nil rescue Ferrum::BrowserError nil end |
#value ⇒ Object
Serializes the handle into a plain Ruby value, resolving nodes into Node objects the same way Frame::Runtime#evaluate does.
60 61 62 |
# File 'lib/ferrum/remote_object.rb', line 60 def value evaluate("this") end |