Class: Charai::Browser
- Inherits:
-
Object
- Object
- Charai::Browser
- Defined in:
- lib/charai/browser.rb
Defined Under Namespace
Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #bidi_call_async(method_, params = {}) ⇒ Object
- #close ⇒ Object
- #create_browsing_context ⇒ Object
-
#initialize(web_socket, debug_protocol: false) ⇒ Browser
constructor
A new instance of Browser.
Constructor Details
#initialize(web_socket, debug_protocol: false) ⇒ Browser
Returns a new instance of Browser.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/charai/browser.rb', line 7 def initialize(web_socket, debug_protocol: false) @web_socket = web_socket @debug_protocol = debug_protocol @browsing_contexts = {} web_socket. do || (JSON.parse()) end bidi_call_async('session.new', { capabilities: { alwaysMatch: { acceptInsecureCerts: false, webSocketUrl: true, }, }, }).value! sync_browsing_contexts bidi_call_async('session.subscribe', { events: %w[browsingContext], }) # do no await end |
Class Method Details
.launch ⇒ Object
3 4 5 |
# File 'lib/charai/browser.rb', line 3 def self.launch(...) BrowserLauncher.new.launch(...) end |
Instance Method Details
#bidi_call_async(method_, params = {}) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/charai/browser.rb', line 41 def bidi_call_async(method_, params = {}) do || @message_results[] = Concurrent::Promises.resolvable_future ({ id: , method: method_, params: params, }) @message_results[] end end |
#close ⇒ Object
36 37 38 39 |
# File 'lib/charai/browser.rb', line 36 def close bidi_call_async('browser.close').value! @web_socket.close end |
#create_browsing_context ⇒ Object
30 31 32 33 34 |
# File 'lib/charai/browser.rb', line 30 def create_browsing_context result = bidi_call_async('browsingContext.create', { type: :tab, userContext: :default }).value! browsing_context_id = result['context'] @browsing_contexts[browsing_context_id] ||= BrowsingContext.new(self, browsing_context_id) end |