Class: Puppeteer::NetworkManager

Inherits:
Object
  • Object
show all
Includes:
EventCallbackable
Defined in:
lib/puppeteer/network_manager.rb

Defined Under Namespace

Classes: Credentials

Instance Method Summary collapse

Methods included from EventCallbackable

#add_event_listener, #emit_event, #observe_first, #on_event, #remove_event_listener

Constructor Details

#initialize(client, ignore_https_errors, frame_manager) ⇒ NetworkManager

Returns a new instance of NetworkManager.

Parameters:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/puppeteer/network_manager.rb', line 17

def initialize(client, ignore_https_errors, frame_manager)
  @client = client
  @ignore_https_errors = ignore_https_errors
  @frame_manager = frame_manager

  # @type {!Map<string, !Request>}
  @request_id_to_request = {}

  # @type {!Map<string, !Protocol.Network.requestWillBeSentPayload>}
  @request_id_to_request_with_be_sent_event

  @extra_http_headers = {}

  @offline = false

  # /** @type {!Set<string>} */
  # this._attemptedAuthentications = new Set();
  @user_request_interception_enabled = false
  @protocol_request_interception_enabled = false
  @user_cache_disabled = false
  # /** @type {!Map<string, string>} */
  # this._requestIdToInterceptionId = new Map();
end

Instance Method Details

#authenticate(username:, password:) ⇒ Object

Parameters:

  • username (String|NilClass)
  • password (String|NilClass)


50
51
52
53
# File 'lib/puppeteer/network_manager.rb', line 50

def authenticate(username:, password:)
  @credentials = Credentials.new(username: username, password: password)
  update_protocol_request_interception
end

#cache_enabled=(enabled) ⇒ Object



91
92
93
94
# File 'lib/puppeteer/network_manager.rb', line 91

def cache_enabled=(enabled)
  @user_cache_disabled = !enabled
  update_protocol_cache_disabled
end

#extra_http_headers!Object<string, string>

Returns:

  • (!Object<string, string>)


69
70
71
# File 'lib/puppeteer/network_manager.rb', line 69

def extra_http_headers
  @extra_http_headers.dup
end

#extra_http_headers=(headers) ⇒ Object

Parameters:

  • extraHTTPHeaders (!Object<string, string>)


56
57
58
59
60
61
62
63
64
65
66
# File 'lib/puppeteer/network_manager.rb', line 56

def extra_http_headers=(headers)
  new_extra_http_headers = {}
  headers.each do |key, value|
    unless value.is_a?(String)
      raise ArgumentError.new("Expected value of header \"#{key}\" to be String, but \"#{value}\" is found.")
    end
    new_extra_http_headers[key.downcase] = value
  end
  @extra_http_headers = new_extra_http_headers
  @client.send_message('Network.setExtraHTTPHeaders', headers: new_extra_http_headers)
end

#initObject



41
42
43
44
45
46
# File 'lib/puppeteer/network_manager.rb', line 41

def init
  @client.send_message('Network.enable')
  if @ignore_https_errors
    @client.send_message('Security.setIgnoreCertificateErrors', ignore: true)
  end
end

#offline_mode=(value) ⇒ Object

Parameters:

  • value (TrueClass|FalseClass)


74
75
76
77
78
79
80
81
82
83
84
# File 'lib/puppeteer/network_manager.rb', line 74

def offline_mode=(value)
  return if @offline == value
  @offline = value
  @client.send_message('Network.emulateNetworkConditions',
    offline: @offline,
    # values of 0 remove any active throttling. crbug.com/456324#c9
    latency: 0,
    downloadThroughput: -1,
    uploadThroughput: -1,
  )
end

#request_interception=(enabled) ⇒ Object



96
97
98
99
# File 'lib/puppeteer/network_manager.rb', line 96

def request_interception=(enabled)
  @user_request_interception_enabled = enabled
  update_protocol_request_interception
end

#user_agent=(user_agent) ⇒ Object

Parameters:

  • user_agent (String)


87
88
89
# File 'lib/puppeteer/network_manager.rb', line 87

def user_agent=(user_agent)
  @client.send_message('Network.setUserAgentOverride', userAgent: user_agent)
end