Android WebView App displays white screen after clicking a link - android

Masters,
I have a question. I've been building an Android App using WebView. Inside the app are links that navigates to external pages(I don't have any control with the WebSite that is loaded inside webview). I have an issue when I clicked a link and logCat returns : I/chromium: [INFO:CONSOLE(10)] "Uncaught TypeError: Cannot read property 'appendChild' of null" App displays white screen only. Have you experienced this issue before? Are there any possible solutions? TIA

To clarify the extent of the problem
What you currently have problem is with
Inside the app are links that navigates to external pages.
I have an
issue when I clicked a link and logCat returns

As you haven't shared your code both for webview(Android) or html code.
As I am faced similar type of problem, So these are method which solved my problems
Method 1:
public boolean shouldOverrideUrlLoading(WebView view, String urlNewString) {
view.loadUrl(urlNewString); // you are using siteView here instead of view
return true;
}
Method 2: use http in url
Make sure the url starts with http://.
Without http it will just show white screen.

Related

Android flutter's flutter_webview_plugin plugin's webview shows loading indicator and nothing else

I have been building a flutter android app with flutter_webview_plugin. My problem is when I use back button of android phone the web view rather than closing shows the loading indicator and nothing else.
To solve this problem we will have to listen both the webview's onDestroy status and navigator's pop-ability and then we will pop the webview route (screen).
To do this we will just write this code within the build method where the WebviewScaffold is returned.
flutterWebviewPlugin.onDestroy.listen((_){
if(Navigator.canPop(context)){
Navigator.of(context).pop();
}
});
Problem solved :)
note flutterWebviewPlugin is an object of FlutterWebviewPlugin declared out of the build method.

Android 4.0.x (ICS) WebView does not update UI clicking <a> tags

I need WebView to show a HTML page A, there are hyperlink tags in page A, which will open page B when clicked. On action bar of my Activity, I have a Button which will call WebView.reload() when clicked. This should be a very simple case of WebView.
PROBLEM:
When running my app on Andorid 4.0.3 or 4.0.4, after click hyperlink ( tags) in page A, Android WevView stays on page A, nothing happend.
What-I-tried:
1. when the problem occurrs, click reload button, WevView is displaying page B correctly.
2. modify source code of page A and B, remove CSS code which affect how tag displays. Then WebView can jump to page B correctly after click hyperlinks in page A.
I think this is a bug in Android 4.0.x, It is not possilbe to remove CSS in HTML, I am stuck with the "reload solution".
Does anyone know the root cause of this bug or a better soluton?
Thanks
Use WebChromeClient for webView fucntionality it should work.Even then you are unable to load the html than debug your code and use alternative which function is not working . because java script and CSS both works in web view only the case if you have made mistake in java script or css thnt it should do strange behavior(not loading/blank load/hang screen).
Issue solved by WORKAROUND in web page source, not Android WebView.
add the following javascript inside html body:
try{
document.documentElement.clientHeight
} catch (e) {
};
above js trys to read web window height, but it will force a refresh of web page.
That's how this js solved this issue.
I guess this should be a bug in Android 4.0.3/4.0.4. But currently you can use this workaround to avoid it, only if your WebView load web pages developed by you.

Disable page forwarding in Android webview

