I'm no good at webby stuff - I have a longstanding mental block about it. I want to display Bing maps in a WebView but I want it to have a desktop useragent. No Google Maps will not do because only Bing maps has online access to the jealously guarded Ordnance Survey 50K and 25K mapping for the...
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.
A new old acquaintance (UltimateWebView) returns on the first day of 2024. This library is my New Year's greeting to all the members of this really special forum, a forum that doesn't let the good old BASIC programming language go into oblivion. The new library is called UltimateWebView2 and is...
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.
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:
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
Enable JavaScript and DOM Storage in WebView settings.
Check for SSL errors using WebViewClient.
Debug Logs: Add logging to see if there is an error or specific event when it times out.
Network Check: Try different networks or a VPN to see if it's a network-related issue.
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.
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