Nate Fischer | b8762b3 | 2019-02-12 00:14:41 | [diff] [blame] | 1 | # Net debugging in WebView |
| 2 | |
| 3 | ## Net log |
| 4 | |
| 5 | WebView supports the `kLogNetLog` flag to log debugging network info to a JSON |
| 6 | file on disk. |
| 7 | |
| 8 | *** aside |
| 9 | For more info on commandline flags, see |
| 10 | [commandline-flags.md](./commandline-flags.md). |
| 11 | *** |
| 12 | |
| 13 | *** note |
| 14 | **Note:** this requires either a `userdebug` or `eng` Android build (you can |
| 15 | check with `adb shell getprop ro.build.type`). Flags cannot be enabled on |
| 16 | production builds of Android. |
| 17 | *** |
| 18 | |
Nate Fischer | a5a8962 | 2019-04-17 01:05:08 | [diff] [blame^] | 19 | 1. Figure out the app's data directory |
| 20 | ```sh |
| 21 | # appPackageName is the package name of whatever app you're interested (ex. |
| 22 | # WebView shell is "org.chromium.webview_shell"). |
| 23 | appDataDir="$(adb shell dumpsys package ${appPackageName} | grep 'dataDir=' | sed 's/^ *dataDir=//')" && \ |
| 24 | ``` |
| 25 | 1. Pick a name for the JSON file. This must be under the WebView folder in the |
| 26 | app's data directory (ex. `jsonFile="${appDataDir}/app_webview/foo.json"`). |
| 27 | **Note:** it's important this is inside the data directory, otherwise |
| 28 | multiple WebView apps might try (and succeed) to write to the file |
| 29 | simultaneously. |
Nate Fischer | b8762b3 | 2019-02-12 00:14:41 | [diff] [blame] | 30 | 1. Kill the app, if running |
| 31 | 1. Set the netlog flag: |
| 32 | ```sh |
| 33 | build/android/adb_system_webview_command_line --log-net-log=${jsonFile} |
| 34 | ``` |
| 35 | 1. Restart the app. Reproduce whatever is of interest, and then kill the app |
| 36 | when finished |
| 37 | 1. Get the netlog off the device: |
| 38 | ```sh |
Nate Fischer | b8762b3 | 2019-02-12 00:14:41 | [diff] [blame] | 39 | adb pull "${appDataDir}/app_webview/${jsonFile}" |
| 40 | ``` |
| 41 | 1. Import the JSON file into [the NetLog |
| 42 | viewer](https://chromium.googlesource.com/catapult/+/master/netlog_viewer/) |
| 43 | |
| 44 | For more details, see the implementation in |
| 45 | [AwUrlRequestContextGetter](/android_webview/browser/net/aw_url_request_context_getter.cc). |
| 46 | For support in the network service code path, see http://crbug.com/902039. |