如何在类似于chrome网络面板的javascript页面/url上记录http请求?
我一直在尝试从URL/页面记录HTTP请求,类似于chrome开发者工具在网络面板中的记录方式。到目前为止,我可以得到加载时间和页面大小。我正在用javascript编写代码,从信息来看,你们知道我可以用javascript记录HTTP请求吗。如何在类似于chrome网络面板的javascript页面/url上记录http请求?,javascript,performance,http,request,Javascript,Performance,Http,Request,我一直在尝试从URL/页面记录HTTP请求,类似于chrome开发者工具在网络面板中的记录方式。到目前为止,我可以得到加载时间和页面大小。我正在用javascript编写代码,从信息来看,你们知道我可以用javascript记录HTTP请求吗。 var start=new Date().getTime(); 函数onLoad(){ var now=new Date().getTime(); var latency=now-start; 警报(“页面加载时间:“+latency+”\n“+”开
var start=new Date().getTime();
函数onLoad(){
var now=new Date().getTime();
var latency=now-start;
警报(“页面加载时间:“+latency+”\n“+”开始时间:“+Start+”\n“+”结束时间:“+now”);
警报(“加载大小:”+document.getElementsByTagName(“html”)[0].outerHTML.length+“KB”);
}
您可以使用API而不是日期来测量时间。您希望记录哪些请求?浏览器所做的事情(加载IMG标签、CSS文件等)是常规JavaScript无法实现的——您必须编写浏览器插件(或者,对于站点域的请求,可以尝试使用服务工作者脚本)。您可以尝试通过覆盖默认函数来“捕获”AJAX
和fetch
调用。
<html>
<head>
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<script type="text/javascript">
var start = new Date().getTime();
function onLoad() {
var now = new Date().getTime();
var latency = now - start;
alert("page loading time: " + latency+"\n"+"Start time:"+start+"\n"+"End time:"+now);
alert("Load_size:"+document.getElementsByTagName("html")[0].outerHTML.length + "KB");
}
</script>
</head>
<body onload="onLoad()">
<!- Main page body goes from here. -->
</body>
</html>