0

I've got some problems with latest jxBrowser.
I have added javascript-java-bridge with onScriptContextCreated:

        mainBrowser.addScriptContextListener(new ScriptContextAdapter()
    {
        @Override
        public void onScriptContextCreated(ScriptContextEvent event)
        {
            Browser browser = event.getBrowser();
            JSValue jsValue = browser.executeJavaScriptAndReturnValue("window");
            jsValue.asObject().setProperty("app", new JavascriptBridge());
            logger.info("Set app context in JS");

        }
    });

In JS I have a function called 'gwtAdapter' in which two Java-functions are called:

function gwtAdapter(name, params, callback)
{

try
{
    if (name == "saveSelectedLoginData")
    {
        app.sendMessageNew(name, params, callback);

        console.log("DURCH DURCH DURCH");
    }
    else
    {
        console.log("Call sendMessage: \n\tName:" + name + "\n\tParams: " + params);

        app.sendMessage(name, [params]);

        console.log("Call sendMessage: \n\tName:" + name + "\n\tCallback: " + callback);
        app.setMessageCallback(name, callback);
    }

}
catch(err)
{
    console.log("Error in gwtAdapter: " + err.message);
}
}

Please don't discuss about reasonableness of those functions ;) They have a reason.
In some cases the browser is hanging when it reaches app.sendMessage and then I don't get any logs or an error message. Then I can't interact with DevTools console any more.

I don't know which information I should add because I can't find something I can add which might be helpful.
LogLevel is already on Level.ALL.

If you have questions, please feel free to ask so I can add something.

Edit_1:

jxbrowser-browser.log:

Mai 10, 2016 11:51:04 AM com.teamdev.jxbrowser.chromium.BrowserType getDefault
INFORMATION: JxBrowser type: HEAVYWEIGHT

jxbrowser-chromium.log: empty

jxbrowser-ipc.log: It doesn't log anything useful for this error

Edit_2:

Strange... After hanging it took about 8 minutes to pass the function but afterwards the javascript-java-bridge is broken.

Here some logs:

Mai 10, 2016 2:52:55 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnConsoleMessage{type=OnConsoleMessage, uid=907, level=0, message='Save LoginData now!', lineNumber=568, sourceId='file:///workspace/xxxxxxx/processes/Contents/Login/js/functions.js'}, SocketInfo{cid=0, bid=0, channelType=Browser}
Mai 10, 2016 2:52:55 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnInvokeJSJavaMessage{type=OnInvokeJSJavaEvent, uid=13, javaObjectId=0, contextPtr=140448130669824, methodName='sendMessageNew', parameters='s21:saveSelectedLoginData:s158:{"saveLoginData": {"selectedUser": "testuser", "selectedPassword": "testuser", "selectedSystem": "xxxxxx", "selectedLanguage": "de"}}:of140448149924128:', returnValue='', errorMessage=''}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelWriter run
INFORMATION: WRITE: OnInvokeJSJavaMessage{type=OnInvokeJSJavaEvent, uid=12, javaObjectId=0, contextPtr=140448130669824, methodName='setMessageCallback', parameters='s6:getUrl:of140448129618576:', returnValue='', errorMessage='Failed to send message.'}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelWriter run
INFORMATION: WRITE: ExecuteJavaScriptMessage{type=ExecuteJavaScript, uid = 40, frameId=-1, javaScript='window', hasReturnValue=true, returnValue='null'}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  ExecuteJavaScriptMessage{type=ExecuteJavaScript, uid = 40, frameId=-1, javaScript='window', hasReturnValue=true, returnValue='oo140448128891328:'}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelWriter run
INFORMATION: WRITE: JSInvokeFunctionMessage{type=JSInvokeFunction, uid=41, objectPtr=140448128891328, functionPtr=140448149924128, contextPtr=140448130669824, frameId=-1, args='on:', result='null', error='null'}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  JSInvokeFunctionMessage{type=JSInvokeFunction, uid=41, objectPtr=140448128891328, functionPtr=140448149924128, contextPtr=140448130669824, frameId=-1, args='on:', result='ou:', error=''}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelWriter run
INFORMATION: WRITE: OnInvokeJSJavaMessage{type=OnInvokeJSJavaEvent, uid=13, javaObjectId=0, contextPtr=140448130669824, methodName='sendMessageNew', parameters='s21:saveSelectedLoginData:s158:{"saveLoginData": {"selectedUser": "testuser", "selectedPassword": "testuser", "selectedSystem": "xxxxxxx", "selectedLanguage": "de"}}:of140448149924128:', returnValue='', errorMessage=''}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnConsoleMessage{type=OnConsoleMessage, uid=1119, level=0, message='voidFunction called', lineNumber=1153, sourceId='file:///workspace/xxxxxxxxx/processes/Contents/Login/js/functions.js'}, SocketInfo{cid=0, bid=0, channelType=Browser}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnConsoleMessage{type=OnConsoleMessage, uid=1120, level=0, message='voidFunction-response: null', lineNumber=1156, sourceId='file:///workspace/xxxxxx/processes/Contents/Login/js/functions.js'}, SocketInfo{cid=0, bid=0, channelType=Browser}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnConsoleMessage{type=OnConsoleMessage, uid=1121, level=0, message='DURCH DURCH DURCH', lineNumber=95, sourceId='file:///workspace/xxxxxx/processes/Contents/Login/js/functions.js'}, SocketInfo{cid=0, bid=0, channelType=Browser}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  JSInvokeFunctionMessage{type=JSInvokeFunction, uid=39, objectPtr=140448151648656, functionPtr=140448129618576, contextPtr=140448130669824, frameId=-1, args='s234:{"response":{"url":"xxxxxxxxx"},"exceptions":{},"success":true}:', result='xxxxxxxx', error=''}, SocketInfo{cid=0, bid=0, channelType=Render}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnConsoleMessage{type=OnConsoleMessage, uid=1122, level=0, message='Login now!', lineNumber=570, sourceId='file:///workspace/xxxxx/processes/Contents/Login/js/functions.js'}, SocketInfo{cid=0, bid=0, channelType=Browser}
Mai 10, 2016 3:01:15 PM com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelReader a
INFORMATION: READ:  OnConsoleMessage{type=OnConsoleMessage, uid=1123, level=0, message='Error in gwtAdapter: undefined', lineNumber=110, sourceId='file:///workspace/xxxxxx/processes/Contents/Login/js/functions.js'}, SocketInfo{cid=0, bid=0, channelType=Browser}

