title: JxBrowser LoadURL/LoadHTML
body: <p>I am having issues with JxBrowser when loading html files from my local directory. I have used loadHTML and loadURL in my project. In the below instance, when I use loadURL inside a browserInvokeAndWait method I am finding it takes too long and is not able to reference my Javascript library as needed. I am trying to enable buttons in my loaded page, however I cannot access any of the loaded elements as the page cannot load itself. Code is below:
      package src.java;</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  
  import javax.swing.JFrame;
  
  import com.teamdev.jxbrowser.chromium.Browser;
  import com.teamdev.jxbrowser.chromium.Callback;
  import com.teamdev.jxbrowser.chromium.JSValue;
  import com.teamdev.jxbrowser.chromium.dom.By;
  import com.teamdev.jxbrowser.chromium.dom.DOMDocument;
  import com.teamdev.jxbrowser.chromium.dom.DOMElement;
  import com.teamdev.jxbrowser.chromium.dom.events.DOMEvent;
  import com.teamdev.jxbrowser.chromium.dom.events.DOMEventListener;
  import com.teamdev.jxbrowser.chromium.dom.events.DOMEventType;
  import com.teamdev.jxbrowser.chromium.events.FinishLoadingEvent;
  import com.teamdev.jxbrowser.chromium.events.LoadAdapter;
  import com.teamdev.jxbrowser.chromium.events.ScriptContextAdapter;
  import com.teamdev.jxbrowser.chromium.events.ScriptContextEvent;
  import com.teamdev.jxbrowser.chromium.swing.BrowserView;
  
  public class VisualFrame {
  
  public VisualFrame(final Graph&lt;GNode&gt; dagGraph, final GNode rootGNode, final Browser browser, final BrowserView view, final JFrame frame){
      frame.setTitle("Visualisation");
      frame.setResizable(false);
  
      browser.addScriptContextListener(new ScriptContextAdapter() {
          @Override
          public void onScriptContextCreated(ScriptContextEvent event) {
              Browser browser = event.getBrowser();
              JSValue window = browser.executeJavaScriptAndReturnValue("window");
              window.asObject().setProperty("java", new CytoData(dagGraph, rootGNode));
              JSValue document = browser.executeJavaScriptAndReturnValue("document");
              document.asObject().setProperty("java", new Graph&lt;GNode&gt;());
          }
      });
  
  
      browser.addLoadListener(new LoadAdapter() {
          @Override
          public void onFinishLoadingFrame(FinishLoadingEvent event) {
              if (event.isMainFrame()) {
                  System.out.println("Has Reached");
                  event.getBrowser().executeJavaScript("var nodes = [];"
                          + "var myArray = new Array();"
                          + "myArray = new Array(window.java.getNodes());"
                          + "var nodes = myArray.toString();"
                          + "nodes = nodes.replace('[','');"
                          + "nodes = nodes.replace(']','');"
                          + "nodes = nodes.split(',');"
                          + "var cy = cytoscape({"
                          + "container: document.getElementById('cy'),"
                          + "boxSelectionEnabled: false,"
                          + "autounselectify: true,"
                          + "style: cytoscape.stylesheet()"
                          + ".selector('node')"
                          + ".css({'content': 'data(id)'})"
                          + ".selector('edge')"
                          + ".css({'curve-style': 'bezier','target-arrow-shape': 'triangle',"
                          + "'width': 4,'line-color': '#ddd','target-arrow-color': '#ddd'})"
                          + ".selector('.highlighted')"
                          + ".css({'background-color': '#61bffc','line-color': '#61bffc',"
                          + "'target-arrow-color': '#61bffc',"
                          + "'transition-property': 'background-color, line-color, target-arrow-color',"
                          + "'transition-duration': '0.5s'}),"
                          + "});"
                          + "var elementCounter = 0;"
                          + "for (i = 0; i &lt; window.java.getSizeOfDAG(); i++) {"
                          + "var currentNode = nodes[i].trim();"
                          + "var eles = cy.add({group: 'nodes', data: { id:currentNode}});"
                          + "elementCounter++}"
                          + "elements: [eles];");
                  event.getBrowser().executeJavaScript("for (i = 0; i &lt; window.java.getSizeOfDAG(); i++) {"
                          + "var newCurrentNode = nodes[i].trim();"
                          + "window.alert(newCurrentNode);"
                          + "var holdArray = window.java.getLinkedNodeIDs(newCurrentNode);"
                          + "var targetNodes = holdArray.toString();"
                          + "targetNodes = targetNodes.replace('[','');"
                          + "targetNodes = targetNodes.replace(']','');"
                          + "targetNodes = targetNodes.split(',');"
                          + "for (x = 0; x &lt; targetNodes.length; x++){"
                          + "var targetString = targetNodes[x].trim();"
                          + "eles = cy.add({group: 'edges', data: { id: elementCounter, source:newCurrentNode.trim(), target:targetString.trim()}});"
                          + "elementCounter++;"
                          + "cy.layout({"
                          + "name: 'breadthfirst', "
                          + "fit: true, "
                          + "directed: true,"
                          + "padding: 15,"
                          + "spacingFactor: 1,"
                          + "avoidOverlap: true}).run();"
                          + "}}");
              }
          }
      });
  
      Browser.invokeAndWaitFinishLoadingMainFrame(browser, new Callback&lt;Browser&gt;(){
          @Override
          public void invoke(Browser arg0) {
              browser.loadURL("file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html");
          }
      });
  
  
  
  
      InputStream urlStream = getClass().getResourceAsStream("../web/UserInputForm.html");
  
      String html = null;
  
      try (BufferedReader urlReader = new BufferedReader(new InputStreamReader (urlStream))) {
          StringBuilder builder = new StringBuilder();
          String row;
          while ((row = urlReader.readLine()) != null) {
                  builder.append(row);
          }
          html = builder.toString();
      }  catch (IOException e) {
              throw new RuntimeException(e);
      }
  
      final String loadHTMLPath = html;
  
      DOMDocument document = browser.getDocument();
      final DOMElement documentElement = document.getDocumentElement();
      System.out.println(browser.getHTML());
      if (documentElement != null) {
          try{
              DOMElement element = documentElement.findElement(By.id("resetBtn"));
              element.addEventListener(DOMEventType.OnClick, new DOMEventListener() {
                  public void handleEvent(DOMEvent event) {
                      System.out.println(event);
                      browser.loadURL("file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/UserInputForm.html");
                      new UserInput(browser, view, frame);
                  }
              }, false);
          }catch(NullPointerException e){
              System.out.println("NULL");
          }
  
      }
  
      if (documentElement != null) {
          try{
              DOMElement element = documentElement.findElement(By.id("finishBranchBtn"));
              element.addEventListener(DOMEventType.OnClick, new DOMEventListener() {
                  public void handleEvent(DOMEvent event) {
                      browser.loadHTML(loadHTMLPath);
                  }
              }, false);
          }catch(NullPointerException e){
              System.out.println("NULL");
          }
  
      }
  
      if (documentElement != null) {
          try{
              DOMElement element = documentElement.findElement(By.id("backBtn"));
              element.addEventListener(DOMEventType.OnClick, new DOMEventListener() {
                  public void handleEvent(DOMEvent event) {
                      browser.loadHTML(loadHTMLPath);
                  }
              }, false);
          }catch(NullPointerException e){
              System.err.println("Caught Exception: " + e.getMessage());
          }
  
      }
  
      if (documentElement != null) {
          try{
              DOMElement element = documentElement.findElement(By.id("nextBtn"));
              element.addEventListener(DOMEventType.OnClick, new DOMEventListener() {
                  public void handleEvent(DOMEvent event) {
                      browser.loadHTML(loadHTMLPath);
                  }
              }, false);
          }catch(NullPointerException e){
  
              System.err.println("Caught Exception: " + e.getMessage());
          }
  
      }
  }
  }
  </code></pre>
  
  <p>I don't quite understand why the loadURL takes so long, and when I attempt the loadHTML technique, I find this doesn't work. I am missing something quite fundamental in regards to the difference between these two methods. </p>
  
  <p>Thanks in advance, 
  Jack</p>
  
  <p>EDIT 
  Chromium.log 
  Feb 27, 2018 1:45:42 PM com.teamdev.jxbrowser.chromium.internal.ipc.a run
  SEVERE: [0227/134542.952445:ERROR:browser_process_stub.cpp(61)] Not implemented reached in virtual ProfileManager *BrowserProcessStub::profile_manager()</p>
  
  <p>IPC Log
  - FINE: WRITE: LoadURLMessage{type=LoadURL, uid=796, url='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', frameId=-1, extraHeaders='null', postData='null', SocketInfo{cid=0, bid=0, channelType=Browser}</p>
  
  <ul>
  <li><p>FINE: READ:  OnHandleLoadMessage{type=OnHandleLoad, uid=9, url='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', loadType=5, loadPolicy=2, isRedirect=false, isBackForward=false, cancel=false, SocketInfo{cid=0, bid=0, channelType=Render}</p></li>
  <li><p>FINE: WRITE: OnHandleLoadMessage{type=OnHandleLoad, uid=9, url='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', loadType=5, loadPolicy=2, isRedirect=false, isBackForward=false, cancel=false, SocketInfo{cid=0, bid=0, channelType=Render}</p></li>
  <li><p>FINE: READ:  OnShouldBeginRequestMessage{type=OnShouldBeginRequest, uid=878, browserContextId=-1, url='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', method='GET', resourceType=0, cancel=false, SocketInfo{cid=0, bid=-1, channelType=Main}
  Feb 27, 2018 1:45:42 PM 
  com.teamdev.jxbrowser.chromium.internal.ipc.MemoryChannelWriter run</p></li>
  <li><p>FINE: WRITE: OnShouldBeginRequestMessage{type=OnShouldBeginRequest, uid=878, browserContextId=-1, url='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', method='GET', resourceType=0, cancel=false, SocketInfo{cid=0, bid=-1, channelType=Main}</p></li>
  <li><p>FINE: READ:  OnDidCommitProvisionalLoadForFrameMessage{type=OnDidCommitProvisionalLoadForFrame, uid=879, frameId=2, url='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', isMainFrame=true, transitionType=1, SocketInfo{cid=0, bid=0, channelType=Browser}</p></li>
  <li><p>FINE: READ:  OnDidFinishLoadMessage{type=OnDidFinishLoad, uid=889, frameId=2, validatedURL='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', isMainFrame=true, SocketInfo{cid=0, bid=0, channelType=Browser}</p></li>
  <li><p>FINE: READ:  OnRunJavaScriptDialogMessage{type=OnRunJavaScriptDialog, uid=890, dialogId=1, originURL='file:///home/mbax4jo2/workspace/EditDistanceVisualisation/src/src/web/index.html', acceptLang='', messageType=0, messageText='bbc', defaultPromptText='', isReload=false, SocketInfo{cid=0, bid=0, channelType=Browser}</p></li>
  </ul>