1
votes

I am trying to obtain the HTML contents of a BrowserComponent in CodenameOne by using this code:

browserComponent.executeAndReturnString("document.documentElement.outerHTML")

This works in the simulator, on iOS and on Android. In a UWP app executeAndReturnString never returns. Here is a runnable example (use in the start method of a new project):

BrowserComponent browserComponent = new BrowserComponent();
browserComponent.addWebEventListener(BrowserComponent.onLoad, evt -> {
    Log.p("onLoad start", Log.INFO);
    Log.p(browserComponent.executeAndReturnString("document.documentElement.outerHTML"), Log.INFO);
    Log.p("onLoad end", Log.INFO);
});

Form form = new Form("Browser Contents Test", new BorderLayout());
form.add(BorderLayout.CENTER, browserComponent);
form.show();

browserComponent.setURL("http://www.codenameone.com");

In a UWP app this is everything in the log:

[EDT] 0:0:1,837 - Codename One revisions: 7dd4e7d08b3442d90959477ee52a5ae8c4361b29
 
[EDT] 0:0:1,891 - onLoad start

I have tried the asynchronous BrowserComponent.execute methods and they do the same thing. Can anyone help me?

1
This is possibly a bug in the UWP port as fewer people use this port and it's the one port that doesn't use webkit. Please file an issue on that here: github.com/codenameone/CodenameOne/issues - Shai Almog
@ShaiAlmog okay thank you. I have added the issue. github.com/codenameone/CodenameOne/issues/3239. - Russ Hayward

1 Answers

0
votes

The executeAndReturnString issue has now been fixed. There was an additional issue that there is a limit on the length of the returned string. That is not fixed yet but it can be worked around with code like this:

browserComponent.executeAndReturnString("document.documentElement.outerHTML.substring(0, 1000)")