add network request tracking for fetch requests in devtools
This commit is contained in:
@@ -122,3 +122,20 @@ func get_request_stats() -> Dictionary:
|
||||
"pending": pending_requests,
|
||||
"total_size": total_size
|
||||
}
|
||||
|
||||
func add_completed_request(url: String, method: String, is_from_lua: bool, status_code: int, status_text: String, response_headers: Dictionary, response_body: String, body_bytes: PackedByteArray = [], request_headers: Dictionary = {}, request_body: String = "", time_ms: float = 0.0):
|
||||
|
||||
var request = NetworkRequest.new(url, method)
|
||||
request.is_from_lua = is_from_lua
|
||||
request.request_headers = request_headers
|
||||
request.request_body = request_body
|
||||
|
||||
if time_ms > 0.0:
|
||||
request.start_time = Time.get_ticks_msec() - time_ms
|
||||
|
||||
request.set_response(status_code, status_text, response_headers, response_body, body_bytes)
|
||||
|
||||
all_requests.append(request)
|
||||
|
||||
if dev_tools_network_tab:
|
||||
dev_tools_network_tab.add_network_request(request)
|
||||
@@ -27,12 +27,32 @@ func _ready():
|
||||
func init(network_request: NetworkRequest, parent_tab: NetworkTab):
|
||||
request = network_request
|
||||
network_tab = parent_tab
|
||||
update_display()
|
||||
if is_node_ready():
|
||||
update_display()
|
||||
else:
|
||||
call_deferred("update_display")
|
||||
|
||||
func update_display():
|
||||
if not request:
|
||||
return
|
||||
|
||||
if icon == null:
|
||||
icon = get_node_or_null("HBoxContainer/IconContainer/Icon") as TextureRect
|
||||
if name_label == null:
|
||||
name_label = get_node_or_null("HBoxContainer/NameLabel") as Label
|
||||
if status_label == null:
|
||||
status_label = get_node_or_null("HBoxContainer/StatusLabel") as Label
|
||||
if type_label == null:
|
||||
type_label = get_node_or_null("HBoxContainer/TypeLabel") as Label
|
||||
if size_label == null:
|
||||
size_label = get_node_or_null("HBoxContainer/SizeLabel") as Label
|
||||
if time_label == null:
|
||||
time_label = get_node_or_null("HBoxContainer/TimeLabel") as Label
|
||||
|
||||
if icon == null or name_label == null or status_label == null or type_label == null or size_label == null or time_label == null:
|
||||
call_deferred("update_display")
|
||||
return
|
||||
|
||||
# Update icon
|
||||
icon.texture = request.get_icon_texture()
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ func _ready():
|
||||
update_status_bar()
|
||||
|
||||
NetworkManager.register_dev_tools_network_tab(self)
|
||||
for req in NetworkManager.get_all_requests():
|
||||
add_network_request(req)
|
||||
|
||||
func add_network_request(request: NetworkRequest):
|
||||
network_requests.append(request)
|
||||
|
||||
Reference in New Issue
Block a user