Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/410.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在类似于chrome网络面板的javascript页面/url上记录http请求?_Javascript_Performance_Http_Request - Fatal编程技术网

如何在类似于chrome网络面板的javascript页面/url上记录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“+”开

我一直在尝试从URL/页面记录HTTP请求,类似于chrome开发者工具在网络面板中的记录方式。到目前为止,我可以得到加载时间和页面大小。我正在用javascript编写代码,从信息来看,你们知道我可以用javascript记录HTTP请求吗。


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>