5

I have a simple webview to display web pages via the network. It loads most pages fine but whenever I try to load http://www.nytimes.com, it shows up as blank. The logcat at this point is:

09-11 11:26:18.428 10567-10630/com.project.test.webviewtest W/cr_media: Requires BLUETOOTH permission
09-11 11:26:18.454 10567-10567/com.project.test.webviewtest W/cr_AwContents: onDetachedFromWindow called when already detached. Ignoring
09-11 11:26:18.470 10567-10567/com.project.test.webviewtest I/cr_Ime: ImeThread is not enabled.
09-11 11:26:18.486 10567-10650/com.project.test.webviewtest D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
09-11 11:26:18.512 10567-10657/com.project.test.webviewtest E/libEGL: validate_display:255 error 3008 (EGL_BAD_DISPLAY)
09-11 11:26:18.530 10567-10650/com.project.test.webviewtest I/OpenGLRenderer: Initialized EGL, version 1.4
09-11 11:26:18.538 10567-10657/com.project.test.webviewtest W/VideoCapabilities: Unrecognized profile 2130706433 for video/avc
09-11 11:26:18.557 10567-10657/com.project.test.webviewtest I/VideoCapabilities: Unsupported profile 4 for video/mp4v-es
09-11 11:26:18.926 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:18.946 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:18.963 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:19.313 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:19.315 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:19.316 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:19.339 10567-10567/com.project.test.webviewtest W/cr_BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 10567
09-11 11:26:19.438 10567-10628/com.project.test.webviewtest W/chromium: [WARNING:spdy_session.cc(2462)] Received HEADERS for invalid stream 3

My MainActivity :

public class MainActivity extends AppCompatActivity {
private WebView mWebView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    mWebView = (WebView) findViewById(R.id.activity_main_webview);
    WebSettings webSettings = mWebView.getSettings();
    webSettings.setJavaScriptEnabled(true);
    mWebView.getSettings().setDomStorageEnabled(true);
    mWebView.setWebViewClient(new TestWebViewClient());
    mWebView.loadUrl("http://www.nytimes.com");
}
}

My TestWebViewClient:

public class TestWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
    view.loadUrl(url);
    return true;
}

@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
    Log.i("WEB_VIEW_TEST", "error code:" + errorCode);
    super.onReceivedError(view, errorCode, description, failingUrl);
}
}

I have added the INTERNET permission in the manifest. So far any other web page I have tried loads up fine. Just this one shows up as blank. I am not sure if the logcat shows the actual error as some things such as the EGL_BAD_DISPLAY and the Cannot call determinedVisibility() errors often show up in the successful loads as well. I don't usually see the last line [WARNING:spdy_session.cc(2462)] Received HEADERS for invalid stream 3 so maybe this is a cause of concern? I do not see any error being received in the onReceivedError in the TestwebViewClient.

Also sometimes (rarely), when I launch the app after a fresh install, the New York Times page title does show up for a second before the view going blank, which probably suggests this is a rendering issue and not a problem with the web view.

I am running this on a physical device running Android M.

Update: I tried printing the url in the shouldOverrideUrlLoading and initially it goes to the correct redirected url: http://mobile.nytimes.com/?referer= but then it switches to data:text/html. I am not sure what to make of it and why it switches to this one. The redirection by itself should not be a problem as youtube.com correctly loads after getting redirected to m.youtube.com

doomguy
  • 401
  • 10
  • 26
  • 2
    I really wonder why is this asking for bluetooth permission? – Nikhil Sep 11 '16 at 18:39
  • interesting had not seen that, but even that shows up for successful loads. – doomguy Sep 11 '16 at 18:44
  • Can you try catching the error by overrinding onReceivedError method for webview (http://stackoverflow.com/questions/4997677/android-webview-onreceivederror) to see if it gives more context of the error. – shubham003 Sep 11 '16 at 19:00
  • Added that but the logcat does not show any error from there. I am thinking this is a page rendering issue and not a problem with the webview maybe – doomguy Sep 11 '16 at 19:10
  • can you try to open that website on same device in browser? ( outside of your app) and share results – Amod Gokhale Sep 12 '16 at 03:02
  • I am able to load the page on my phone's chrome browser. – doomguy Sep 12 '16 at 04:08
  • Also, if I do not set the webview client, the page redirects and opens properly in the browser instead of the webview. – doomguy Sep 12 '16 at 04:16
  • 1
    @doomguy Have you try to open this - http://mobile.nytimes.com/international/ – Dipali Shah Sep 13 '16 at 05:24
  • @Dipalishah that one actually opens fine! – doomguy Sep 13 '16 at 05:29
  • @Dipalishah any idea what's going on? – doomguy Sep 13 '16 at 13:38
  • @doomguy this scenario can be possible - sometimes browser websites are too heavy or huge to load in webview at that time force to load twice or use mobile version of that site. Check this -http://stackoverflow.com/questions/18112715/webview-must-be-loaded-twice-to-load-correctly – Dipali Shah Sep 13 '16 at 13:43
  • @Dipalishah I tried the post Runnable methods on that link but they did not work. Also it is unable to load http://mobile.nytimes.com/ as well, only the international link you gave was loading. I also tried calling loadUrl twice with did not work either. – doomguy Sep 13 '16 at 14:28
  • @doomguy Convert your activity in fragment. I am not sure about is that will be helpful or not but for some user it solves the problem. So i will suggest you try and error method- http://stackoverflow.com/questions/31159149/using-webview-in-fragment/31159185#31159185 – Dipali Shah Sep 14 '16 at 05:28

4 Answers4

1

So i figured out the issue but still don't know the cause. The page opens if I comment out shouldOverrideUrlLoading in TestWebViewClient. I am not sure why this is a problem for just this page but it works for other pages.

doomguy
  • 401
  • 10
  • 26
0

Try to change http://www.nytimes.com to https://www.nytimes.com

It is not allowed to load unsecure URL's

Black
  • 18,150
  • 39
  • 158
  • 271
0

I had this problem and removing

view.loadUrl(url);

from shouldOverrideUrlLoading solved my problem. maybe help you.

ahzare
  • 1
  • 1
0

You can try this website (from official android.com) https://developer.android.com/guide/webapps/webview

Security Coding
  • 119
  • 1
  • 9