Class: Selenium::WebDriver::DevTools::NetworkInterceptor Private

Inherits:
Object
  • Object
show all
Defined in:
rb/lib/selenium/webdriver/devtools/network_interceptor.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Wraps the network request/response interception, providing thread-safety guarantees and handling special cases such as browser canceling requests midst interception.

You should not be using this class directly, use Driver#intercept instead.

Constant Summary collapse

CANNOT_GET_BODY_ON_REDIRECT_ERROR_CODE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

CDP fails to get body on certain responses (301) and raises: “Can only get response body on requests captured after headers received.”

'-32000'
INVALID_INTERCEPTION_ID_ERROR_CODE =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

CDP fails to operate with intercepted requests. Typical reason is browser cancelling intercepted requests/responses.

'-32602'

Instance Method Summary collapse

Constructor Details

#initialize(devtools) ⇒ NetworkInterceptor

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of NetworkInterceptor.



41
42
43
44
# File 'rb/lib/selenium/webdriver/devtools/network_interceptor.rb', line 41

def initialize(devtools)
  @devtools = devtools
  @lock = Mutex.new
end

Instance Method Details

#intercept(&block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



46
47
48
49
50
51
52
53
# File 'rb/lib/selenium/webdriver/devtools/network_interceptor.rb', line 46

def intercept(&block)
  devtools.network.on(:loading_failed) { |params| track_cancelled_request(params) }
  devtools.fetch.on(:request_paused) { |params| request_paused(params, &block) }

  devtools.network.set_cache_disabled(cache_disabled: true)
  devtools.network.enable
  devtools.fetch.enable(patterns: [{requestStage: 'Request'}, {requestStage: 'Response'}])
end