测量网页大小
我们在.Net Framework 3.5 SP1中创建了一个WPF应用程序,用于显示各种Web应用程序。 WPF 应用程序使用 Web 浏览器控件来显示各种应用程序的网页。
我们对这些网页进行检测来测量响应时间和各种其他参数,其中页面大小是一个重要参数。
下面的代码描述了我们如何访问页面大小。
void wbEvents1_DocumentComplete(object pDisp, ref object URL)
{ objInstrument.PageSize = Convert.ToInt32(((mshtml.HTMLDocumentClass)(((SHDocVw.IWebBrowser2)pDisp).Document)).fileSize);
}
但我们在这里面临以下问题:
我们只能获取 Document 对象的文件大小,即下载的 HTML 的大小,而无法获取其关联资源的大小,例如 (.css; .js; .img,我们需要的是 HTML 文档的整体页面大小,包括 HTML 中的所有资源对象(.css; .js; .img 等)。
此外,如果下载的页面的标题中包含以下任何参数; IE 不返回 fileSize 属性的任何值。
缓存控制=无缓存
Pragma = no-cache
请求帮助解决我们最早面临的上述两个问题。
We have a WPF application created in .Net Framework 3.5 SP1, used for displaying various Web Application. The WPF application uses a Web Browser control to display the web pages of the various applications.
We instrument these web pages to measure the response time and various other parameters, of which Page size is an important parameter.
The code below describes how we are accessing Page size.
void wbEvents1_DocumentComplete(object pDisp, ref object URL)
{ objInstrument.PageSize = Convert.ToInt32(((mshtml.HTMLDocumentClass)(((SHDocVw.IWebBrowser2)pDisp).Document)).fileSize);
}
But we are facing following issues over here:
We are able to get only the filesize of the Document object i.e the size of the downloaded HTML only without the size of its associated resources like (.css; .js; .img, etc).What we need is the holistic Page size of the HTML document, including all the resource objects within the HTML(.css; .js; .img, etc) .
Also in case if the downloaded page has any of the following parameters in its header; IE does not return any value for the fileSize attribute.
Cache-Control = no-cache
Pragma = no-cache
Request for help in resolving the above 2 issues that we are facing at earliest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是直接答案,但也许您可以考虑通过本地代理获取有问题的网页,该代理可以监视和检测所有流量,并在进程外运行时通过 IPC 将其传回父应用程序。
在浏览器和网络之间放置代理可以让您准确、完整地测量传输的字节数、每个请求花费的时间等。可能有很多现有的监控解决方案可以按对象类型等细分流量,或者您可以根据代理的原始信息编写自己的分析文章。也许,Squid + 日志文件分析器插件或调整现有代理来收集所需的统计信息(在CharlesProxy 的精神)。
要指示浏览器控件使用代理,您可以使用 InternetSetOption()(有一个例子)。
This is not a direct answer, but perhaps you could consider fetching the web pages in question through a local proxy, which could monitor and instrument all traffic and communicate it back to parent app via IPC if run out-of-process.
Placing a proxy in between the browser and the net would give you exact and complete measurement of bytes transfered, time spent on each request, etc. There are probably plenty of existing monitoring solutions which will break down traffic by object type, etc. or you could write your own analysis piece given raw information from the proxy. Perhaps, Squid + log-file analyzer plugin or adapt an existing proxy to gather the needed stats (in the spirit of CharlesProxy).
To instruct the browser control to user a proxy, you can use InternetSetOption() (there's an example).