I have a webview that shows ads (not my ads), the problem is when user clicks the "x" button to exit the ad, the ad still directs them to a site. What I wonder is since I can't control the ads, can I instead Disable page directing/forwarding inside webview? that means even if user clicks a link inside my webview nothing should happen.
You are looking for WebClient.shouldOverrideUrlLoading method.
webview.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading (WebView view, String url){
//True if the host application wants to leave the current WebView and handle the url itself, otherwise return false.
return true;
}
});
I tried using shouldOverrideUrlLoading, but it didn't work. It looks like that this method is called only once when the html is loaded. After that, you click a link but the method is no more invoked.
I am also making a WebView embedding Youtube Player. Instead of forwarding ads redirect from the WebView, I prefer to open ads in a browser. So I override onLoadResource method:
#Override
public void onLoadResource(final WebView view, final String url) {
if(url.indexOf("googleadservices.")>-1){
view.getSettings().setJavaScriptEnabled(false);
view.stopLoading();
view.postDelayed(
new Runnable(){
#Override
public void run(){
Uri uri=Uri.parse(url);
Intent i=new Intent(Intent.ACTION_VIEW,uri);
i.setClassName("com.android.browser","com.android.browser.BrowserActivity");
startActivity(i);
}
}
,100
);
}
}
It worked. When I clicked the ads link, a new browser is opened in which ads site is displayed well, and the WebView was not redirected. When I push the return button, WebView show up again and I can continue watching video.
But there were still problems. If I repeat opening browser and returning to WebView for many times, the WebView might fail to block redirecting to the ads site. It is just redirected to the ads site. If I am lucky I could repeat opening and returning for 100 times. But sometimes It failed just when I repeat several times. I don't know why.
Does anyboday have any idea about how to improve it? Or is there another way to disable ads redirect?
You can build undetected webview build-id adblocker
I know it is too late for answering this question, however, for the sake of others who have the same question.
Well, you can build webview build-id adblocker, if you wish to prevent ads from loading, and provide smooth experience to the users, I am confident, because I have already implemented it in may app.
The Idea
Is to have a black list of all possible ad-serves domain name, then while webview load resources, you will prevent loading from black list domains. so it depends on how many ads-serves domain you have in the black list, fortunately, there is one website (pgl.yoyo.org/as/) which provide you with a very long list of ad-serves domai names, and listed them in many flavoures.
you can read this article for:
how to implement webview build-id adblocker
, you will build it %100 as long as you follow step by step instructions.
A summary of what we need to do:
Get the list of ad hostnames from pgl.yoyo.org.
Save the list somewhere, load it when application starts.
UseWebViewClient.shouldInterceptRequest(WebView, String) to intercept
requests.
Check if the request URL belongs to one of the hostnames in
the list and override it, returning a dummy resource instead of the
actual one, which is supposed to be ads

FbDialog doesn't show full content on smaller devices

Steps to repro
Log in to FB with new FB account I can see the webdialog showing me
current goals and other stuff, but I can not see Authorize OK cancel
buttons(probably moved down). I can not scroll to see those buttons
Can any one suggest me quick fix, without necessarily updating FB SDK
I can confirm this is affecting Facebook SDK 2 and 3 in Android. I can't speak to iOS. For some reason, scrollbars are disabled in their WebDialog.java code so I tried enabling scrollbars in setUpWebView. Scrollbars now appear in this prompt but the OK and Cancel buttons aren't there. So, it's not a case of the buttons being off-screen and unreachable but rather the buttons aren't part of the content at all when the Current Goals section is included.
It looks like this is a problem Facebook will need to resolve on their side.
I just posted this workaround to: webDialog "CURRENT GOALS" header but no button to authorize or cancel
In the FaceBookSDK I modified com/facebook/widget/WebDialog.java, so that once the web dialog was loaded it would look for the block that contains "Current Goals" and hide it (if it exists). Once you do that, the buttons are visible again (at least they were for me).
In com/facebook/widget/WebDialog.java:
private class DialogWebViewClient extends WebViewClient {
// ... other methods ...
#Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
if (!isDetached) {
spinner.dismiss();
}
/*
* Once web view is fully loaded, set the contentFrameLayout background to be transparent
* and make visible the 'x' image.
*/
contentFrameLayout.setBackgroundColor(Color.TRANSPARENT);
webView.setVisibility(View.VISIBLE);
crossImageView.setVisibility(View.VISIBLE);
// I don't know how to highlight in the code block
// So I just add this extra long comment to make it obvious
// Add a javascript call to hide that element, if it exists
webView.loadUrl("javascript:try{ document.getElementById('nux-missions-bar').style.display='none'; } catch (e) {}");
// End changes
}
This should help, at least until FaceBook fixes the API.
I was facing the same problem which is solved. I just changed my app permission which was running in sandbox mode> I just changed it to live mode and suddenly everything started working fine. I think there was a problem with fb sdk which is solved by now.....

