Class: Puppeteer::Bidi::Core::WindowRealm
- Inherits:
-
Realm
- Object
- EventEmitter
- Realm
- Puppeteer::Bidi::Core::WindowRealm
- Defined in:
- lib/puppeteer/bidi/core/realm.rb,
sig/puppeteer/bidi/core/realm.rbs
Overview
WindowRealm represents a JavaScript realm in a window or iframe
Instance Attribute Summary collapse
-
#browsing_context ⇒ Object
readonly
Returns the value of attribute browsing_context.
-
#sandbox ⇒ Object
readonly
Returns the value of attribute sandbox.
Attributes inherited from Realm
Class Method Summary collapse
-
.from(browsing_context, sandbox = nil) ⇒ WindowRealm
Create a window realm.
Instance Method Summary collapse
- #dispose_realm(reason) ⇒ Object
-
#environment ⇒ Object
Get the environment (Frame) for this realm.
-
#environment=(frame) ⇒ void
Set the environment (Frame) for this realm This is set by Frame when it's created.
-
#initialize(browsing_context, sandbox = nil) ⇒ WindowRealm
constructor
A new instance of WindowRealm.
- #initialize_realm ⇒ Object
- #session ⇒ Object
-
#target ⇒ Hash[Symbol, untyped]
Override target to use context-based target.
Methods inherited from Realm
#call_function, #disown, #dispose, #evaluate, #perform_dispose, #resolve_execution_context_id
Methods included from Disposable::DisposableMixin
#dispose, #disposed?, #perform_dispose
Methods inherited from EventEmitter
#dispose, #disposed?, #emit, #off, #on, #once, #remove_all_listeners
Constructor Details
#initialize(browsing_context, sandbox = nil) ⇒ WindowRealm
Returns a new instance of WindowRealm.
138 139 140 141 142 143 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 138 def initialize(browsing_context, sandbox = nil) super('', '') # ID and origin will be set when realm is created @browsing_context = browsing_context @sandbox = sandbox @workers = {} end |
Instance Attribute Details
#browsing_context ⇒ Object (readonly)
Returns the value of attribute browsing_context.
136 137 138 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 136 def browsing_context @browsing_context end |
#sandbox ⇒ Object (readonly)
Returns the value of attribute sandbox.
136 137 138 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 136 def sandbox @sandbox end |
Class Method Details
.from(browsing_context, sandbox = nil) ⇒ WindowRealm
Create a window realm
130 131 132 133 134 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 130 def self.from(browsing_context, sandbox = nil) realm = new(browsing_context, sandbox) realm.send(:initialize_realm) realm end |
Instance Method Details
#dispose_realm(reason) ⇒ Object
210 211 212 213 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 210 def dispose_realm(reason) @reason = reason dispose end |
#environment ⇒ Object
Get the environment (Frame) for this realm
155 156 157 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 155 def environment @environment end |
#environment=(frame) ⇒ void
This method returns an undefined value.
Set the environment (Frame) for this realm This is set by Frame when it's created
149 150 151 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 149 def environment=(frame) @environment = frame end |
#initialize_realm ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 175 def initialize_realm # Listen for browsing context closure @browsing_context.once(:closed) do |reason| dispose_realm(reason) end # Listen for realm creation (this realm) session.on('script.realmCreated') do |info| next unless info['type'] == 'window' next unless info['context'] == @browsing_context.id next unless info['sandbox'] == @sandbox # Set the ID and origin for this realm @id = info['realm'] @origin = info['origin'] @execution_context_id = nil emit(:updated, self) end # Listen for dedicated worker creation session.on('script.realmCreated') do |info| next unless info['type'] == 'dedicated-worker' next unless info['owners']&.include?(@id) worker = DedicatedWorkerRealm.from(self, info['realm'], info['origin']) @workers[worker.id] = worker worker.once(:destroyed) do @workers.delete(worker.id) end emit(:worker, worker) end end |
#session ⇒ Object
169 170 171 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 169 def session @browsing_context.user_context.browser.session end |
#target ⇒ Hash[Symbol, untyped]
Override target to use context-based target
161 162 163 164 165 |
# File 'lib/puppeteer/bidi/core/realm.rb', line 161 def target result = { context: @browsing_context.id } result[:sandbox] = @sandbox if @sandbox result end |