Class: Puppeteer::NetworkManager
Defined Under Namespace
Classes: Credentials, InternalNetworkCondition, QueuedEventGroup, RedirectInfo
Instance Method Summary
collapse
Methods included from IfPresent
#if_present
#add_event_listener, #emit_event, #observe_first, #off, #on_event, #remove_event_listener
Methods included from DebugPrint
#debug_print, #debug_puts
Constructor Details
#initialize(client, ignore_https_errors, frame_manager, network_enabled: true) ⇒ NetworkManager
Returns a new instance of NetworkManager.
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/puppeteer/network_manager.rb', line 90
def initialize(client, ignore_https_errors, frame_manager, network_enabled: true)
@client = client
@ignore_https_errors = ignore_https_errors
@frame_manager = frame_manager
@network_enabled = network_enabled
@network_event_manager = Puppeteer::NetworkEventManager.new
@clients = Set.new
@initialized = false
@extra_http_headers = {}
@user_agent = nil
@user_agent_metadata = nil
@accept_language = nil
@attempted_authentications = Set.new
@user_request_interception_enabled = false
@protocol_request_interception_enabled = false
@user_cache_disabled = nil
@internal_network_condition = InternalNetworkCondition.new(method(:send_to_clients))
@interception_semaphore = Async::Semaphore.new(1)
add_client(@client)
end
|
Instance Method Details
#add_client(client) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/puppeteer/network_manager.rb', line 120
def add_client(client)
return unless @network_enabled
return if @clients.include?(client)
@clients << client
setup_listeners(client)
if @initialized
if Async::Task.current?
Async do
configure_client(client)
end
else
configure_client(client)
end
end
end
|
#authenticate(username:, password:) ⇒ Object
224
225
226
227
228
229
230
231
|
# File 'lib/puppeteer/network_manager.rb', line 224
def authenticate(username:, password:)
if username.nil? && password.nil?
@credentials = nil
else
@credentials = Credentials.new(username: username, password: password)
end
update_protocol_request_interception
end
|
#cache_enabled=(enabled) ⇒ Object
296
297
298
299
|
# File 'lib/puppeteer/network_manager.rb', line 296
def cache_enabled=(enabled)
@user_cache_disabled = !enabled
update_protocol_cache_disabled
end
|
#emulate_network_conditions(network_condition) ⇒ Object
276
277
278
|
# File 'lib/puppeteer/network_manager.rb', line 276
def emulate_network_conditions(network_condition)
@internal_network_condition.network_condition = network_condition
end
|
262
263
264
|
# File 'lib/puppeteer/network_manager.rb', line 262
def
@extra_http_headers.dup
end
|
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/puppeteer/network_manager.rb', line 234
def ()
= {}
.each do |key, value|
unless value.is_a?(String)
type_description =
case value
when Numeric
'number'
when TrueClass, FalseClass
'boolean'
when NilClass
'null'
when Symbol
'symbol'
when Array, Hash
'object'
else
value.class.to_s
end
raise ArgumentError.new("Expected value of header \"#{key}\" to be String, but \"#{type_description}\" is found.")
end
[key.downcase] = value
end
@extra_http_headers =
apply_to_clients { |client| (client) }
end
|
#init ⇒ Object
113
114
115
116
117
118
|
# File 'lib/puppeteer/network_manager.rb', line 113
def init
apply_to_clients do |client|
configure_client(client)
end
@initialized = true
end
|
#inspect ⇒ Object
137
138
139
140
141
142
143
|
# File 'lib/puppeteer/network_manager.rb', line 137
def inspect
values = %i[network_event_manager].map do |sym|
value = instance_variable_get(:"@#{sym}")
"@#{sym}=#{value}"
end
"#<Puppeteer::HTTPRequest #{values.join(' ')}>"
end
|
#num_requests_in_progress ⇒ Object
266
267
268
|
# File 'lib/puppeteer/network_manager.rb', line 266
def num_requests_in_progress
@network_event_manager.num_requests_in_progress
end
|
#offline_mode=(value) ⇒ Object
271
272
273
|
# File 'lib/puppeteer/network_manager.rb', line 271
def offline_mode=(value)
@internal_network_condition.offline_mode=(value)
end
|
#request_interception=(enabled) ⇒ Object
301
302
303
304
|
# File 'lib/puppeteer/network_manager.rb', line 301
def request_interception=(enabled)
@user_request_interception_enabled = enabled
update_protocol_request_interception
end
|
#set_accept_language(accept_language) ⇒ Object
291
292
293
294
|
# File 'lib/puppeteer/network_manager.rb', line 291
def set_accept_language(accept_language)
@accept_language = accept_language
apply_to_clients { |client| apply_user_agent(client) }
end
|
#set_user_agent(user_agent, user_agent_metadata = nil) ⇒ Object
Also known as:
user_agent=
282
283
284
285
286
|
# File 'lib/puppeteer/network_manager.rb', line 282
def set_user_agent(user_agent, user_agent_metadata = nil)
@user_agent = user_agent
@user_agent_metadata = user_agent_metadata
apply_to_clients { |client| apply_user_agent(client) }
end
|