1. 程式人生 > >關於android客戶端中webview除錯的方法

關於android客戶端中webview除錯的方法

    google官方在android API19中針對WebView引入了一個新的方法setWebContentsDebuggingEnabled(boolean enabled),官方API中關於此方法的介紹是:

 Enables debugging of web contents (HTML / CSS / JavaScript) loaded into any WebViews of this application. This flag can be enabled in order to facilitate debugging of web layouts and JavaScript code running inside WebViews. Please refer to WebView documentation for the debugging guide. The default is false.


 意思就是說對於載入進此WebView中的頁面是否可除錯,預設值是false,不允許除錯。

    那麼怎樣才能像除錯web頁面一樣除錯WebView中的頁面呢?其實,現在的Chrome瀏覽器已經支援了此功能,步驟如下:

1、設定WebView可除錯:

mWebView.setWebContentsDebuggingEnabled(true);
2、翻牆檢視此文件:遠端除錯android裝置中的Web頁面 (需要翻牆哦!)