Q:

javafx webview javascript XMLHttpRequest responseType arraybuffer

I have a javafx application where i open a website in the webview and execute a javascript function.  In this js function i make XMLHttpRequest request to get pdf file and i am trying to send it back to the java.  The problem is with the encoding, because the pdf is binary and the response is converted to UTF-8 text.  My function right now look like this:
webEngine.executeScript(
  "function xhrDownload() {"                
  + "var req = new XMLHttpRequest();"        
  + "req.onload = function () {"
  + "if (req.readyState === req. DONE && req.status == 200) {"        
  + "java.sendData(req.responseText);"              
  + "}"
  + "};"
  + "req.open(\"GET\", \"https://xxxx/test.pdf\", false);"              
  + "req.send();"
  + "}xhrDownload();"

);
I tried to set the responseType ='arraybuffer' but i get this error:
Exception in thread "JavaFX Application Thread" netscape.javascript. JSException: InvalidAccessError (DOM Exception 15): The object does not support the operation or argument. 
at com.sun.webkit.dom. JSObject.fwkMakeException(JSObject.java:156)
at com.sun.webkit. WebPage.twkExecuteScript(Native Method)
at com.sun.webkit. WebPage.executeScript(WebPage.java:1509)
at javafx.scene.web. WebEngine.executeScript(WebEngine.java:1005)
at main.xhrDownload(main.java:77)
at main.lambda$0(main.java:54)
at com.sun.javafx.binding. ExpressionHelper$SingleChange.fireValueChangedEvent(ExpressionHelper.java:182)
at com.sun.javafx.binding. ExpressionHelper.fireValueChangedEvent(ExpressionHelper.java:81)
at javafx.beans.property. ReadOnlyObjectPropertyBase.fireValueChangedEvent(ReadOnlyObjectPropertyBase.java:74)
at javafx.beans.property. ReadOnlyObjectWrapper.fireValueChangedEvent(ReadOnlyObjectWrapper.java:102)
at javafx.beans.property. ObjectPropertyBase.markInvalid(ObjectPropertyBase.java:112)
at javafx.beans.property. ObjectPropertyBase.set(ObjectPropertyBase.java:146)
at javafx.scene.web. WebEngine$LoadWorker.updateState(WebEngine.java:1287)
at javafx.scene.web. WebEngine$LoadWorker.dispatchLoadEvent(WebEngine.java:1398)
at javafx.scene.web. WebEngine$LoadWorker.access$1200(WebEngine.java:1280)
at javafx.scene.web. WebEngine$PageLoadListener.dispatchLoadEvent(WebEngine.java:1267)
at com.sun.webkit. WebPage.fireLoadEvent(WebPage.java:2499)
at com.sun.webkit. WebPage.fwkFireLoadEvent(WebPage.java:2343)
at com.sun.webkit.network. URLLoader.twkDidFinishLoading(Native Method)
at com.sun.webkit.network. URLLoader.notifyDidFinishLoading(URLLoader.java:859)
at com.sun.webkit.network. URLLoader.lambda$didFinishLoading$103(URLLoader.java:850)
at com.sun.javafx.application. PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security. AccessController.doPrivileged(Native Method)
at com.sun.javafx.application. PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui. InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win. WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win. WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang. Thread.run(Unknown Source)

The main goal of this application is to download this pdf file.  But i cannot make just make request to the file url from java because this file is available only after you login to a website.(Session protected or something like that). 
Thanks in advance for any help :D

A:

I couldn't find any solution to my problem so i tried a different way.  I just open the pdf inside the WebView with the help of PDFjs library and then i take a snapshot of it.  At least i have an image of the file now.