ABOUT US

|

SUPPORT

|

BLOG

DOWNLOADS    

 

 

 

 


 

 

Capturing network and browser activity

 

 

 

 

 

 

WebRenderer supports a complete set of events that provide for the capturing of many different browser and network related activities. The com.webrenderer.swing.event package is the package containing all WebRenderer event classes.

BrowserEvents

The BrowserEvent is the class that supplies all browser interface related events (navigation, link and title change etc.). Two key methods in the BrowserListener interface are the onBeforeNavigate and the onLoadIntercept methods. The onBeforeNavigate method is fired when navigation is occuring. Through onBeforeNavigate the URL and POST information are made available. onLoadIntercept is fired before a URL navigation begins and provides the opportunity to block the URL load (e.blockLoad). Because of the timing in which this event is fired POST information is not available.

The BrowserListener interface:

onBeforeNavigate is fired as WebRenderer navigates to a page. This event can be fired through the clicking on a link, JavaScript within a page right through to a WebRenderer loadURL. onBeforeNavigate is used to signal the start of a transaction from page to page.

Example usage:
 
Browser.addBrowserListener(new BrowserAdapter() {
        public void onBeforeNavigate(BrowserEvent e) {
                // Page navigation occurring
        }
});

        
onLoadIntercept is much like the onBeforeNavigate method with the exception that it can block the load of a page. This method is useful in filtering URL loads to any set criteria such as domain specific.
 
Example usage:
 
browser.addBrowserEvent(new BrowserAdapter() {
        public void onLoadIntercept(BrowserEvent e) {
                if(e.getURL().contains("jadeliquid.com")) {
                        // Blocking the load of the URL
                        e.blockLoad();
                }
        }
});


If the blockLoad method is not called the page will load as normal after the onLoadIntercept method returns.

Other methods available through the NetworkListener

// Deprecated. Use MouseListener
void onContextMenu(BrowserEvent e)

// Invoked when the link message changes in a browser
void onLinkChange(BrowserEvent e)
 
// Invoked when the loading of a URL is prematurely stopped
void onNavigationCancelled(BrowserEvent e)
 
// Invoked when the title changes in a browser
void onTitleChange(BrowserEvent e)
 
// Invoked when the URL changes in a browser
void onURLChange(BrowserEvent e)

NetworkEvents

The NetworkEvent class supplies all network transaction activity and page load status. The NetworkEvent class contains the single most important event in the WebRenderer package; the onDocumentComplete(NetworkEvent e). onDocumentComplete signals the completion of a document load and signals when browser and DOM related "get" methods become populated.

Example:


browser.addNetworkListener(new NetworkAdapter() {
        public void onDocumentComplete() {
// Document has completed loading fire manipulation
        }
});


Other useful NetworkEvents include:

// Invoked when a document stops loading in a browser
onDocumentComplete(NetworkEvent e)  

// Invoked when a document starts loading in a browser.
onDocumentLoad(NetworkEvent e)

// Invoked from an IBrowserCanvas when before a HTTP request is sent.
onHTTPInterceptHeaders(NetworkEvent e)

// Invoked from an IMozillaBrowserCanvas when Http Response data is sent back from a request.
onHTTPResponse(NetworkEvent e)

// Invoked when an error occurs on the network.
onNetworkError(NetworkEvent e)

// Invoked when the status of the network has changed.
onNetworkStatus(NetworkEvent e)

// Invoked when the progress of a document download changes.
onProgressChange(NetworkEvent e)


MouseEvents

The MouseEvent class handles all mouse click interaction on WebRenderer. MouseEvents are fired for mouse clicks and button presses. It is important to note that the WebRenderer MouseEvent has the same name as the java.awt.event.MouseEvent, and so does its listeners MouseListener and MouseAdapter. An explicit import must be made to the package these events are located in otherwise they will not fire.

Example:

browser.addMouseAdapter(new com.webrenderer.swing.event.MouseAdapter() {
        public void onClick(com.webrenderer.swing.event.MouseEvent e) {
                if ((e.getModifiers() & 4)>0) {
                        System.out.println("Right Button Pressed");
                } else {
                        System.out.println("Left Button Pressed");
                }
        }
});


KeyboardEvents

WebRenderer has an event set to handle all key presses. When using the keyboard event classes it is important to explicitly import the com.webrenderer.event because the naming is ambiguous with the java.awt.event.KeyEvent, KeyListener, KeyAdapter.

Example:

browser.addKeyListener(new com.webrenderer.swing.event.KeyAdapter() {
        public void onKeyPress(com.webrenderer.swing.event.KeyEvent e) {
                System.out.println("KeyEvent: " + e.getKeyChar());
        }
});

If any of the WebRenderer events are not firing please see the section on the
WebRenderer license dialog

 

 

 

 

 

Copyright JadeLiquid Software - www.jadeliquid.com