Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android webview cannot load certain page

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

like image 982
doomguy Avatar asked Nov 08 '22 09:11

doomguy


1 Answers

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.

like image 194
doomguy Avatar answered Nov 15 '22 04:11

doomguy