Class: Puppeteer::Bidi::Core::WindowRealm

Inherits:
Realm show all
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

Attributes inherited from Realm

#id, #origin

Class Method Summary collapse

Instance Method Summary collapse

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.

Parameters:

  • browsing_context (Object)
  • sandbox (Object) (defaults to: nil)


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_contextObject (readonly)

Returns the value of attribute browsing_context.

Returns:

  • (Object)


136
137
138
# File 'lib/puppeteer/bidi/core/realm.rb', line 136

def browsing_context
  @browsing_context
end

#sandboxObject (readonly)

Returns the value of attribute sandbox.

Returns:

  • (Object)


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

Parameters:

  • browsing_context (BrowsingContext)
  • sandbox (String, nil) (defaults to: nil)

Returns:



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

Parameters:

  • reason (Object)

Returns:

  • (Object)


210
211
212
213
# File 'lib/puppeteer/bidi/core/realm.rb', line 210

def dispose_realm(reason)
  @reason = reason
  dispose
end

#environmentObject

Get the environment (Frame) for this realm

Returns:

  • (Object)


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

Parameters:

  • frame (Object)


149
150
151
# File 'lib/puppeteer/bidi/core/realm.rb', line 149

def environment=(frame)
  @environment = frame
end

#initialize_realmObject

Returns:

  • (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

#sessionObject

Returns:

  • (Object)


169
170
171
# File 'lib/puppeteer/bidi/core/realm.rb', line 169

def session
  @browsing_context.user_context.browser.session
end

#targetHash[Symbol, untyped]

Override target to use context-based target

Returns:

  • (Hash[Symbol, untyped])


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