Class: Ferrum::Worker
- Inherits:
-
Object
- Object
- Ferrum::Worker
- Includes:
- Frame::Runtime, Interceptable
- Defined in:
- lib/ferrum/worker.rb
Overview
A dedicated or shared Worker spawned by a page. Unlike Page it has no DOM, frames, mouse/keyboard, or navigation history -- just a single global execution context and its own network activity.
Constant Summary
Constants included from Frame::Runtime
Frame::Runtime::INTERMITTENT_ATTEMPTS, Frame::Runtime::INTERMITTENT_SLEEP
Instance Attribute Summary collapse
-
#client ⇒ Client, SessionClient
readonly
Client connection.
-
#network ⇒ Network
readonly
Network object.
-
#target_id ⇒ Object
readonly
Returns the value of attribute target_id.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#close ⇒ Boolean
Closes the target in the browser, and its connection.
-
#close_connection ⇒ void
Closes the WebSocket connection only, without asking the browser to close the underlying target.
-
#command ⇒ Boolean, Hash
Sends a CDP command through #client.
-
#initialize(client, target_id:, url:) ⇒ Worker
constructor
A new instance of Worker.
-
#inspect ⇒ String
Debug representation of the worker.
-
#main_frame ⇒ Object
Workers have a single execution context and no navigable document, so there's nothing for Network to check requests against.
-
#timeout ⇒ Numeric
How long to wait for CDP responses and JS evaluation to complete.
Methods included from Interceptable
Methods included from Frame::Runtime
#evaluate, #evaluate_async, #evaluate_func, #evaluate_on, #execute
Constructor Details
#initialize(client, target_id:, url:) ⇒ Worker
Returns a new instance of Worker.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ferrum/worker.rb', line 21 def initialize(client, target_id:, url:) @client = client @target_id = target_id @url = url @options = client. @page = self @execution_id = Concurrent::MVar.new @network = Network.new(self) subscribe prepare end |
Instance Attribute Details
#client ⇒ Client, SessionClient (readonly)
Client connection.
17 18 19 |
# File 'lib/ferrum/worker.rb', line 17 def client @client end |
#network ⇒ Network (readonly)
Network object.
37 38 39 |
# File 'lib/ferrum/worker.rb', line 37 def network @network end |
#target_id ⇒ Object (readonly)
Returns the value of attribute target_id.
19 20 21 |
# File 'lib/ferrum/worker.rb', line 19 def target_id @target_id end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
19 20 21 |
# File 'lib/ferrum/worker.rb', line 19 def url @url end |
Instance Method Details
#close ⇒ Boolean
Closes the target in the browser, and its connection.
63 64 65 66 67 68 |
# File 'lib/ferrum/worker.rb', line 63 def close client.command("Target.closeTarget", async: true, targetId: target_id) close_connection true end |
#close_connection ⇒ void
This method returns an undefined value.
Closes the WebSocket connection only, without asking the browser to close the underlying target. Kept separate from #close so a whole context can be dropped (the browser closes its targets anyway) without every worker having to be closed one by one.
76 77 78 |
# File 'lib/ferrum/worker.rb', line 76 def close_connection client&.close end |
#command ⇒ Boolean, Hash
Sends a CDP command through #client.
50 51 52 |
# File 'lib/ferrum/worker.rb', line 50 def command(...) client.command(...) end |
#inspect ⇒ String
Debug representation of the worker.
83 84 85 |
# File 'lib/ferrum/worker.rb', line 83 def inspect "#<#{self.class} @target_id=#{@target_id.inspect} @url=#{@url.inspect}>" end |
#main_frame ⇒ Object
Workers have a single execution context and no navigable document, so there's nothing for Network to check requests against.
56 57 58 |
# File 'lib/ferrum/worker.rb', line 56 def main_frame nil end |
#timeout ⇒ Numeric
How long to wait for CDP responses and JS evaluation to complete.
42 43 44 |
# File 'lib/ferrum/worker.rb', line 42 def timeout @options.timeout end |