Class: Charai::BrowsingContext::Realm
- Inherits:
-
Object
- Object
- Charai::BrowsingContext::Realm
- Defined in:
- lib/charai/browsing_context.rb
Defined Under Namespace
Classes: ScriptEvaluationError
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #_with_injected_script(&block) ⇒ Object
-
#initialize(browsing_context:, id:, origin:, type: nil) ⇒ Realm
constructor
A new instance of Realm.
- #script_call_function(function_declaration, arguments: [], as_handle: false) ⇒ Object
- #script_evaluate(expression, as_handle: false) ⇒ Object
Constructor Details
#initialize(browsing_context:, id:, origin:, type: nil) ⇒ Realm
Returns a new instance of Realm.
137 138 139 140 141 142 |
# File 'lib/charai/browsing_context.rb', line 137 def initialize(browsing_context:, id:, origin:, type: nil) @browsing_context = browsing_context @id = id @origin = origin @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
196 197 198 |
# File 'lib/charai/browsing_context.rb', line 196 def type @type end |
Instance Method Details
#_with_injected_script(&block) ⇒ Object
190 191 192 193 194 |
# File 'lib/charai/browsing_context.rb', line 190 def _with_injected_script(&block) raise ArgumentError, "block is required" unless block_given? @injected_script ||= _new_injected_script block.call(@injected_script) end |
#script_call_function(function_declaration, arguments: [], as_handle: false) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/charai/browsing_context.rb', line 166 def script_call_function(function_declaration, arguments: [], as_handle: false) args = arguments.map do |arg| serialize(arg) end result = @browsing_context.send(:bidi_call_async, 'script.callFunction', { functionDeclaration: function_declaration, arguments: args, target: { realm: @id }, resultOwnership: as_handle ? 'root' : 'none', awaitPromise: true, userActivation: true, }).value! if result['type'] == 'exception' raise ScriptEvaluationError, result['exceptionDetails']['text'] end if as_handle Handle.new(result['result']['handle']) else deserialize(result['result']) end end |
#script_evaluate(expression, as_handle: false) ⇒ Object
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/charai/browsing_context.rb', line 146 def script_evaluate(expression, as_handle: false) result = @browsing_context.send(:bidi_call_async, 'script.evaluate', { expression: expression, target: { realm: @id }, resultOwnership: as_handle ? 'root' : 'none', awaitPromise: true, userActivation: true, }).value! if result['type'] == 'exception' raise ScriptEvaluationError, result['exceptionDetails']['text'] end if as_handle Handle.new(result['result']['handle']) else deserialize(result['result']) end end |