123456789_123456789_123456789_123456789_123456789_

Class: Selenium::WebDriver::Network

Relationships & Source Files
Inherits: Object
Defined in: rb/lib/selenium/webdriver/common/network.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(bridge) ⇒ Network

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/network.rb', line 25

def initialize(bridge)
  @network = BiDi::Network.new(bridge.bidi)
  @callbacks = {}
end

Instance Attribute Details

#callbacks (readonly)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/network.rb', line 23

attr_reader :callbacks

Instance Method Details

#add_authentication_handler(username, password)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/network.rb', line 30

def add_authentication_handler(username, password)
  intercept = @network.add_intercept(phases: [BiDi::Network::PHASES[:auth_required]])
  auth_id = @network.on(:auth_required) do |event|
    request_id = event['requestId']
    @network.continue_with_auth(request_id, username, password)
  end
  @callbacks[auth_id] = intercept

  auth_id
end

#add_request_handler

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/network.rb', line 51

def add_request_handler
  intercept = @network.add_intercept(phases: [BiDi::Network::PHASES[:before_request]])
  request_id = @network.on(:before_request) do |event|
    request_id = event['requestId']
    @network.continue_with_request(request_id: request_id)
  end

  @callbacks[request_id] = intercept

  request_id
end

#clear_handlers

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/network.rb', line 47

def clear_handlers
  @callbacks.each_key { |id| remove_handler(id) }
end

#remove_handler(id)

[ GitHub ]

  
# File 'rb/lib/selenium/webdriver/common/network.rb', line 41

def remove_handler(id)
  intercept = @callbacks[id]
  @network.remove_intercept(intercept['intercept'])
  @callbacks.delete(id)
end