Android WebView Uncaught Reference Error - android

I have a simple WebView in my app that loads the Google Finance page with a specific symbol so users can see historical prices and other information, but for some reason in the Log I keep seeing this message when loading the webview:
I/chromium﹕ [INFO:CONSOLE(242)] "Uncaught ReferenceError: og is not defined", source: https://www.google.com/m/finance#search/GOOG (242)
Although this doesn't prevent the webview from loading the url, I don't understand why I'm getting that message. I've tried with numerous ticker symbols (for example replace GOOG with AXP, BUD, CMCSK) and the message is always the same so I'm thinking it's referring to the "google" part of the url but I don't know why it would come up as not defined.

It is simply a javascript error that happened on the specific page you loaded.
Try loading the page:
https://www.google.com/m/finance#search/GOOG
in browser with opened developer console and you will see something like this:
==> as long as you do not control the webpage you are loading there is not much what you can do about that. Except maybe checking if the url etc. that you use is the right one.

Related

Android WebView ERR_TOO_MANY_REDIRECTS

I am trying to allow user to login into our application through a WebView, but when trying to login, I get an error saying ERR_TOO_MANY_REDIRECTS. The login protocol consists of 5 redirects, but we have no control over it.
It works in a web browser, but Anroid WebView starts thinking we are in a redirect loop and cancels the whole thing. Up until API 8 there was a function onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg), which allowed you to continue, but is now not used anymore.
What can I do to get around this problem?
In my code I have the following line:
webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
Just deleting this line solve the issue.

oAuth support in a WebView

So I've created a simple WebView application that wraps an already existing mobile friendly site and displays it on the device. I've enabled javascript, supported screen orientation changes, etc...
I've run into an issue with the oAuth support though. Accessing the site from the chrome browser on the device, everything runs fine.
If I try to access the site from the app/WebView, it will push me over to the oAuth screen, let me input credentials and everything, but the moment it tries to push me back to the website and log me in, I get this:
Failed to recognize URL query:
https://exittix.com/frontend/login/redirect.html#access_token=******************************&expires_in=********&state=****client_id=******************network*****facebook*****display***popup****callback****_hellojs_agj27sx5****state****oauth_proxy***https***auth-server.herokuapp.com%2Fproxy***scope***basic_profile***email***basic***oauth***version***auth***https***facebook.com%2Foauth***
The * is used to protect data.
So, any ideas why oAuth isn't working inside a JS enabled webview but works fine in the mobile chrome browser for android?
Thanks in advance for your help!
EDIT:
Ok, so I've tracked the error I'm getting back to redirect.html.
This page calls some javascript. If the javascript fails to redirect, then it displays that error I have above instead.
The javascript being called to handle the oAuth is Andrew Dodson's hello.js script.
You can see it HERE.
I've concluded that the second half of the error's url is indeed the unhandled JSON.
Here's what the returned data looks like after I've decoded it from the URL encoded characters:
{"client_id":"************.apps.googleusercontent.com","network":"google","display":"popup","callback":"_hellojs_********","state":"","oauth_proxy":"https://auth-server.herokuapp.com/proxy","scope":["https://www.googleapis.com/auth/userinfo.profile","https://www.googleapis.com/auth/userinfo.email","basic"],"oauth":{"version":2,"auth":"https://accounts.google.com/o/oauth2/auth"}}&access_token=***.*.*****_*********************************************************&token_type=Bearer&expires_in=3600
Any ideas why this isn't getting handled properly in the WebView?

How to get page state in webview

In my Android app, I have need to show a webpage in a WebView, using the URL obtained from my server. However, it sometimes shows OK but sometimes shows an error page (a .NET-style yellow page stating "Server Error in /Web Application").
I want to do something in my app to identify that error and redirect to another page, but how do I recognize the error?
See How to retrieve HTML content from WebView (as a string)
Check the HttpResponse code and see if there's error returned.
Take note of the comment to avoid consuming double of the bandwidth required, make a HttpRequest and load it into the WebView if there's not error.

what the reason behind <GATE-M>DEV_ACTION_ERROR</GATE-M> android logs

My application is using web view and every thing is working fine(no force close,no visible error) but in log cat i am getting unlimited and continuous logs like.
09-06 09:05:27.464: I/GATE(3471): <GATE-M>DEV_ACTION_ERROR</GATE-M>
my web view renders a local html file which resides in asset folder.From Android native code i am sending some string to webview to call a java script function.
because of unlimited logs i am not able to see my custom log message.
Can any please tell me the reason so can eliminate if i did any thing wrong.
I am loading the WebView using the Url from server. In my case it is not html file. Just check the input stream from the server. if any content is there then set webview otherwise dont.

How to avoid "Redirect Notice" from Google in Android Webview

I have a an app that uses a webview and webviewclient. It's supposed to be a whitelist based browser for kids, so I'm checking urls and only allowing certain ones to be loaded. Generally its working, but when I search on google and click a search result, I get a page that says "Redirect Notice - the previous page is sending you to..."
I am not posting code because I don't know which section is relevant. Can anyone point me where to look?
Added: The problem has to be either
1) in the way Google is serving the search results (why would it it be different than the default browser?), or
2) how the webview is handling them.
I'm starting to think it has to do with the way Google is serving search results, as the links give the "redirect notice" anywhere. Here's an example link:
http://www.google.com/url?sa=t&source=web&cd=2&ved=0cccqfjab&url=http%3a%2f%2faerik.com%2f&ei=dlwwt-bgc-wciqk8tkzadw&usg=afqjcnhkstsuy-erndsrb4nkkpvda_xutq
If Google is serving my app search results differently, could it be because of cookies or user-agents? Does a webview automatically handle cookies and send the default user-agent?
Ah... I figured it out. I doubt anyone else will have a similar issue, because the root cause was that I was lowercasing the URL as I checked it against the whitelist, then loading the lowercased URL... kind of dumb, but then again, many bugs are.
Sign in with your google account, then visit the url. It will work. Once you successfully visited the url, you can revisit that site .

Categories

Resources