1

This is a strange issue but I'm not sure what to try from here. In my app users can open various links, for which I have provided a Fragment with a WebView. A significant percentage of these links are Imgur albums, but for some reason the albums do not load properly in WebView on my device or emulators that I have tried. I have set up an app with a single WebView that displays the behavior here: https://github.com/damien5314/imgur-album-webview.

I set up WebView debugging in Chrome, and loaded the page side-by-side in the WebView, as well as on desktop Chrome with mobile emulation enabled. On desktop Chrome, the page loads after receiving a response from api.imgur.com with the list of images, then downloads and displays the individual images after page load. On the WebView on my device, the images are never downloaded after receiving the response from the Imgur API.

Note - Only Imgur album pages are giving me issues. Individual images load just fine.

mWebView.loadUrl("http://imgur.com/a/2dtj8"); // Album, does not load images
// mWebView.loadUrl("https://imgur.com/X2eInSx"); // Single image, works fine

I want to say this is an Imgur issue with their JS on Android, but since the JS is obfuscated my web debugging options are limited, not to mention I can load the same link in a WebView in a similar app, so there must be some way to make it work. If someone sees any problem in my code let me know, otherwise any suggestions for the next steps to debug this issue would be appreciated. Thanks!

Damien Diehl
  • 383
  • 4
  • 13
  • I haven't gotten the chance to look into this again, but I will likely try debugging a little more, then maybe get in contact with an Imgur dev as this issue is specific to their site. – Damien Diehl Jul 30 '15 at 04:12
  • I read that it was an update by Google that broke the WrbView and it was affecting all apps, but when I test, it's only my all that doesn't work – SpaceMonkey Jul 30 '15 at 10:08
  • 1
    Yep exactly, if I go to the same link in another similar application, it looks like they're just using a regular WebView as I am, but for some reason it works in their app. I might investigate into WebView options a little more and see if there's not some JS-related configuration that needs to be done (obviously I'm enabling JS, but maybe something deeper than that). – Damien Diehl Jul 30 '15 at 16:05
  • @Spacemonkey The issue was DOM storage being disabled for my WebView (see my answer). Imgur depends on this functionality in the JS for album pages. – Damien Diehl Aug 13 '15 at 02:49

1 Answers1

6

Well, this was actually a lot easier than originally thought. I didn't notice a JavaScript error occurring on load of the page in WebView, which wasn't occurring when loading the page in Chrome.

Uncaught TypeError: Cannot read property 'getItem' of null

Upon tracing the JS, I found this was stemming from use of window.localStorage. This is not permitted in WebView unless the setting is enabled.

mWebView.getSettings().setDomStorageEnabled(true);

Credit to this answer: Android webview & localStorage

Community
  • 1
  • 1
Damien Diehl
  • 383
  • 4
  • 13