Issue
The following trick for getting page's HTML content after javascript has been rendered works pretty well, when placed in the onNewPicture()
of a WebView
's PictureListener
:
browser.loadUrl("javascript:window.HTMLOUT.showHTML('<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
However, for some reason it works only the first time the page is loaded. That is, the application's first such WebView.loadUrl()
call gets a completely rendered version of the page.
Thereafter, if I reload/refresh the page (same exact URL), the output of HTMLOUT.showHTML()
appears to be the original HTML+javascript before the page was rendered.
The strange thing is that visually, on the WebView
itself, all content is there! (albeit after a significant delay... I can see the WebView's hourglass spinning, perhaps it takes too long for Javascript to be re-processed?)
This seems to suggest either an initialization problem (in my code), a bug in WebView, or some caching principle that is well known to experienced web programmers but with which I am not familiar with yet.
But then it gets even more interesting: Subsequent calls to WebView.loadUrl()
result in the aforementioned failure multiple (3-10) times until... the page is miraculously fully rendered again! (and then multiple failures again, and so on)
Which may suggest timing problem?
Any suggestion on how to debug or troubleshoot this?
Solution
you have to inject the javascript after the page loads! Took me forever to figure it out
Answered By - CQM
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.