HtmlUnit failing on invalid javascript
See original GitHub issueOpened a question at StackOverflow, opening issue here as per your suggestion.
I need to load the Discord login page but am failing on javascript exceptions.
Running Java 11 on Eclipse 2019-06 with HtmlUnit 2.35
My java code:
webClient = new WebClient();
webClient.getOptions().setDownloadImages(false);
webClient.getOptions().setCssEnabled(false);
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setHistorySizeLimit(5);
webClient.getOptions().setMaxInMemory(524288000);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
webClient.getPage("https://discordapp.com/login");
The full log:
Jul 30, 2019 3:30:39 PM com.gargoylesoftware.htmlunit.html.HtmlLink onAllChildrenAddedToPage
WARNING: Link type 'chrome-webstore-item' not supported.
Jul 30, 2019 3:30:39 PM com.gargoylesoftware.htmlunit.html.HtmlLink onAllChildrenAddedToPage
WARNING: Link type 'stylesheet' not supported.
Jul 30, 2019 3:30:39 PM com.gargoylesoftware.htmlunit.html.HtmlLink onAllChildrenAddedToPage
WARNING: Link type 'icon' not supported.
Jul 30, 2019 3:30:42 PM com.gargoylesoftware.htmlunit.javascript.DefaultJavaScriptErrorListener scriptException
SEVERE: Error during JavaScript execution
======= EXCEPTION START ========
EcmaError: lineNumber=[49] column=[0] lineSource=[<no source>] name=[TypeError] sourceName=[https://discordapp.com/assets/0765c293b8e5eac16193.js] message=[TypeError: Cannot find function setPrototypeOf in object function Object() { [native code] }. (https://discordapp.com/assets/0765c293b8e5eac16193.js#49)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot find function setPrototypeOf in object function Object() { [native code] }. (https://discordapp.com/assets/0765c293b8e5eac16193.js#49)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:885)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:765)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:741)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:104)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:997)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:373)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:268)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:798)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:754)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1175)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1115)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:303)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3126)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2075)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:922)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:438)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:389)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:997)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:252)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:196)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:159)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:531)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:398)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
at discordBot.DiscordWatcher.homePage(DiscordWatcher.java:33)
at discordBot.MainForDiscordWatcher.main(MainForDiscordWatcher.java:8)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function setPrototypeOf in object function Object() { [native code] }. (https://discordapp.com/assets/0765c293b8e5eac16193.js#49)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4334)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4312)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4345)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:4364)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:4440)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2612)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2594)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1520)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1010)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:424)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:322)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3628)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:123)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:756)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:870)
... 35 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot find function setPrototypeOf in object function Object() { [native code] }. (https://discordapp.com/assets/0765c293b8e5eac16193.js#49)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4334)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:4312)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:4345)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:4364)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.notFunctionError(ScriptRuntime.java:4440)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2612)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2594)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1520)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:49)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:49)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:49)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:1)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:45)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:45)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:9)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:9)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:20)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:49)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:45)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:49)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:49)
at script.r(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script.d(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script.c(https://discordapp.com/assets/e4c71e4c5b1f4c2b4d17.js:1)
at script(https://discordapp.com/assets/0765c293b8e5eac16193.js:1)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:1010)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:111)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:424)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:322)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3628)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.exec(InterpretedFunction.java:123)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$2.doRun(JavaScriptEngine.java:756)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:870)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:617)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:534)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.callSecured(HtmlUnitContextFactory.java:336)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:765)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:741)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:104)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:997)
at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:373)
at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:247)
at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:268)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:798)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:754)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1175)
at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1115)
at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219)
at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:303)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3126)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2075)
at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:922)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:438)
at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:389)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.parse(HTMLParser.java:997)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:252)
at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:196)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:268)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:159)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:531)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:398)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:315)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:466)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:448)
at discordBot.DiscordWatcher.homePage(DiscordWatcher.java:33)
at discordBot.MainForDiscordWatcher.main(MainForDiscordWatcher.java:8)
======= EXCEPTION END ========
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (6 by maintainers)
Top Results From Across the Web
java - HtmlUnit failing on invalid javascript, can it be corrected ...
Is this an issue that I can resolve on my client or is the javascript simply invalid and HtmlUnit will never process it...
Read more >JS Browserdetection fail and redirect · Issue #368 · HtmlUnit ...
I've tried with two different classes and problem still occur. @PostMapping("/startScraping") public ResponseEntity<FlashScraper> startScraping ...
Read more >com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter ...
throwing error with htmlunit works fine with firefox and chrome. ... SEVERE: runtimeError: message=[**An invalid or illegal selector was specified ...
Read more >HtmlUnit / Bugs / #1943 Javascript errors - SourceForge
Caused by: com.steadystate.css.dom.DOMExceptionImpl: Syntax error (Error in declaration. (Invalid token "}". Was expecting one of: <S>, ":".))
Read more >HTMLUnit unable to process Javascript? - CodeRanch
The only error I see is the UnknownHostException - make sure that host is not blocked from the machine where this code runs....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
just made a pull request for rhino - https://github.com/mozilla/rhino/pull/588
You are right, did not try different browser versions, had the constructor empty which defaults to best supported.