Class: Puppeteer::Bidi::Core::Realm
- Inherits:
-
EventEmitter
- Object
- EventEmitter
- Puppeteer::Bidi::Core::Realm
- Includes:
- Disposable::DisposableMixin
- Defined in:
- lib/puppeteer/bidi/core/realm.rb,
sig/puppeteer/bidi/core/realm.rbs
Overview
Realm is the base class for script execution realms
Direct Known Subclasses
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#origin ⇒ Object
readonly
Returns the value of attribute origin.
Instance Method Summary collapse
-
#call_function(function_declaration, await_promise, **options) ⇒ Async::Task[Hash[String, untyped]]
Call a function in the realm.
-
#disown(handles) ⇒ Async::Task[untyped]
Disown handles (remove references).
-
#dispose ⇒ void
Emit :destroyed before EventEmitter is marked as disposed so Realm consumers can terminate their pending tasks.
-
#evaluate(expression, await_promise, **options) ⇒ Async::Task[Hash[String, untyped]]
Evaluate an expression in the realm.
-
#initialize(id, origin) ⇒ Realm
constructor
A new instance of Realm.
- #perform_dispose ⇒ Object
-
#resolve_execution_context_id ⇒ Integer
Resolve the CDP execution context ID for this realm.
-
#session ⇒ Session
Abstract method - must be implemented by subclasses.
-
#target ⇒ Hash[Symbol, untyped]
Get the target for script execution.
Methods included from Disposable::DisposableMixin
Methods inherited from EventEmitter
#disposed?, #emit, #off, #on, #once, #remove_all_listeners
Constructor Details
#initialize(id, origin) ⇒ Realm
Returns a new instance of Realm.
13 14 15 16 17 18 19 20 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 13 def initialize(id, origin) super() @id = id @origin = origin @reason = nil @execution_context_id = nil @disposables = Disposable::DisposableStack.new end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
11 12 13 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 11 def id @id end |
#origin ⇒ Object (readonly)
Returns the value of attribute origin.
11 12 13 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 11 def origin @origin end |
Instance Method Details
#call_function(function_declaration, await_promise, **options) ⇒ Async::Task[Hash[String, untyped]]
Call a function in the realm
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 44 def call_function(function_declaration, await_promise, **) raise RealmDestroyedError, @reason if disposed? = .dup [:userActivation] = true unless .key?(:userActivation) || .key?("userActivation") # Note: In Puppeteer, returnByValue controls serialization, not awaitPromise # awaitPromise controls whether to wait for promises # For BiDi, we use 'root' ownership by default to keep handles alive # Only use 'none' if explicitly requested params = { functionDeclaration: function_declaration, awaitPromise: await_promise, target: target, resultOwnership: 'root', ** } session.async_send_command('script.callFunction', params) end |
#disown(handles) ⇒ Async::Task[untyped]
Disown handles (remove references)
31 32 33 34 35 36 37 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 31 def disown(handles) raise RealmDestroyedError, @reason if disposed? session.async_send_command('script.disown', { target: target, handles: handles }) end |
#dispose ⇒ void
This method returns an undefined value.
Emit :destroyed before EventEmitter is marked as disposed so Realm consumers can terminate their pending tasks.
101 102 103 104 105 106 107 108 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 101 def dispose return if disposed? @reason ||= "Realm already destroyed, probably because all associated browsing contexts closed." emit(:destroyed, @reason) super end |
#evaluate(expression, await_promise, **options) ⇒ Async::Task[Hash[String, untyped]]
Evaluate an expression in the realm
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 70 def evaluate(expression, await_promise, **) raise RealmDestroyedError, @reason if disposed? = .dup [:userActivation] = true unless .key?(:userActivation) || .key?("userActivation") # Use 'root' ownership by default to keep handles alive params = { expression: expression, awaitPromise: await_promise, target: target, resultOwnership: 'root', ** } session.async_send_command('script.evaluate', params) end |
#perform_dispose ⇒ Object
118 119 120 121 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 118 def perform_dispose @disposables.dispose super end |
#resolve_execution_context_id ⇒ Integer
Resolve the CDP execution context ID for this realm
90 91 92 93 94 95 96 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 90 def resolve_execution_context_id return @execution_context_id if @execution_context_id # This uses a Chrome-specific extension to BiDi result = session.connection.send_command('goog:cdp.resolveRealm', { realm: @id }) @execution_context_id = result['executionContextId'] end |
#session ⇒ Session
Abstract method - must be implemented by subclasses
114 115 116 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 114 def session raise NotImplementedError, 'Subclasses must implement #session' end |
#target ⇒ Hash[Symbol, untyped]
Get the target for script execution
24 25 26 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 24 def target { realm: @id } end |