Google search links in the webview of my app opening of a blank page ..!

The webview with google search result links loaded in my android app, when I clicked on the links, it is opening up a blank screen.
I think, it is something to do with onmousedown event attached with every href links in the result page.
will be very thankful if I am provided with a way to handle this and make webview to actually openup the link that I am clicking on.
Here's another solution. After Google finishes loading the blank page you load the WebView with the previous page (which is the actual result) using the WebView's tag or a member variable. Like this:
#Override
public void onPageFinished(WebView view, String url)
{
System.out.println("onPageFinished: " + url);
if ("about:blank".equals(url) && view.getTag() != null)
{
view.loadUrl(view.getTag().toString());
}
else
{
view.setTag(url);
}
}
Here's my LogCat:
I/System.out(13182): onPageFinished: http://www.google.com/#hl=en&sugexp=les%3B&gs_rn=1&gs_ri=tablet-gws&cp=2&gs_id=9&xhr=t&q=amazon...
I/System.out(13182): onPageFinished: http://www.amazon.com/
I/System.out(13182): onPageFinished: about:blank
I/System.out(13182): onPageFinished: http://www.amazon.com/
I'm having the same problem. I get the "about:blank" page when I click on Google search results in a WebView in my Asus Transformer TF700 running 4.1.1. It doesn't happen in my Acer A100 tablet or other phones.
I noticed the result links work when I switch from Tablet to Classic version at the bottom of main Google Search Page.
https://www.google.com/?nota=1
If you remove the ?nota=1 in the above URL you won't see the Tablet option in your PC. In your tablet however the default google.com URL displays the Tablet option at the bottom.
If you use nota=1 in your search results page the links will work. Like this:
http://www.google.com/search?nota=1&q=amazon
I know this is not perfect. We'd like the default Google search results page's links to work. Google is doing something funky on the Tablet version which Asus Transformer doesn't seem to like!
I will post an update when I figure out what is causing this. Oh! the fun with Android :)
I wanted to add this as a comment to Stan Texan's answer, but I don't have enough rep points...
I'm testing on an older tablet (LG Optimus Tab/DoCoMo L-06c/T-Mobile G-Slate/Rogers LG V909) running Honeycomb (3.1) and my WebView is running into the same problem on Google's website.
Google's own browser works just fine when navigating to www.google.com, but when I use that url in a WebView in my app, the links are all "about:blank". 0_o
Therefore, if the user wants to go to Google's search page, I rewrite the url as follows:
//get the url from the user..
inUrl = urlAddressEditText.getText().toString();
// make sure it's properly formatted...
...
// then add the "/?nota=1&" if it's a Google domain.
String outUrl = inUrl.replaceFirst("(www\\.google\\..*/?)(\\??)", "$1/?nota=1&");
webView.loadView(outUrl);
So far this works, but I haven't tested it out for every scenario.
I had a look at your Vuwize app. Instead of embedding www.google.com directly into a WebView, you seem to have your own search form, run a Google search, and then render the result page yourself. This could explain your problem because result links in search results from Google is not straight href links to original pages. To understand more about your problem, it's necessary to see what exactly you're doing and how you run Google search from your server side.
If you just embed www.google.com in a WebView directly like this:
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
Users can enter search directly into Google and get result pages, where links are all clickable in the same WebView.
Here's another solution to handle blank pages caused in Jelly Bean. I found 2 URLs that cause blank pages. Override loadUrl(String) and not load them at all.
#Override
public void loadUrl(String url)
{
if (url != null && !(url.startsWith("file:///android_asset") || "about:blank".equals(url)))
{
super.loadUrl(url);
}
}

Categories

Resources