ABOUT US

|

SUPPORT

|

BLOG

DOWNLOADS    

 

 

 

 


 

 

DOM Modification

 

 

 

 

 

 

Although onDocumentComplete is triggered immediately after a page has completed loading, some web pages contain scripts that subsequently modify the page's DOM[1], which has the potential to cause unexpected (but not incorrect) rendering of pages.  For example, if the JavaScript onLoad() function (which also triggers immediately after a page has completed loading) changes images on the page, these images may not not be present in the DOM or have completed loading (depending on the timing of the JavaScript modification to the DOM, and network speed) at the time savePageImageToDisk was called.

Similar issues arise with animating GIF images, and other systems that dynamically change the appearance or content of pages.
  The rendered image will always reflect the current state of the page at the time that savePageImageToDisk is called.

One possible solution for pages that post-modify the DOM on document load is to insert a short time delay to allow for any document changes to take effect before saving the image, as shown below:

 

 

browser.addNetworkListener( new NetworkAdapter() {
              public void onDocumentComplete( com.webrenderer.event.NetworkEvent e ) {
                            try {
                                          Thread.sleep(1000);          // 1 second delay
                            } catch ( InterruptedException ex ) {
                                          System.out.println("Thread Interrupted: " + ex);
                            }
                            browser.savePageImageToDisk(new File("loadedpage.jpg"), IBrowserCanvas.IMAGE_FORMAT_JPG);
              }
});

 

[1]DOM - the Document Object Model, the internal hierarchical representation of the page structure.

 

 

 

 

 

 Copyright © JadeLiquid Software - www.jadeliquid.com