lib/puppeteer/cdp_session.rb in puppeteer-ruby-0.0.13 vs lib/puppeteer/cdp_session.rb in puppeteer-ruby-0.0.14

- old
+ new

@@ -1,9 +1,9 @@ class Puppeteer::CDPSession include Puppeteer::DebugPrint include Puppeteer::EventCallbackable - using Puppeteer::AsyncAwaitBehavior + using Puppeteer::DefineAsyncMethod class Error < StandardError; end # @param {!Connection} connection # @param {string} targetType @@ -11,11 +11,10 @@ def initialize(connection, target_type, session_id) @callbacks = {} @connection = connection @target_type = target_type @session_id = session_id - @pending_messages = {} end attr_reader :connection # @param method [String] @@ -33,35 +32,20 @@ raise Error.new("Protocol error (#{method}): Session closed. Most likely the #{@target_type} has been closed.") end id = @connection.raw_send(message: { sessionId: @session_id, method: method, params: params }) promise = resolvable_future callback = Puppeteer::Connection::MessageCallback.new(method: method, promise: promise) - if pending_message = @pending_messages.delete(id) - debug_puts "Pending message (id: #{id}) is handled" - callback_with_message(callback, pending_message) - else - @callbacks[id] = callback - end + @callbacks[id] = callback promise end # @param {{id?: number, method: string, params: Object, error: {message: string, data: any}, result?: *}} object def handle_message(message) if message['id'] if callback = @callbacks.delete(message['id']) callback_with_message(callback, message) else - debug_puts "unknown id: #{id}. Store it into pending message" - - # RECV is often notified before SEND. - # Wait about 10 frames before throwing an error. - message_id = message['id'] - @pending_messages[message_id] = message - Concurrent::Promises.schedule(0.16, message_id) do |id| - if @pending_messages.delete(id) - raise Error.new("unknown id: #{id}") - end - end + raise Error.new("unknown id: #{id}") end else emit_event message['method'], message['params'] end end