Source:
public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webView = (WebView)getView().findViewById(R.id.course_unit_webView); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if ( callback != null ) callback.finishProcess(); if ( errorCode == HttpStatus.SC_FORBIDDEN || errorCode == HttpStatus.SC_UNAUTHORIZED ){ tryToLoadWebview(view); } super.onReceivedError(view, errorCode, description, failingUrl); } public void onPageFinished(WebView view, String url) { if ( callback != null ) callback.finishProcess(); String sessionIdRefreshUrl = Api.getSessionTokenExchangeUrl(); if ( url.equals(sessionIdRefreshUrl) ){ String cookies = CookieManager.getInstance().getCookie(url); String[] cookieValues=cookies.split(";"); for (int i = 0; i < cookieValues.length; i++) { String[] split = cookieValues[i].split("="); if ( split[0].trim().equals(PrefManager.Key.SESSION_ID) ){ PrefManager pref = new PrefManager(getActivity(), PrefManager.Pref.LOGIN); pref.put(PrefManager.Key.AUTH_ASSESSMENT_SESSION_ID, split[1]); pref.put(PrefManager.Key.AUTH_ASSESSMENT_SESSION_EXPIRATION, new Date().getTime() + 3600 * 24 * 1000 ); break; } } tryToLoadWebview(view); return; } view.loadUrl("javascript:EdxAssessmentView.resize(document.body.getBoundingClientRect().height)"); super.onPageFinished(view, url); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); webView.addJavascriptInterface(this, "EdxAssessmentView"); tryToLoadWebview(webView); }

Target:
public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); WebView webView = (WebView)getView().findViewById(R.id.course_unit_webView); webView.getSettings().setJavaScriptEnabled(true); webView.setWebViewClient(new WebViewClient() { @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { if ( callback != null ) callback.finishProcess(); if ( errorCode == HttpStatus.SC_FORBIDDEN || errorCode == HttpStatus.SC_UNAUTHORIZED || errorCode == HttpStatus.SC_NOT_FOUND){ tryToLoadWebview(view); } super.onReceivedError(view, errorCode, description, failingUrl); } public void onPageFinished(WebView view, String url) { if ( callback != null ) callback.finishProcess(); String sessionIdRefreshUrl = Api.getSessionTokenExchangeUrl(); if ( url.equals(sessionIdRefreshUrl) ){ String cookies = CookieManager.getInstance().getCookie(url); String[] cookieValues=cookies.split(";"); for (int i = 0; i < cookieValues.length; i++) { String[] split = cookieValues[i].split("="); if ( split[0].trim().equals(PrefManager.Key.SESSION_ID) ){ PrefManager pref = new PrefManager(getActivity(), PrefManager.Pref.LOGIN); pref.put(PrefManager.Key.AUTH_ASSESSMENT_SESSION_ID, split[1]); pref.put(PrefManager.Key.AUTH_ASSESSMENT_SESSION_EXPIRATION, new Date().getTime() + 3600 * 24 * 1000 ); break; } } tryToLoadWebview(view); return; } view.loadUrl("javascript:EdxAssessmentView.resize(document.body.getBoundingClientRect().height)"); super.onPageFinished(view, url); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { return false; } }); webView.addJavascriptInterface(this, "EdxAssessmentView"); tryToLoadWebview(webView); }