Hunter的大杂烩

February 27, 2020

fiddler script并发记录请求时抛出异常错误的处理

Filed under: 技术话题 — Tags: — hunter @ 12:18 am

网上一般教导在OnBeforeRequest 里加上一段 fso 写文件的代码,来记录请求数据,但是如果页面内元素比较多的情况下,浏览器会并发同时发出请求,这时会出现 permission deined 错误,因为前一个请求打开了LOG文件,还未释放,导致下一个请求无法打开文件。

我的处理方法比较粗暴,用javascript 模拟goto的方法,遇到异常的时候,强制重新再打开一次,简单测试了一下,效果不俗。。。。

		//add by hunter
		if (oSession.fullUrl.Contains("xxx.net"))
		{
			var first = 0;
			log_again:
				for (var x = 0; x < 1; x++){
				FiddlerObject.log("Request url[" + first + "]: " + oSession.url);
				try {
					var fso;
					var file;
					fso = new ActiveXObject("Scripting.FileSystemObject");
					//文件保存路径,可自定义
					file = fso.OpenTextFile("D:\\Fiddle_Sessions.txt", 8 ,true, -2);
					file.writeLine("Request url[" + first + "]: " + oSession.url);
					file.close();
				}
				catch(ex)
				{
					first = first + 1;
					x = -1;
					if (first < 5) continue log_again;
				}
			}
		}

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Powered by WordPress