为什么netsniff.js将javascript错误输出到输出中?
问题描述:
我使用netsniff.js这样的:为什么netsniff.js将javascript错误输出到输出中?
phantomjs --ignore-ssl-errors=true --ssl-protocol=any netsniff.js http://thermex.ru/ > t.out
当netsniff完成后,我在文本编辑器打开文件t.out,我看到了JS错误是这样的:
TypeError: 'undefined' is not a function (evaluating '$('.bxslider').bxSlider({ mode: 'fade', preloadImages: 'all', slideWidth: 697 })') http://thermex.ru/:565 http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js:2 http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js:2 http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js:2 http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js:2
后这个错误我看到有效的HAR数据。
但我不能解析这个文件,因为他不包含有效的JSON数据(JS错误+有效的JSON HAR数据=没有有效的JSON数据)。
如何从netsniff.js接收该域的有效文件?
答
您可以到page.onError
,page.onConsoleMessage
和phantom.onError
事件,以防止(在netsniff.js page.open
之前)的默认操作寄存器:
page.onError = function(){};
page.onConsoleMessage= function(){};
phantom.onError = function(){};