Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ScriptException when trying to execute a function #111

Open
WickyPlays opened this issue Dec 17, 2019 · 11 comments
Open

ScriptException when trying to execute a function #111

WickyPlays opened this issue Dec 17, 2019 · 11 comments
Labels
js-engine Issues related to the js engine

Comments

@WickyPlays
Copy link

WickyPlays commented Dec 17, 2019

So as the title said, however in this case the script in the website cannot be modified (the script is in the error). When I try to execute login() from the click, it tells me a ScriptError exception (this is from the Selenium which uses HtmlUnitDriver): WebElement submit = driver.findElement(By.id("login")); submit.click();

Error: ======= EXCEPTION START ======== Exception class=[net.sourceforge.htmlunit.corejs.javascript.EvaluatorException] com.gargoylesoftware.htmlunit.ScriptException: missing ) after formal parameters: (https://aternos.org:443/panel/js/aternos.js?v=30042019#1) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:883) 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.compile(JavaScriptEngine.java:714) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:680) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.compile(JavaScriptEngine.java:103) at com.gargoylesoftware.htmlunit.html.HtmlPage.loadJavaScriptFromUrl(HtmlPage.java:1102) at com.gargoylesoftware.htmlunit.html.HtmlPage.loadExternalJavaScriptFile(HtmlPage.java:982) at com.gargoylesoftware.htmlunit.html.HtmlScript.executeScriptIfNeeded(HtmlScript.java:362) at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:236) at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:257) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:792) at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source) at com.gargoylesoftware.htmlunit.html.HTMLParser$HtmlUnitDOMBuilder.endElement(HTMLParser.java:748) 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:3146) at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2074) 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:991) at com.gargoylesoftware.htmlunit.html.HTMLParser.parse(HTMLParser.java:246) at com.gargoylesoftware.htmlunit.html.HTMLParser.parseHtml(HTMLParser.java:190) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:269) at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:160) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:534) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:400) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:317) at org.openqa.selenium.htmlunit.HtmlUnitDriver.get(HtmlUnitDriver.java:715) at org.openqa.selenium.htmlunit.HtmlUnitDriver.lambda$get$8(HtmlUnitDriver.java:697) at org.openqa.selenium.htmlunit.HtmlUnitDriver.lambda$runAsync$0(HtmlUnitDriver.java:438) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748)

@rbri
Copy link
Member

rbri commented Dec 17, 2019

Looks like a syntax error in the source file. Can you please check if you get this with real browsers also.

@WickyPlays
Copy link
Author

WickyPlays commented Dec 17, 2019

I checked it, it seems like the Login button in the real browser's working well, with only 2 warnings (those are not mentioning about syntax)

Edit: I just tested the same code, but with bare Selenium, and it's working well. Seems HtmlUnitDriver is my only "head-less" browser choice without any browser installation though, but it keeps doing the same EvaluatorException

Edit 2: I've put webClient.getOptions().setThrowExceptionOnScriptError(false);, but error is still there

@rbri
Copy link
Member

rbri commented Dec 20, 2019

setThrowExceptionOnScriptError(false) still logs the error but does not stop the js execution at the place the error occures.
Looks like a problem with the js.
Can you please provide a complete sample - i have to be able to reproduce this here to try to help.

And please use the latest version (or even better the latest SNAPSHOT build)

@WickyPlays
Copy link
Author

WickyPlays commented Dec 21, 2019

https://aternos.org:443/panel/js/aternos.js?v=30042019#1

And yes, I am using ver 2.36.0 for the driver

@rbri
Copy link
Member

rbri commented Dec 22, 2019

Sorry but simply pointing to the js is not a complete sample.
I need something like a some lines of java code i can use to recreate your problem here.

@WickyPlays
Copy link
Author

WickyPlays commented Dec 30, 2019

Sorry for the long response:

    WebDriver driver = new HtmlUnitDriver(BrowserVersion.FIREFOX_60, true) {
        @Override
        protected WebClient modifyWebClient(WebClient client) {
            WebClient modifiedClient = super.modifyWebClient(client);
            modifiedClient.getOptions().setThrowExceptionOnScriptError(false);
            modifiedClient.getOptions().setThrowExceptionOnFailingStatusCode(false);
            modifiedClient.setAjaxController(new NicelyResynchronizingAjaxController());
            return modifiedClient;
        }
    };

    try {
        driver.get("https://aternos.org/go");

        WebElement user = driver.findElement(By.id("user"));
        user.clear();
        user.sendKeys("name");

        WebElement password = driver.findElement(By.id("password"));
        password.clear();
        password.sendKeys("password");

        JavascriptExecutor ex = (JavascriptExecutor) driver;
        ex.executeScript("login();"); //where it gets the error from
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        driver.close();
    }

There you go

@rbri
Copy link
Member

rbri commented Dec 31, 2019

Thanks, was able to reproduce this.

The problem is (at least) this line in the js code

    $.prototype.fa = function(style = "fas", ...classes) {

At the moment Rhino (the base of the js implementation in HtmlUnit) does not support the spread operator (https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Operators/Spread_operator). And adding the support is not that simple.

@WickyPlays
Copy link
Author

So what now?

@rbri
Copy link
Member

rbri commented Jan 1, 2020

What about working together on this to add the support in Rhino?

@vmuthusamy
Copy link

@rbri @thienbao860 Any progress on this issue?

Curious to understand what would be the Level of effort on this undertaking.

@rbri
Copy link
Member

rbri commented Mar 27, 2024

see #755

@rbri rbri added the js-engine Issues related to the js engine label Mar 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
js-engine Issues related to the js engine
Projects
None yet
Development

No branches or pull requests

3 participants