Android Question SOLVED - Cannot load page in webview

Robert Valentino

Well-Known Member
Licensed User
Longtime User
For years I have been using webview to load the website: https://www.leaguesecretary.com/

But I have received reports it is not longer working

I have created a test project. In the test project when you click on LoadURL every other time it tries to load https://www.leaguesecretary.com/ or load "www.bowlingbrackets.com"

The www.bowlingbrackets.com website loads fine (my website) but the https://www.leaguesecretary.com/ hangs until it times out.

Please a little help (bowling season is starting soon)

Thanks

BobVal

PS: the WebViewClient_ReceivedSslError routine never gets called
 

Attachments

  • Project.zip
    14.6 KB · Views: 40

JohnC

Expert
Licensed User
Longtime User
I looked at your code and I don't see where you are adding the ChromeClient, so try that:

 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
This version uses ChromeClient and CookiesManager

Same problem
 

Attachments

  • Project2.zip
    14.7 KB · Views: 40
Last edited:
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
I saw this posting: https://www.b4x.com/android/forum/threads/loadurl-problem.145275/#post-923000 and Erel asked if it worked with iHttpUtils2

So, I decided to add this code to my Click routine
B4X:
            If  mOneOrTheOther Then
                Try
                    Dim job As HttpJob
                    job.Initialize("", Me)
                    job.Download("www.leaguesecretary.com")
                    Wait For (job) JobDone (job As HttpJob)
                    If job.Success Then
                        Dim Data As String = job.GetString
                        mWebViewExtras.LoadHtml(Data)
                    Else
                        Dim Error As String = job.ErrorMessage
                        mWebViewExtras.LoadHtml(Error)
                    End If
                Catch
                    Log(LastException.Message)
                End Try
                job.Release                
                
'                mWebViewExtras.LoadUrl("www.leaguesecretary.com")
            Else
                mWebViewExtras.LoadUrl("www.bowlingbrackets.com")
            End If

The waiting for jobDone works fine and I can display the data (looks funny - no icons / formating) in LoadHtml.

So why isn't LoadUrl working for this site?
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Maybe this webview might work better:

 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I'm out of ideas.

But, I did notice that when I load that page into a desktop firefox browser and display the dev toolbox, there is a lot of stuff loaded into that page from other domains.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
YES, I noticed that too but there is nothing I can do about that stuff (not my website) - So many Ads

Will, keep looking. There has to be someway to load this page in a WebView or something is wrong with WebView
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Here is what ChatGPT says - maybe there is a hint somewhere in here:

When using Android's WebView to load webpages, there are several factors that could cause a page to time out while another loads successfully. Let's look into some common reasons why https://www.leaguesecretary.com/ might be timing out:

1. Page Requirements and Compatibility

  • JavaScript and Advanced Features: Some websites require advanced JavaScript or specific browser capabilities that might not be enabled or fully supported in a WebView. If League Secretary uses complex JavaScript or web features that WebView isn't handling well, it could lead to timeouts.
  • Webview Configuration: If the WebView is not set up to support JavaScript or if certain WebView settings are disabled (like cookies, DOM storage, etc.), the website might not load correctly.

2. Network and Security Issues

  • HTTP vs. HTTPS: Websites that use HTTPS might not load correctly if there are issues with the SSL/TLS configuration on either the server or the client side. WebView might also have issues if SSL errors are not handled properly.
  • Certificate Errors: WebView might encounter SSL certificate errors that a regular browser doesn't show, depending on your WebView setup (e.g., webViewClient.onReceivedSslError might need to handle these errors).
  • Timeout Settings: The WebView could be timing out due to network latency or restrictions on the device or network, particularly if the timeout settings are lower than required to load the page.

3. Server-side Issues

  • Server Configuration: The server hosting the website might have certain configurations or blocks in place that prevent loading from WebView. For example, some websites block requests from specific user agents or restrict loading to known browsers.
  • Traffic Filtering: If the website implements firewall or security rules that block non-standard traffic or detects your WebView as a bot or harmful request, it might prevent loading.

4. WebView Settings

  • Make sure you have enabled JavaScript in your WebView:
B4X:
WebView webView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true); // Enables DOM storage
webSettings.setUseWideViewPort(true); // May help in some cases
webSettings.setLoadWithOverviewMode(true); // May help in some cases

5. Error Handling in WebView

  • Implement a WebViewClient to handle errors and debug further:
B4X:
webView.setWebViewClient(new WebViewClient() {
    @Override
    public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
        // Handle the error
        Log.e("WebViewError", "Error: " + error.toString());
    }

    @Override
    public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
        // Handle SSL error
        handler.proceed(); // Ignore SSL certificate errors (not recommended for production)
    }
});

6. Testing in a Browser

  • Test the URL in the Chrome browser on the Android device to see if it loads correctly. If it loads in Chrome but not in WebView, the issue is likely with WebView settings or capabilities.
  • Also, try testing the same page on different networks to rule out network-specific issues.

Steps to Troubleshoot

  1. Enable JavaScript and DOM Storage in WebView settings.
  2. Check for SSL errors using WebViewClient.
  3. Debug Logs: Add logging to see if there is an error or specific event when it times out.
  4. Network Check: Try different networks or a VPN to see if it's a network-related issue.
  5. User-Agent: Consider setting the WebView's user agent string to mimic a common browser to see if that affects loading:
B4X:
String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3";
webSettings.setUserAgentString(userAgent);

Conclusion

Try these steps, and if the issue persists, it might require more specific network analysis or checking if there are updates or patches for the website or WebView.
 
Upvote 0

Robert Valentino

Well-Known Member
Licensed User
Longtime User
Using WebViewSettings, I tried as many of the above as I could.

Still nothing.

I think #6 is the answer that something is wrong with our WebView (but I could be wrong - what would that be now the 2nd time in my 73 years of life... LOL 2nd trillion maybe). LOL

Thanks for trying. ANYBODY have any other ideas
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
One last thing to try is see if there is an update to the "Webview" control in the google play store.
 
Upvote 0
Top