I replaced some parts with xxxxxx

Edit_3:

I think I got it. Maybe it's a bug?

At first some code:

function testFunction()
{
    gwtAdapter("testFunction", '{"gwtIndexGuiReady":true, "xxxxx":1000, "isNewItem":true}', testFunc2);
}

function testFunc2()
{
    gwtAdapter("testFunc2", '{"gwtIndexGuiReady":true, "xxxxx":1000, "isNewItem":true}', voidFunction);
}

function voidFunction(response)
{
    console.log("voidFunction called");
    if(typeof response !== 'undefined')
    {
        console.log("voidFunction-response: " + response);
    }
}

Steps to reproduce error:

  1. Start JxBrowser
  2. Open DevTools
  3. Set breakpoint on app.sendMessage in gwtAdapter
  4. Call testFunction();
  5. See how the bridge is not working correctly on second gwtAdapter call

First function call (sendMessage from testFunction) is working fine but the second function call (sendMessage from testFunc2) will not work.

A little explanation:

the last parameter from gwtAdapter is a callback, which will be executed from Java (where function is the callback as JSFunction):

    JSValue jsValue = mainBrowser.executeJavaScriptAndReturnValue("window");

    logger.info("Call callback for: " + name);

    function.invoke(jsValue.asObject(), messageMap.get(name));

in this callback there is another call to gwtAdapter and sendMessage will break there or in other words it hangs at sendMessage for about 8:30minutes and then passes this function.

Edit_4:

Maybe it's a threading problem? I think it's executing the javascript-callback and in this callback it tries to execute a function in Java (sendMessage). I think it can't execute javascript and receive calls parallel.

dominic.e
  • 286
  • 3
  • 17
  • 1
    The log messages are very important in this case. For example, I see in the OnConsoleMessage message that there's error in JavaScript code — 'Error in gwtAdapter: undefined', lineNumber=110, sourceId='file:///workspace/xxxxxx/processes/Contents/Login/js/functions.js' it looks like Java callback isn't invoked because of some errors in JavaScript code. Please make sure that JavaScript code doesn't throw any error in the gwtAdapter() function. – Vladimir May 11 '16 at 08:17

2 Answers2

0

Yesterday TeamDev released version 6.4 (Chromium v49) for jxBrowser in which the problem is solved.

dominic.e
  • 286
  • 3
  • 17
0

We had a similar problem recently.

We found this solution:

  • Keep a reference to your passed JavascriptBridge objects elsewhere in your application (eg. static variable).

We believe the cause of the problem is this:

  • The object might get garbage-collected at some time. And this is when the bridge object stops working.
  • For an unknown reason JX does not hold a reference to that object the way java usually does, which makes it eligable to garbage-collection.
  • By keeping the reference in your java-side-app this can't happen.
Frederic Leitenberger
  • 1,949
  • 24
  • 32