我使用的HtmlUnit 2.9和Java腳本解析我在以下情況例外的HtmlUnit ScriptException 「控制檯」 沒有定義
function debug(o){
if (console && console.log){
console.log(o)
}
};
堆棧跟蹤
EcmaError:
lineNumber=[168]
column=[0]
lineSource=[null]
name=[ReferenceError]
sourceName=[script in http://localhost:808/mypage/ll.html from (154, 36) to (301, 14)]
message=[ReferenceError: "console" is not defined. (script in http://localhost:8080.com/mypage/ll.html from (154, 36) to (301, 14)#168)]
com.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "console" is not defined. (script in http://localhost:8080.com/mypage/ll.html from (154, 36) to (301, 14)#168)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:595)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:537)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:538)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:545)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:520)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:195)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:214)
如果獲取腳本異常是由於console
我嘗試在Firefox上指定的頁面,它工作正常,我已經嘗試3.6以及9.0.1。
我也試過設置setThrowExceptionOnScriptError(false)
爲了避免異常,但引擎停止或在得到錯誤後不解析javascript。
有沒有什麼辦法可以讓javascript引擎在javascript中理解console
?
如果使用BrowserVersion是否也停止.FIREFOX_3_6? – milan 2011-12-31 22:00:38
可能有用(見下面的答案以及):http://stackoverflow.com/questions/1215392/how-to-quickly-and-conveniently-disable-all-console-log-statements-in-my-code – 2011-12-31 22:37:41
沒有你有沒有找到解決這個問題的方法? – Cuga 2012-01-17 21:23:19