admin管理员组文章数量:1426801
I am using htmlunit 2.9 and on java script parsing I am getting script exception due to console
in following exception
function debug(o){
if (console && console.log){
console.log(o)
}
};
Stacktrace
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/mypage/ll.html from (154, 36) to (301, 14)#168)]
.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "console" is not defined. (script in http://localhost:8080/mypage/ll.html from (154, 36) to (301, 14)#168)
at .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 .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:545)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:520)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:195)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:214)
if I try specified page on firefox it works fine, I have tried v 3.6 as well as 9.0.1.
i have tried also to set setThrowExceptionOnScriptError(false)
in order to avoid exception but engine stops or do not parse javascript after getting an error.
Is there any way that javascript engine can understand console
in javascript?
I am using htmlunit 2.9 and on java script parsing I am getting script exception due to console
in following exception
function debug(o){
if (console && console.log){
console.log(o)
}
};
Stacktrace
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./mypage/ll.html from (154, 36) to (301, 14)#168)]
.gargoylesoftware.htmlunit.ScriptException: ReferenceError: "console" is not defined. (script in http://localhost:8080./mypage/ll.html from (154, 36) to (301, 14)#168)
at .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 .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:545)
at .gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:520)
at .gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:896)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:195)
at .gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:214)
if I try specified page on firefox it works fine, I have tried v 3.6 as well as 9.0.1.
i have tried also to set setThrowExceptionOnScriptError(false)
in order to avoid exception but engine stops or do not parse javascript after getting an error.
Is there any way that javascript engine can understand console
in javascript?
- Does it also stop if you use BrowserVersion.FIREFOX_3_6? – milan Commented Dec 31, 2011 at 22:00
- Possibly helpful (see lower answers as well): stackoverflow./questions/1215392/… – Jared Farrish Commented Dec 31, 2011 at 22:37
3 Answers
Reset to default 2Your if
condition isn't properly structured:
if (console && console.log){
That first if will throw an error if its not set; accessing console
in environments its not defined in is like accessing any undefined variable; it will throw a ReferenceError
.
Try:
if( typeof console != "undefined" && console.log ) {
Or:
if(window.console && console.log) {
It doesn't throw in error in Firefox since Firefox implements the Firebug API, as do Chrome and Safari. But, by default, Internet Explorer does not, so, it's worth doing a proper feature check here, as it will throw a ReferenceError in browsers that don't implement this API.
https://sourceforge/tracker/index.php?func=detail&aid=3518475&group_id=47038&atid=448266 implies that support for console
was just added to HtmlUnit.
Your code does use the java script console object, and it's not supported till the current version, and it is promised to be supported in the next release as it is said here
本文标签: javaHtmlunit ScriptException quotconsolequot is not definedStack Overflow
版权声明:本文标题:java - Htmlunit ScriptException "console" is not defined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745485247a2660352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论