Menu ▾ ▴

#1792 Missed Context.javaToJS() conversion for ReactJS demo page

Latest SVN
closed
None
1
2016-06-07
2016-05-31
No

Hello,

trunk, r12741.

The following code:

public class ReactDemo {
    public static void main(String[] args) throws IOException {
        java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.ALL);
        java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript").setLevel(Level.ALL);
        WebClient wc = new WebClient(BrowserVersion.CHROME);
        try {
            wc.getOptions().setCssEnabled(true);
            wc.getOptions().setThrowExceptionOnScriptError(true);
            wc.getOptions().setJavaScriptEnabled(true);
            wc.setAjaxController(new NicelyResynchronizingAjaxController());
            wc.setJavaScriptTimeout(5000);
            wc.getOptions().setUseInsecureSSL(true);
            wc.getPage("https://react.rocks/");
            wc.waitForBackgroundJavaScript(4900);
        } finally {
            wc.close();
        }
    }

}

causes the following error output:

RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object com.gargoylesoftware.htmlunit.ScriptException: Exception invoking EventTarget.removeEventListener() with arguments [String, NativeObject, Boolean] of class com.gargoylesoftware.htmlunit.ScriptException where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object com.gargoylesoftware.htmlunit.ScriptException: Exception invoking EventTarget.removeEventListener() with arguments [String, NativeObject, Boolean] of class com.gargoylesoftware.htmlunit.ScriptException where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setSrc of class com.gargoylesoftware.htmlunit.ScriptException where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
Rhino runtime detected object com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setSrc of class com.gargoylesoftware.htmlunit.ScriptException where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
ERROR 12:47:29,909 com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl: Job run failed with unexpected RuntimeException: Exception invoking setSrc
======= EXCEPTION START ========
Exception class=[java.lang.RuntimeException]
com.gargoylesoftware.htmlunit.ScriptException: Exception invoking setSrc
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:904)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:835)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:807)
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:216)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:52)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:426)
    at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:157)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: Exception invoking setSrc
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:182)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putImpl(ScriptableObject.java:2889)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.put(ScriptableObject.java:545)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putProperty(ScriptableObject.java:2572)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1648)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1643)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1259)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:800)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:413)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:252)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3264)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:828)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
    ... 10 more
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking EventTarget.removeEventListener() with arguments [String, NativeObject, Boolean]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:904)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:835)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:807)
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:216)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:259)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeListeners(EventListenersContainer.java:390)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:110)
    at com.gargoylesoftware.htmlunit.html.HtmlImage.doOnLoad(HtmlImage.java:201)
    at com.gargoylesoftware.htmlunit.html.HtmlImage.setAttributeNS(HtmlImage.java:134)
    at com.gargoylesoftware.htmlunit.html.DomElement.setAttribute(DomElement.java:331)
    at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLImageElement.setSrc(HTMLImageElement.java:108)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153)
    ... 24 more
Caused by: java.lang.IllegalArgumentException: Exception invoking EventTarget.removeEventListener() with arguments [String, NativeObject, Boolean]
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:195)
    at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:448)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2575)
    at net.sourceforge.htmlunit.corejs.javascript.BaseFunction.execIdCall(BaseFunction.java:321)
    at net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject.call(IdFunctionObject.java:94)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1540)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:800)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:826)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
    ... 41 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153)
    ... 50 more
Enclosed exception: 
java.lang.RuntimeException: Exception invoking setSrc
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:182)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject$GetterSlot.setValue(ScriptableObject.java:309)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putImpl(ScriptableObject.java:2889)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.put(ScriptableObject.java:545)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptableObject.putProperty(ScriptableObject.java:2572)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1648)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.setObjectProp(ScriptRuntime.java:1643)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1259)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:800)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:413)
    at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:252)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3264)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:828)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:835)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:807)
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:216)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptFunctionJob.runJavaScript(JavaScriptFunctionJob.java:52)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptExecutionJob.run(JavaScriptExecutionJob.java:102)
    at com.gargoylesoftware.htmlunit.javascript.background.JavaScriptJobManagerImpl.runSingleJob(JavaScriptJobManagerImpl.java:426)
    at com.gargoylesoftware.htmlunit.javascript.background.DefaultJavaScriptExecutor.run(DefaultJavaScriptExecutor.java:157)
    at java.lang.Thread.run(Thread.java:745)
Caused by: com.gargoylesoftware.htmlunit.ScriptException: Exception invoking EventTarget.removeEventListener() with arguments [String, NativeObject, Boolean]
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:904)
    at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:628)
    at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:515)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:835)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:807)
    at com.gargoylesoftware.htmlunit.InteractivePage.executeJavaScriptFunctionIfPossible(InteractivePage.java:216)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeEventListeners(EventListenersContainer.java:259)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventListenersContainer.executeListeners(EventListenersContainer.java:390)
    at com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.executeEventLocally(EventTarget.java:110)
    at com.gargoylesoftware.htmlunit.html.HtmlImage.doOnLoad(HtmlImage.java:201)
    at com.gargoylesoftware.htmlunit.html.HtmlImage.setAttributeNS(HtmlImage.java:134)
    at com.gargoylesoftware.htmlunit.html.DomElement.setAttribute(DomElement.java:331)
    at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLImageElement.setSrc(HTMLImageElement.java:108)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153)
    ... 24 more
