Class: Ferrum::IsolatedWorld
- Inherits:
-
Object
- Object
- Ferrum::IsolatedWorld
- Includes:
- Frame::Runtime
- Defined in:
- lib/ferrum/isolated_world.rb,
sig/ferrum/isolated_world.rbs
Overview
A named JavaScript world in a Frame: it shares the frame's DOM but has
its own globals, so the page's scripts can't see or tamper with what runs
in it. Chrome creates the world on first use and again in every new
document, and it's the same world that
Page#evaluate_on_new_document with world_name: runs scripts in.
Evaluation methods are the same as Frame's, see Frame::Runtime.
Constant Summary
Constants included from Frame::Runtime
Frame::Runtime::DEEP_SERIALIZATION, Frame::Runtime::INTERMITTENT_ATTEMPTS, Frame::Runtime::INTERMITTENT_SLEEP, Frame::Runtime::SHALLOW_SERIALIZATION, Frame::Runtime::UNSERIALIZABLE_NUMBERS
Instance Attribute Summary collapse
-
#frame ⇒ Frame
readonly
The frame the world belongs to.
-
#name ⇒ String
readonly
The world's name.
-
#page ⇒ Page
readonly
The page the world belongs to.
Instance Method Summary collapse
-
#execution_id ⇒ Integer?
Execution context id of the world in the frame's current document.
-
#execution_id!(timeout = nil) ⇒ Integer
Execution context id of the world in the frame's current document, creating the world there if it doesn't exist yet.
-
#execution_id=(value) ⇒ Integer?
private
Sets the execution context id, or clears it if
nilis given, e.g. -
#initialize(frame, name) ⇒ IsolatedWorld
constructor
A new instance of IsolatedWorld.
-
#inspect ⇒ String
Debug representation of the world.
Methods included from Frame::Runtime
#evaluate, #evaluate_handle, #evaluate_in, #execute
Constructor Details
#initialize(frame, name) ⇒ IsolatedWorld
Returns a new instance of IsolatedWorld.
30 31 32 33 34 35 |
# File 'lib/ferrum/isolated_world.rb', line 30 def initialize(frame, name) @frame = frame @page = frame.page @name = name @execution_id = Concurrency::Cell.new end |
Instance Attribute Details
#frame ⇒ Frame (readonly)
The frame the world belongs to.
23 24 25 |
# File 'lib/ferrum/isolated_world.rb', line 23 def frame @frame end |
#name ⇒ String (readonly)
The world's name.
18 19 20 |
# File 'lib/ferrum/isolated_world.rb', line 18 def name @name end |
#page ⇒ Page (readonly)
The page the world belongs to.
28 29 30 |
# File 'lib/ferrum/isolated_world.rb', line 28 def page @page end |
Instance Method Details
#execution_id ⇒ Integer?
Execution context id of the world in the frame's current document.
57 58 59 |
# File 'lib/ferrum/isolated_world.rb', line 57 def execution_id @execution_id.value end |
#execution_id!(timeout = nil) ⇒ Integer
Execution context id of the world in the frame's current document, creating the world there if it doesn't exist yet.
43 44 45 46 47 48 49 50 |
# File 'lib/ferrum/isolated_world.rb', line 43 def execution_id!(timeout = nil) execution_id || begin response = @page.command("Page.createIsolatedWorld", timeout: timeout, frameId: @frame.id, worldName: @name) id = response["executionContextId"] self.execution_id = id execution_id || id end end |
#execution_id=(value) ⇒ Integer?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Sets the execution context id, or clears it if nil is given, e.g.
when the document the world was created in is gone.
70 71 72 73 74 75 76 |
# File 'lib/ferrum/isolated_world.rb', line 70 def execution_id=(value) if value.nil? @execution_id.clear elsif !@execution_id.set? @execution_id.set(value) end end |
#inspect ⇒ String
Debug representation of the world.
83 84 85 |
# File 'lib/ferrum/isolated_world.rb', line 83 def inspect "#<#{self.class} @name=#{@name.inspect} @frame_id=#{@frame.id.inspect} @execution_id=#{execution_id.inspect}>" end |