Migration

In JxBrowser 6.1 several changes to public API have been introduced. These changes may require changes to your application’s source code. This short guide shows how to change your application’s source code written with JxBrowser 6.0.2 API to JxBrowser 6.1 API.

Frames IDs

6.0.2

In 6.0.2 the Browser.getFramesIds() method returns IDs of all frames on the currently loaded web page. It doesn’t allow getting IDs of the frames located inside another frame.

Set<Long>framesIds=browser.getFramesIds();

6.1

Now, the Browser.getFramesIds() method returns IDs of the main frame only. To get IDs of the frames located inside another frame the Browser.getFramesIds(long frameId) method has been introduced.

Working with BrowserFunction

6.0.2

To register global JavaScript function the Browser.registerFunction(String functionName, BrowserFunction function) method is used. Every time when a web page is loaded, JxBrowser creates a function with the functionName and attach it to the window JavaScript global object.

publicvoidonBeforeURLRequest(BeforeURLRequestParamsparams){if("POST".equals(params.getMethod())){UploadDatauploadData=params.getUploadData();UploadDataTypedataType=uploadData.getType();if(dataType==UploadDataType.FORM_URL_ENCODED){FormDatadata=(FormData)uploadData;data.setPair("key1","value1","value2");data.setPair("key2","value2");}elseif(dataType==UploadDataType.MULTIPART_FORM_DATA){MultipartFormDatadata=(MultipartFormData)uploadData;data.setPair("key1","value1","value2");data.setPair("key2","value2");data.setFilePair("file3","C:\\Test.zip");}elseif(dataType==UploadDataType.PLAIN_TEXT){TextDatadata=(TextData)uploadData;data.setText("My data");}elseif(dataType==UploadDataType.BYTES){BytesDatadata=(BytesData)uploadData;data.setData("My data".getBytes());}// Apply modified upload data that will be sent to a web server.params.setUploadData(uploadData);}}

In 6.1 version JavaScript Java Bridge API has been updated. Now, you don’t need to wrap Java primitive types into JSValue to pass them to JavaScript side. You can use Java primitive types directly. They will be wrapped automatically by JxBrowser.