Class: Puppeteer::Bidi::Realm
- Inherits:
-
Object
- Object
- Puppeteer::Bidi::Realm
- Defined in:
- lib/puppeteer/bidi/realm.rb,
sig/puppeteer/bidi/realm.rbs
Overview
Base realm abstraction that mirrors Puppeteer's Realm class hierarchy. Provides shared lifecycle management for WaitTask instances. https://github.com/puppeteer/puppeteer/blob/main/packages/puppeteer-core/src/api/Realm.ts
Direct Known Subclasses
Instance Attribute Summary collapse
-
#task_manager ⇒ Puppeteer::Bidi::TaskManager
readonly
: Puppeteer::Bidi::TaskManager.
Instance Method Summary collapse
-
#adopt_handle(handle) ⇒ JSHandle
Adopt a handle from another realm into this realm.
-
#default_timeout ⇒ Numeric
Get the default timeout.
-
#dispose ⇒ void
Dispose this realm.
-
#disposed? ⇒ Boolean
Check if this realm is disposed.
-
#ensure_environment_active! ⇒ void
Ensure the environment is still active.
-
#environment ⇒ Object
Get the environment object (must be implemented by subclass).
-
#initialize(timeout_settings) ⇒ Realm
constructor
A new instance of Realm.
-
#page ⇒ Page
Get the page for this realm.
-
#transfer_handle(handle) ⇒ JSHandle
Transfer a handle into this realm, disposing of the original.
-
#wait_for_function(page_function, options = {}, *args, &block) ⇒ void
Wait for a function to return a truthy value.
Constructor Details
#initialize(timeout_settings) ⇒ Realm
Returns a new instance of Realm.
14 15 16 17 18 |
# File 'lib/puppeteer/bidi/realm.rb', line 14 def initialize(timeout_settings) @timeout_settings = timeout_settings @task_manager = TaskManager.new @disposed = false end |
Instance Attribute Details
#task_manager ⇒ Puppeteer::Bidi::TaskManager (readonly)
: Puppeteer::Bidi::TaskManager
10 11 12 |
# File 'lib/puppeteer/bidi/realm.rb', line 10 def task_manager @task_manager end |
Instance Method Details
#adopt_handle(handle) ⇒ JSHandle
Adopt a handle from another realm into this realm. Mirrors Puppeteer's BidiRealm#adoptHandle implementation.
88 89 90 91 92 |
# File 'lib/puppeteer/bidi/realm.rb', line 88 def adopt_handle(handle) raise ArgumentError, 'handle must be a JSHandle' unless handle.is_a?(JSHandle) evaluate_handle('(node) => node', handle) end |
#default_timeout ⇒ Numeric
Get the default timeout
37 38 39 |
# File 'lib/puppeteer/bidi/realm.rb', line 37 def default_timeout @timeout_settings.timeout end |
#dispose ⇒ void
This method returns an undefined value.
Dispose this realm
71 72 73 74 75 76 |
# File 'lib/puppeteer/bidi/realm.rb', line 71 def dispose return if @disposed @disposed = true @task_manager.terminate_all(Error.new('waitForFunction failed: frame got detached.')) end |
#disposed? ⇒ Boolean
Check if this realm is disposed
80 81 82 |
# File 'lib/puppeteer/bidi/realm.rb', line 80 def disposed? @disposed end |
#ensure_environment_active! ⇒ void
This method returns an undefined value.
Ensure the environment is still active
112 113 114 115 116 117 |
# File 'lib/puppeteer/bidi/realm.rb', line 112 def ensure_environment_active! env = environment return unless env.respond_to?(:detached?) raise FrameDetachedError if env.detached? end |
#environment ⇒ Object
Get the environment object (must be implemented by subclass)
22 23 24 |
# File 'lib/puppeteer/bidi/realm.rb', line 22 def environment raise NotImplementedError, 'Subclass must expose its environment object' end |
#page ⇒ Page
Get the page for this realm
28 29 30 31 32 33 |
# File 'lib/puppeteer/bidi/realm.rb', line 28 def page env = environment return env.page if env.respond_to?(:page) raise NotImplementedError, 'Environment must expose a page reference' end |
#transfer_handle(handle) ⇒ JSHandle
Transfer a handle into this realm, disposing of the original. Mirrors Puppeteer's BidiRealm#transferHandle implementation.
98 99 100 101 102 103 104 105 106 |
# File 'lib/puppeteer/bidi/realm.rb', line 98 def transfer_handle(handle) raise ArgumentError, 'handle must be a JSHandle' unless handle.is_a?(JSHandle) return handle if handle.realm.equal?(self) adopted = adopt_handle(handle) handle.dispose adopted end |
#wait_for_function(page_function, options = {}, *args, &block) ⇒ void
This method returns an undefined value.
Wait for a function to return a truthy value
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/puppeteer/bidi/realm.rb', line 47 def wait_for_function(page_function, = {}, *args, &block) ensure_environment_active! polling = [:polling] || 'raf' if polling.is_a?(Numeric) && polling < 0 raise ArgumentError, "Cannot poll with non-positive interval: #{polling}" end timeout = .key?(:timeout) ? [:timeout] : default_timeout = { polling: polling, timeout: timeout, root: [:root] } result = WaitTask.new(self, , page_function, *args).result Async(&block).wait if block result.wait end |