Class: Playwright::Connection
- Inherits:
-
Object
- Object
- Playwright::Connection
- Defined in:
- lib/playwright/connection.rb
Overview
Instance Attribute Summary collapse
-
#local_utils ⇒ Object
readonly
Returns the value of attribute local_utils.
Instance Method Summary collapse
- #async_run ⇒ Object
- #async_send_message_to_server(guid, method, params, metadata: nil) ⇒ Object
- #cleanup(cause: nil) ⇒ Object
-
#initialize(transport) ⇒ Connection
constructor
A new instance of Connection.
- #initialize_playwright ⇒ Object
- #mark_as_remote ⇒ Object
- #remote? ⇒ Boolean
- #send_message_to_server(guid, method, params, metadata: nil) ⇒ Object
- #set_in_tracing(value) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(transport) ⇒ Connection
Returns a new instance of Connection.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/playwright/connection.rb', line 8 def initialize(transport) @transport = transport @transport. do || dispatch() end @transport.on_driver_crashed do callbacks = @callbacks_mutex.synchronize { @callbacks.values } callbacks.each { |callback| callback.reject(::Playwright::DriverCrashedError.new) } raise ::Playwright::DriverCrashedError.new end @transport.on_driver_closed do cleanup end @objects = {} # Hash[ guid => ChannelOwner ] @objects_mutex = Mutex.new @waiting_for_object = {} # Hash[ guid => Promise<ChannelOwner> ] @callbacks = {} # Hash [ guid => Promise<ChannelOwner> ] @callbacks_mutex = Mutex.new @root_object = RootChannelOwner.new(self) @remote = false @tracing_count = 0 @closed_error = nil end |
Instance Attribute Details
#local_utils ⇒ Object (readonly)
Returns the value of attribute local_utils.
33 34 35 |
# File 'lib/playwright/connection.rb', line 33 def local_utils @local_utils end |
Instance Method Details
#async_run ⇒ Object
43 44 45 |
# File 'lib/playwright/connection.rb', line 43 def async_run @transport.async_run end |
#async_send_message_to_server(guid, method, params, metadata: nil) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/playwright/connection.rb', line 76 def (guid, method, params, metadata: nil) return if @closed_error callback = Concurrent::Promises.resolvable_future with_generated_id do |id| # register callback promise object first. # @see https://github.com/YusukeIwaki/puppeteer-ruby/pull/34 @callbacks_mutex.synchronize { @callbacks[id] = callback } = {} frames = [] if frames = [:stack] [:wallTime] = [:wallTime] [:apiName] = [:apiName] [:location] = [:stack].first [:internal] = ![:apiName] if [:title] [:title] = [:title] end end .compact! = { id: id, guid: guid, method: method, params: replace_channels_with_guids(params), metadata: , } begin @transport.() rescue => err @callbacks_mutex.synchronize { @callbacks.delete(id) } callback.reject(err) raise unless err.is_a?(Transport::AlreadyDisconnectedError) end if @tracing_count > 0 && !frames.empty? && guid != 'localUtils' && !remote? @local_utils.add_stack_to_tracing_no_reply(id, frames) end end callback end |
#cleanup(cause: nil) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/playwright/connection.rb', line 52 def cleanup(cause: nil) @closed_error = TargetClosedError.new(message: cause) callbacks = @callbacks_mutex.synchronize do @callbacks.values.tap { @callbacks.clear } end callbacks.each { |callback| callback.reject(@closed_error) } end |
#initialize_playwright ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/playwright/connection.rb', line 60 def initialize_playwright # Avoid Error: sdkLanguage: expected one of (javascript|python|java|csharp) # ref: https://github.com/microsoft/playwright/pull/18308 # ref: https://github.com/YusukeIwaki/playwright-ruby-client/issues/228 result = ('', 'initialize', { sdkLanguage: 'python' }) ChannelOwners::Playwright.from(result['playwright']) end |
#mark_as_remote ⇒ Object
35 36 37 |
# File 'lib/playwright/connection.rb', line 35 def mark_as_remote @remote = true end |
#remote? ⇒ Boolean
39 40 41 |
# File 'lib/playwright/connection.rb', line 39 def remote? @remote end |
#send_message_to_server(guid, method, params, metadata: nil) ⇒ Object
124 125 126 |
# File 'lib/playwright/connection.rb', line 124 def (guid, method, params, metadata: nil) (guid, method, params, metadata: ).value! end |
#set_in_tracing(value) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/playwright/connection.rb', line 68 def set_in_tracing(value) if value @tracing_count += 1 else @tracing_count -= 1 end end |
#stop ⇒ Object
47 48 49 50 |
# File 'lib/playwright/connection.rb', line 47 def stop @transport.stop cleanup end |