blob: b0f906f8d545bc632b247df67feb3886d9e5cbbb [file] [log] [blame] [view]
Nate Fischerb8762b32019-02-12 00:14:411# Net debugging in WebView
2
3## Net log
4
5WebView supports the `kLogNetLog` flag to log debugging network info to a JSON
6file on disk.
7
8*** aside
9For 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
15check with `adb shell getprop ro.build.type`). Flags cannot be enabled on
16production builds of Android.
17***
18
Nate Fischer7d9828c2019-04-17 19:23:2719```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
22Wrote 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>"
28Running with flags ['--enable-features=NetworkService,NetworkServiceInProcess', '--log-net-log=netlog.json']
29Netlog will start recording as soon as app starts up. Press ctrl-C to stop recording.
30^C
31Pulling netlog to "netlog.json"
32```
33
34Then import the JSON file into [the NetLog
35viewer](https://chromium.googlesource.com/catapult/+/master/netlog_viewer/).
36
37For more details, see the implementation in
38[AwUrlRequestContextGetter](/android_webview/browser/net/aw_url_request_context_getter.cc).
39For support in the network service code path, see http://crbug.com/902039.
40
41### Manual steps
42
Nate Fischera5a89622019-04-17 01:05:08431. 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 ```
491. 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 Fischerb8762b32019-02-12 00:14:41541. Kill the app, if running
551. Set the netlog flag:
56 ```sh
57 build/android/adb_system_webview_command_line --log-net-log=${jsonFile}
58 ```
591. Restart the app. Reproduce whatever is of interest, and then kill the app
60 when finished
611. Get the netlog off the device:
62 ```sh
Nate Fischerb8762b32019-02-12 00:14:4163 adb pull "${appDataDir}/app_webview/${jsonFile}"
64 ```
Nate Fischer7d9828c2019-04-17 19:23:2765 1. Follow the step above for using the Netlog viewer