Caused by: java.lang.IllegalArgumentException: Exception invoking EventTarget.removeEventListener() with arguments [String, NativeObject, Boolean]
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:195)
    at net.sourceforge.htmlunit.corejs.javascript.FunctionObject.call(FunctionObject.java:448)
    at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.applyOrCall(ScriptRuntime.java:2575)
    at net.sourceforge.htmlunit.corejs.javascript.BaseFunction.execIdCall(BaseFunction.java:321)
    at net.sourceforge.htmlunit.corejs.javascript.IdFunctionObject.call(IdFunctionObject.java:94)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1540)
    at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:800)
    at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:105)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:826)
    at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:889)
    ... 41 more
Caused by: java.lang.IllegalArgumentException: argument type mismatch
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:153)
    ... 50 more
== CALLING JAVASCRIPT ==
  function () {
      i.check();
  }
======= EXCEPTION END ========

The DOM gets rendered incorrectly (the slide hrefs are not present) and API calls are sent to rollbar.com.

I think I've narrowed it down to the bundled imagesLoaded plugin in https://react.rocks/scripts/bundle.js but I may be wrong.

I don't quite understand what's causing the problem, and as such I've failed to narrow it down to a minimal test case. imagesLoaded, when used by itself, seems to be working for me.

Discussion

  • Ahmed Ashour

    Ahmed Ashour - 2016-06-01
    • status: open --> accepted
     
  • Sebastian Cato

    Sebastian Cato - 2016-06-01

    The DOM gets rendered incorrectly (the slide hrefs are not present)

    correction: the anchor elements are present, and they have href attributes. With

    wc.getOptions().setThrowExceptionOnScriptError(false);

    I can get the HtmlAnchor node and call it's click() method. The URL of the page enclosed in the toplevel window will change to that of the URL referenced by the anchor, however the HTTP request to that URL will not be performed (seen using DebuggingWebConnection):

    import java.util.logging.Level;
    import com.gargoylesoftware.htmlunit.BrowserVersion;
    import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
    import com.gargoylesoftware.htmlunit.TopLevelWindow;
    import com.gargoylesoftware.htmlunit.WebClient;
    import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
    import com.gargoylesoftware.htmlunit.html.HtmlPage;
    import com.gargoylesoftware.htmlunit.util.DebuggingWebConnection;
    
    public class ReactDemo {
        public static void main(String[] args) throws Exception {
            java.util.logging.Logger.getLogger("com.gargoylesoftware").setLevel(Level.ALL);
            java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit.javascript").setLevel(Level.ALL);
            WebClient wc = new WebClient(BrowserVersion.CHROME);
            try {
                wc.getOptions().setCssEnabled(true);
                wc.getOptions().setThrowExceptionOnScriptError(false);
                wc.getOptions().setJavaScriptEnabled(true);
                wc.setAjaxController(new NicelyResynchronizingAjaxController());
                wc.setJavaScriptTimeout(5000);
                wc.getOptions().setUseInsecureSSL(true);            
                wc.setWebConnection(new DebuggingWebConnection(wc.getWebConnection(), "thingy"));
    
                HtmlPage p = (HtmlPage)wc.getPage("https://react.rocks/");
                wc.waitForBackgroundJavaScript(4900);
    
    
                HtmlAnchor a = (HtmlAnchor)p.getByXPath("//a[@data-reactid=\".0.0.6.0.$mobx-examples.0\"]").get(0);
                System.out.println("MOBX EXAMPLES HREF: " + a.getAttribute("href"));
                a.click();
                Thread.sleep(5000);
                for (TopLevelWindow w : wc.getTopLevelWindows()) {
                    System.out.println("TOPLEVEL URL AFTER CLICK: " + w.getEnclosedPage().getUrl());
                }
            } finally {
                wc.close();
            }
        }
    }
    

    will print:

    [Rhino output here]
    MOBX EXAMPLES HREF: /example/mobx-examples
    TOPLEVEL URL AFTER CLICK: https://react.rocks/example/mobx-examples
    

    but no request to https://react.rocks/example/mobx-examples will be seen in the listed requests in /tmp/thingy/index.html

     
  • Ahmed Ashour

    Ahmed Ashour - 2016-06-01
    • status: accepted --> pending
    • assigned_to: Ahmed Ashour
     
  • Ahmed Ashour

    Ahmed Ashour - 2016-06-01

    removeEventListener was fixed in SVN, please check now.

     
  • Sebastian Cato

    Sebastian Cato - 2016-06-07

    This seems to have fixed the problem, thank you!

     
  • Ahmed Ashour

    Ahmed Ashour - 2016-06-07
    • status: pending --> closed
     

Log in to post a comment.