htmlandroid-webviewbox-view-api

viewer.js invoking 'fail' event in Android WebView


I'm currently trying to make the HTML5 viewer.js example work inside an android WebView.

WebView initialization looks like this:

webView.setWebViewClient(new WebViewClient());
final WebSettings webSettings = webView.getSettings();
settings.setJavaScriptEnabled(true);
webView.loadUrl("file:///android_asset/index.html");

The thing is that in a Nexus 7 running Android 4.3 JB (which uses Chrome as stock browser) the example fails and renders: Error loading document metadata (did you check the url?). I also tried a Samsung Galaxy Nexus running 4.2 with same results.

But on a GBox (MediaBox, Android TV) running Android 4.0.4 ICS (which uses the default Browser application), it takes a while but it renders the document. With a lot of styles problems, but it can render it.

However, if I serve all the assets from a remote server (for instance, a Python SimpleHttpServer) and load the WebView using the index page url, it doesn't have any problems in any device.

Is this a Crocodoc View API specific issue regarding cross-browsing?


Solution

  • This is a Chrome-specific issue, see here: Problems with jQuery getJSON using local files in Chrome

    In summary, Chrome's security model blocks AJAX requests from file:/// URLs. This causes trouble for viewer.js because it utilizes AJAX to load resources in a performance optimized manner. The recommended solution is to always serve the assets through a web server.