Skip to content

Latest commit

 

History

History
143 lines (111 loc) · 5.81 KB

commandline-flags.md

File metadata and controls

143 lines (111 loc) · 5.81 KB

Commandline flags

Can I apply commandline flags on my device?

*** note Note: WebView only permits toggling commandline flags on devices/emulators running a debuggable Android OS image. Most users cannot apply commandline flags, because they're using devices with production Android images.


You can check which Android image you have on your device with the following:

# If you don't have `adb` in your path, you can source this file to use
# the copy from chromium's Android SDK.
$ source build/android/envsetup.sh

# If this outputs "userdebug" or "eng" then you can apply flags following this
# guide. If it outputs "user" then you cannot apply flags on this device.
$ adb shell getprop ro.build.type
userdebug

If the above outputs "user," then you cannot apply flags on the device/emulator. If you intend to use this device for chromium development, then you may consider re-flashing the device or creating a debuggable Android emulator.

Applying flags

WebView reads flags from a specific file on the device as part of the startup sequence. Therefore, it's important to always kill the WebView-based app you're examining after modifying commandline flags, to ensure the flags are picked up during the next app restart.

WebView always looks for the same file on the device (/data/local/tmp/webview-command-line), regardless of which package is the the WebView provider.

Python script

The simplest way to set WebView flags is with the dedicated python script. This works regardless of which package is the WebView provider:

# Overwrite flags (supports multiple)
build/android/adb_system_webview_command_line --show-composited-layer-borders --force-enable-metrics-reporting
# Clear flags
build/android/adb_system_webview_command_line ""
# Print flags
build/android/adb_system_webview_command_line

Generated Wrapper Script

If you have a locally compiled APK, you may instead set flags using the Generated Wrapper Script like so:

autoninja -C out/Default system_webview_apk
# Overwrite flags (supports multiple)
out/Default/bin/system_webview_apk argv --args='--show-composited-layer-borders --force-enable-metrics-reporting'
# Clear flags
out/Default/bin/system_webview_apk argv --args=''
# Print flags
out/Default/bin/system_webview_apk argv

*** note Note: be careful if using a monochrome_* target, as the Generated Wrapper Script writes to Chrome browser's flags file, and WebView will not pick up these flags. If using Monochrome, you can set flags with the system_webview_* Generated Wrapper Scripts, or use one of the other methods in this doc.


Manual

Or, you can use the adb in your $PATH like so:

FLAG_FILE=/data/local/tmp/webview-command-line
# Overwrite flags (supports multiple). The first token is ignored. We use '_'
# as a convenient placeholder, but any token is acceptable.
adb shell "echo '_ --show-composited-layer-borders --force-enable-metrics-reporting' > ${FLAG_FILE}"
# Clear flags
adb shell "rm ${FLAG_FILE}"
# Print flags
adb shell "cat ${FLAG_FILE}"

Verifying flags are applied

You can confirm you've applied commandline flags correctly by dumping the full state of the commandline flags with the WebView Log Verbosifier app and starting up a WebView app.

Applying Features with flags

base::Features (or, "Features") are Chromium's mechanism for toggling off-by-default code paths. While debugging flags are also off-by-default, Features typically guard soon-to-launch product enhancements until they're tested enough for field trials or public launch, at which point the Feature is removed and the legacy code path is no longer supported and removed from the codebase. On the other hand, debugging flags don't "launch," as they're typically only helpful for debugging issues.

WebView supports the same syntax for toggling Features as the rest of chromium: --enable-features=feature1,feature2 and --disable-features=feature3,feature4. You can apply --enable-features and --disable-features like any other flags, per the steps above. Please consult base/feature_list.h for details.

Finding Features and flags

WebView supports toggling any flags/Features supported in any layer we depend on (ex. content). For more details on Chromium's layer architecture, see this diagram (replace "chrome" with "android_webview"). Although we support toggling these flags, not all flags will have an effect when toggled, nor do we guarantee WebView functions correctly when the flag is toggled.

Some interesting flags and Features:

  • --show-composited-layer-borders: highlight rendering layers, which is useful for identifying which content in the app is rendered by a WebView.
  • --force-enable-metrics-reporting: enable UMA metrics reporting (does not override app opt-out)
  • --finch-seed-expiration-age=0 --finch-seed-min-update-period=0 --finch-seed-min-download-period=0 --finch-seed-ignore-pending-download: always request a new finch seed when an app starts

WebView also defines its own flags and Features:

Implementation

See CommandLineUtil.java.