Android Webview: Get current viewport/rendered content - android

I am writing an Android Webview App to record what HTML content I am currently looking at. Is there any way to capture the rendered HTML content (or DOM element)?
I checked all the Android Webview APIs, and none provided such functionalities.
I also tried to rewrite the scroll listener, but it won't give me the content I am looking at(rendering on the current screen) either.
The previous question shows how to get the entire HTML content from the Webview: how to get HTML content from a Webview? (13 answers), but it couldn't solve my issue, since even if I got the page content I won't know which part I am looking at.
Please let me know if you have any suggestions or reasonable solutions for this.

Related

How to edit content and layout of webview?

Is there a way for me to edit the contents of the Webview or to crop out some parts of the content, i'm focusing on UI and would like to clean up the content for a project i am working on.
Also lets say I want to display content of the webView individually as well (multiple webviews within an activity) for aesthetic purposes, how would I go about doing that?
One technique I've used in the past is to request the page with an HttpURLConnection rather than the WebView. Then I parse and edit the HTML data and display it in the WebView using the loadData method. You could even use something like JSoup to parse the HTML. However, if you are depending on having the JavaScript run on the page, you may have a problem because using loadData will disrupt the same-origin policy.

Check for input in webview

I have an app that has a web-view which has a basic web-form that has a few fields and a submit button. I would like to figure out in my app if the form has any input in any of the fields. I cannot change the form from the server side, and I can't be certain much about the fields (ids / names in the html).
In iOS we accomplish this with an interesting process of pulling all the html out when loading the form, and comparing it to the html at any given point, if they don't match, the user must have entered something into a field. I believe we were able to get the html by injecting and running some javascript into the web-view. I'm not sure exactly how to approach the problem on android, or if android has any better tools to get whether a form has been edited.
Anybody have any ideas / pseudo-code how I can tell if a form has had input in any of the fields in a webview in android?
Unfortunately, there are no special form-related tools in Android WebView either. You can use the same approach as you have described for iOS.
A couple of links to get you started:
Read HTML content of webview widgets
Android Web-View : Inject local Javascript file to Remote Webpage

Inconsistent DOM structure of the loaded HTML page in webview

I am making Highlighter for Android in WebView.
For the highlighting purpose, in one example i am using JQuery and Rangy, in another pure Javascript and XPath. I am trying the same Highlight in Desktop Browsers also.
Please refer to the previous questions which i posted for the problems which i am facing during Highlighting...
-->> Problem when using XPath
-->> Problem when using Rangy (Not answered yet!)
So... from the responses to these question, i came to the conclusion that
the DOM structure of the loaded HTML in WebView is inconsistent and different than that of the same HTML page loaded in Desktop Browser mostly with reference to "TextNodes"..
To support this conclusion, i have created a jsFiddle (link in the question).
But, i also think that WebView may not be changing the DOM structure but it surely returns incorrect TextNodes inside a div...
Now the question is, is there any way to stop this change in DOM structure of the HTML in WebView?
Any insight guys?

Get complete HTML contents from Android WebView

I have a WebView with some web page in it. Now I want to retrieve complete HTML contents of what is inside the WebView.
I use loadUrl("javascript:...") and WebView's javascript interface feature to retrieve this HTML using something like this:
document.getElementsByTagName('html')[0].innerHTML / outerHTML
document.documentElement.outerHTML
...
In each case I receive partial HTML contents - exactly first 10000 characters! So my question is - how do I get complete HTML content? Is it device-specific and, maybe there are workarounds?
Btw, web pages are created dynamically with javascript - I can't simply download the file from server.
Also, I tried printing HTML contents in javascript with console.log and found exactly the same behavior.
Thanks in advance!
My mistake - it was not related to javascript, neither had to do with specific device I tested on.
So, in short, any of those js properties work correctly.

Android WebView Grid Display

I am having some problems with a webview I am using to access a specific URL within my Activity. When I load this exact same URL on a PC browser such as firefox, the edges of the grid are displayed
When I try to load the same URL from within my WebView by using
webView.loadURL("www.url.com");
I get the following grid.
Any ideas on how I can fix this? It's not a major issue, just annoying.
And this isn't real data, so don't worry about that.
I don't know that much about HTML so maybe this is an HTML issue?
Apologize for using imageshack, I can't post images yet.
Have you tried scrolling to the side? Does it display the images, then?
You might try the following:
Building webpages to support different screen densities
Take a look at the Android documentation there. It should give you a good example of how to get your data to display properly on any device.
Hope this helps!

Categories

Resources