0

Usually, when you click inside Android WebView page and transfer to another page, WebViewClient receives call to shouldOverrideUrlLoading method. But, this doesn't work with money.cnn.com. When I browse on money.cnn.com, I receive callbacks only into onPageStarted and into onPageFinished. Both only once. Browsing inside the site after doesn't give any callbacks to WebViewClient. If I browse only inside the money.cnn.com my log shows only these two lines. No more, no less.

> 10-14 14:10:25.581 28886-28886/com.myapp I/MyApp: onPageStarted
> 10-14 14:10:36.822 28886-28886/com.myapp I/MyApp: onPageFinished

My code is:

mWebView.setWebViewClient(mSWWebViewClient);                        
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setDomStorageEnabled(true);
mWebView.loadUrl(getUrl());
WebViewClient mSWWebViewClient = new WebViewClient() {
    @Override
    public void onPageStarted(WebView view, String url, Bitmap favicon) {
       super.onPageStarted(view, url, favicon);
       Log.d("MyApp", "onPageStarted ");
    }


    @Override
    public void onPageFinished(WebView view, String url) {
       super.onPageFinished(view, url);
       Log.d("MyApp", "onPageFinished ");
    }


    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
       Log.d("MyApp", "shouldOverrideUrlLoading ");
    }
};

My question is why shouldOverrideUrlLoading doesn't receive callback at all, and how can I detect a change of the content of this site while browsing through it?

Edition Finally, I have finished with the solution https://stackoverflow.com/a/40551880/955321

Shivam Kumar
  • 1,892
  • 2
  • 21
  • 33
Michael Katkov
  • 2,256
  • 1
  • 20
  • 17
  • Use `public WebResourceResponse shouldInterceptRequest (WebView view, WebResourceRequest request)` http://stackoverflow.com/questions/26651586/difference-between-shouldoverrideurlloading-and-shouldinterceptrequest – Morrison Chang Oct 14 '16 at 18:55
  • No, it is not what I mean. I need to intercept the main url of the page, not the every url for every content – Michael Katkov Oct 15 '16 at 14:39
  • I'm not clear based on your last comment what you are looking for. My only suggestions are to use `shouldInterceptRequest` to monitor XmlHttpRequests. And use Chrome debugging tools https://developers.google.com/web/tools/chrome-devtools/remote-debugging/ to see how the page is written and to see how content is loaded. – Morrison Chang Oct 15 '16 at 15:05
  • I thought you recommend me to use shouldInterceptRequest instead of shouldOverrideUrlLoading. Actually, the site use html 5 and dom storage. It made me add mWebView.getSettings().setDomStorageEnabled(true). The site showed infinite loading without that line of code. The problem is: I need to show different views over the main webview, depending on what type of content appears: the main page or an article. But, I don't receive any callbacks when I surf from the main page deeper inside. Morrison, maybe you've faced already a situation like that? – Michael Katkov Oct 15 '16 at 15:35

0 Answers0