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
|
# 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
@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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/puppeteer/network_manager.rb', line 119
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
219
220
221
222
223
224
225
226
|
# File 'lib/puppeteer/network_manager.rb', line 219
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
284
285
286
287
|
# File 'lib/puppeteer/network_manager.rb', line 284
def cache_enabled=(enabled)
@user_cache_disabled = !enabled
update_protocol_cache_disabled
end
|
#emulate_network_conditions(network_condition) ⇒ Object
271
272
273
|
# File 'lib/puppeteer/network_manager.rb', line 271
def emulate_network_conditions(network_condition)
@internal_network_condition.network_condition = network_condition
end
|
257
258
259
|
# File 'lib/puppeteer/network_manager.rb', line 257
def
@extra_http_headers.dup
end
|
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
# File 'lib/puppeteer/network_manager.rb', line 229
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
112
113
114
115
116
117
|
# File 'lib/puppeteer/network_manager.rb', line 112
def init
apply_to_clients do |client|
configure_client(client)
end
@initialized = true
end
|
#inspect ⇒ Object
136
137
138
139
140
141
142
|
# File 'lib/puppeteer/network_manager.rb', line 136
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
261
262
263
|
# File 'lib/puppeteer/network_manager.rb', line 261
def num_requests_in_progress
@network_event_manager.num_requests_in_progress
end
|
#offline_mode=(value) ⇒ Object
266
267
268
|
# File 'lib/puppeteer/network_manager.rb', line 266
def offline_mode=(value)
@internal_network_condition.offline_mode=(value)
end
|
#request_interception=(enabled) ⇒ Object
289
290
291
292
|
# File 'lib/puppeteer/network_manager.rb', line 289
def request_interception=(enabled)
@user_request_interception_enabled = enabled
update_protocol_request_interception
end
|
#set_user_agent(user_agent, user_agent_metadata = nil) ⇒ Object
Also known as:
user_agent=
277
278
279
280
281
|
# File 'lib/puppeteer/network_manager.rb', line 277
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
|