Reputation: 382
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!
Upvotes: 1
Views: 985
Reputation: 382
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
Upvotes: 6