Debugging WebView in Android

671 views
Skip to first unread message

Thuan Duc Tran

unread,
May 23, 2013, 3:38:17 AM5/23/13
to wei...@googlegroups.com
Hi,

I was trying to find a tool that can debug a web page inside webview in my Android Application. I first tried with an HTML page and everything was great. However when I try to debug my real webview that does not load content from an url (webview.loadurl) but to load from data Weinre cannot detect the target anymore. How can I fix this problem? Here is my code:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)this.findViewById(R.id.button1);
this.webview = (WebView)this.findViewById(R.id.webView1);
//webview.setWebChromeClient(new WebChromeClient());
final String htmlPre = "<!DOCTYPE html><html lang=\"en\"><head><meta charset=\"utf-8\"> <script src='http://debug.phonegap.com/target/target-script-min.js#anonymous'></script> <script>alert('hello')</script></head><body style='margin:0; pading:0; background-color: black;'>";  
   final String htmlCode = 
           "  autoplay='true' " +
           "  quality='high' bgcolor='#000000' " +
           "  name='VideoPlayer' align='middle'" + // width='640' height='480' 
           "  allowScriptAccess='*' allowFullScreen='true'" +
           "  type='application/x-shockwave-flash' " +
           "  pluginspage='http://www.macromedia.com/go/getflashplayer' />" +
           "";
   final String htmlPost = "</body></html>";
   
this.webview.getSettings().setJavaScriptEnabled(true);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
webview.loadDataWithBaseURL("null", htmlPre+htmlCode+htmlPost, "text/html", "UTF-8", null);
}
});

Thanks in advanced!

Patrick Mueller

unread,
May 23, 2013, 6:00:27 AM5/23/13
to wei...@googlegroups.com
On Thursday, May 23, 2013 3:38:17 AM UTC-4, Thuan Duc Tran wrote:
HTML page and everything was great. However when I try to debug my real webview that does not load content from an url (webview.loadurl) but to load from data Weinre cannot detect the target anymore.
 
charset=\"utf-8\"> <script src='http://debug.phonegap.com/target/target-script-min.js#anonymous'></script> 
 
Try a server other than debug.phonegap.com - eg, run your own server.

Also, can you load scripts from anywhere else?  Maybe there's something wrong with your WebView configuration.

Thuan Duc Tran

unread,
May 23, 2013, 11:23:35 PM5/23/13
to wei...@googlegroups.com
Thanks I somehow manage to make it run now. First I use my own server because phonegap server breaks down too often but it still does not work. Then I put the link to my host  as baseURL (webview.loadDataWithBaseURL(baseURL,data,mimeType,encoding,historyURL), at first I make it null - webview.loadDataWithBaseURL(null,....)) though I has nothing on that host and it works now.

Thuan Duc Tran

unread,
May 24, 2013, 1:01:12 AM5/24/13
to wei...@googlegroups.com
Excuse me can I ask you one more silly question? My webview content is kind of long that I have to scroll to see it all. However, the Weinre highlighters seems to be in "fixed position", I know in the script file it is "absolute" but when I scroll the highlighter of the upper text is still there on the screen while the highlighter of the below ones is nowhere to be seen because it is outside of the screen. How can I fix this problem? Thanks a lot.

Thuan Duc Tran

unread,
May 24, 2013, 1:20:49 AM5/24/13
to wei...@googlegroups.com
On Friday, May 24, 2013 12:01:12 PM UTC+7, Thuan Duc Tran wrote:
Excuse me can I ask you one more silly question? My webview content is kind of long that I have to scroll to see it all. However, the Weinre highlighters seems to be in "fixed position", I know in the script file it is "absolute" but when I scroll the highlighter of the upper text is still there on the screen while the highlighter of the below ones is nowhere to be seen because it is outside of the screen. How can I fix this problem? Thanks a lot.

Oh sorry my mistake, there might be some conflict with my other js files, I just tested it with another webview and other datacontent, Weinre highlighters runs fine without anyproblem.
Reply all
Reply to author
Forward
0 new messages