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 | 7d9828c | 2019-04-17 19:23:27 | [diff] [blame^] | 19 | ```shell |
| 20 | # Optional: set any flags of your choosing before running the script |
| 21 | $ build/android/adb_system_webview_command_line --enable-features=NetworkService,NetworkServiceInProcess |
| 22 | Wrote command line file. Current flags (in webview-command-line): |
| 23 | 005d1ac915b0c7d6 (bullhead-userdebug 6.0 MDB08M 2353240 dev-keys): --enable-features=NetworkService,NetworkServiceInProcess |
| 24 | |
| 25 | # Replace "<app package name>" with your app's package name (ex. the |
| 26 | # WebView Shell is "org.chromium.webview_shell") |
| 27 | $ android_webview/tools/record_netlog.py --package="<app package name>" |
| 28 | Running with flags ['--enable-features=NetworkService,NetworkServiceInProcess', '--log-net-log=netlog.json'] |
| 29 | Netlog will start recording as soon as app starts up. Press ctrl-C to stop recording. |
| 30 | ^C |
| 31 | Pulling netlog to "netlog.json" |
| 32 | ``` |
| 33 | |
| 34 | Then import the JSON file into [the NetLog |
| 35 | viewer](https://chromium.googlesource.com/catapult/+/master/netlog_viewer/). |
| 36 | |
| 37 | For more details, see the implementation in |
| 38 | [AwUrlRequestContextGetter](/android_webview/browser/net/aw_url_request_context_getter.cc). |
| 39 | For support in the network service code path, see http://crbug.com/902039. |
| 40 | |
| 41 | ### Manual steps |
| 42 | |
Nate Fischer | a5a8962 | 2019-04-17 01:05:08 | [diff] [blame] | 43 | 1. Figure out the app's data directory |
| 44 | ```sh |
| 45 | # appPackageName is the package name of whatever app you're interested (ex. |
| 46 | # WebView shell is "org.chromium.webview_shell"). |
| 47 | appDataDir="$(adb shell dumpsys package ${appPackageName} | grep 'dataDir=' | sed 's/^ *dataDir=//')" && \ |
| 48 | ``` |
| 49 | 1. Pick a name for the JSON file. This must be under the WebView folder in the |
| 50 | app's data directory (ex. `jsonFile="${appDataDir}/app_webview/foo.json"`). |
| 51 | **Note:** it's important this is inside the data directory, otherwise |
| 52 | multiple WebView apps might try (and succeed) to write to the file |
| 53 | simultaneously. |
Nate Fischer | b8762b3 | 2019-02-12 00:14:41 | [diff] [blame] | 54 | 1. Kill the app, if running |
| 55 | 1. Set the netlog flag: |
| 56 | ```sh |
| 57 | build/android/adb_system_webview_command_line --log-net-log=${jsonFile} |
| 58 | ``` |
| 59 | 1. Restart the app. Reproduce whatever is of interest, and then kill the app |
| 60 | when finished |
| 61 | 1. Get the netlog off the device: |
| 62 | ```sh |
Nate Fischer | b8762b3 | 2019-02-12 00:14:41 | [diff] [blame] | 63 | adb pull "${appDataDir}/app_webview/${jsonFile}" |
| 64 | ``` |
Nate Fischer | 7d9828c | 2019-04-17 19:23:27 | [diff] [blame^] | 65 | 1. Follow the step above for using the Netlog viewer |