Nate Fischer | a902914 | 2019-03-01 21:14:36 | [diff] [blame] | 1 | # System WebView Shell |
| 2 | |
Nate Fischer | 8bd8a11 | 2021-04-23 20:45:10 | [diff] [blame] | 3 | [TOC] |
| 4 | |
Nate Fischer | 599a83b | 2020-07-30 23:52:39 | [diff] [blame] | 5 |  |
| 6 | |
Nate Fischer | b84a88e | 2022-03-10 17:11:00 | [diff] [blame] | 7 | WebView team maintains a "shell"—a thin interface over the WebView |
| 8 | APIs—to exercise WebView functionality. The System WebView Shell (AKA |
Nate Fischer | b9f21ddc | 2020-07-09 12:15:29 | [diff] [blame] | 9 | "shell browser," "WebView shell") is a standalone app implemented [in |
Nate Fischer | a902914 | 2019-03-01 21:14:36 | [diff] [blame] | 10 | chromium](/android_webview/tools/system_webview_shell/). While often used for |
| 11 | manual testing, we also use the shell for automated tests (see our [layout and |
| 12 | page cycler tests](./test-instructions.md#layout-tests-and-page-cycler-tests)). |
| 13 | |
| 14 | *** note |
| 15 | This relies on the WebView installed on the system. So if you're trying to |
| 16 | verify local changes to WebView, or run against a specific WebView build, you |
| 17 | must **install WebView first.** |
| 18 | *** |
| 19 | |
| 20 | *** promo |
| 21 | **Tip:** the shell displays the WebView version (the corresponding [chromium version |
| 22 | number](https://www.chromium.org/developers/version-numbers)) in the title bar |
| 23 | at the top. This can be helpful for checking which WebView version is installed |
| 24 | & selected on the device. |
| 25 | *** |
| 26 | |
Torne (Richard Coles) | 1eeb534 | 2021-03-29 22:23:55 | [diff] [blame] | 27 | *** note |
| 28 | This is *not* a production quality browser and does not implement suitable |
| 29 | security UI to be used for anything other than testing WebView. This should not |
| 30 | be shipped anywhere or used as the basis for implementing a browser. |
| 31 | *** |
| 32 | |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 33 | ## Setting up the build |
| 34 | |
Nate Fischer | aa36593 | 2020-04-28 06:35:29 | [diff] [blame] | 35 | WebView shell only requires `target_os = "android"`. The simplest option is to |
| 36 | just reuse the same out/ folder and GN args you would normally use for WebView |
| 37 | or Chrome for Android. |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 38 | |
Nate Fischer | aa36593 | 2020-04-28 06:35:29 | [diff] [blame] | 39 | *** note |
| 40 | **For the emulator:** the emulator comes with WebView shell preinstalled with a |
| 41 | different signing key, so installation will fail with |
| 42 | `INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package ... signatures do not match |
| 43 | previously installed version`. You can workaround this in your GN args with |
| 44 | `system_webview_shell_package_name = "org.chromium.my_webview_shell"`. |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 45 | |
Nate Fischer | aa36593 | 2020-04-28 06:35:29 | [diff] [blame] | 46 | Your local build will install alongside the preinstalled WebView shell. You may |
| 47 | hide the preinstalled shell by running `adb root` followed by `adb shell pm |
| 48 | disable org.chromium.webview_shell` in your terminal (copy-paste the command |
| 49 | as-written, **don't** use the package name from the GN arg above). |
| 50 | *** |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 51 | |
Chris Mumford | 9d1f8c3 | 2019-09-19 23:02:37 | [diff] [blame] | 52 | ## Building the shell |
| 53 | |
| 54 | ```sh |
| 55 | $ autoninja -C out/Default system_webview_shell_apk |
| 56 | ``` |
| 57 | |
| 58 | ## Installing the shell |
Nate Fischer | a902914 | 2019-03-01 21:14:36 | [diff] [blame] | 59 | |
| 60 | ```sh |
Nate Fischer | a902914 | 2019-03-01 21:14:36 | [diff] [blame] | 61 | $ out/Default/bin/system_webview_shell_apk install |
Chris Mumford | 9d1f8c3 | 2019-09-19 23:02:37 | [diff] [blame] | 62 | ``` |
Nate Fischer | a902914 | 2019-03-01 21:14:36 | [diff] [blame] | 63 | |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 64 | ## Running the shell |
Chris Mumford | 9d1f8c3 | 2019-09-19 23:02:37 | [diff] [blame] | 65 | |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 66 | ```sh |
| 67 | # Launch a URL from the commandline, or open the app from the app launcher |
| 68 | $ out/Default/bin/system_webview_shell_apk launch "https://www.google.com/" |
| 69 | |
| 70 | # For more commands: |
| 71 | $ out/Default/bin/system_webview_shell_apk --help |
Chris Mumford | 9d1f8c3 | 2019-09-19 23:02:37 | [diff] [blame] | 72 | ``` |
| 73 | |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 74 | *** note |
| 75 | **Note:** `system_webview_shell_apk` does not support modifying CLI flags. See |
| 76 | https://crbug.com/959425. Instead, you should modify WebView's flags by |
| 77 | following [commandline-flags.md](./commandline-flags.md). |
| 78 | *** |
| 79 | |
Nate Fischer | 8bd8a11 | 2021-04-23 20:45:10 | [diff] [blame] | 80 | ## Prebuilt APKs |
| 81 | |
| 82 | We maintain a **public** archive of prebuilt WebView shell APKs. This saves you |
| 83 | the effort of setting up a chromium checkout just for the sake of compiling this |
| 84 | test app. You can download a prebuilt APK from this cloud storage bucket: |
Nate Fischer | b5c00c2 | 2022-05-21 00:30:41 | [diff] [blame] | 85 | https://storage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Android/ |
Nate Fischer | 8bd8a11 | 2021-04-23 20:45:10 | [diff] [blame] | 86 | |
Nate Fischer | b5c00c2 | 2022-05-21 00:30:41 | [diff] [blame] | 87 | 1. Click on the "name" column header **twice**. This will force the page to sort |
| 88 | the newest builds toward the top. Click the folder with the largest number, |
| 89 | ignoring the `LAST_CHANGE` and `refs_heads_main-*/` folders. |
Nate Fischer | 8bd8a11 | 2021-04-23 20:45:10 | [diff] [blame] | 90 | * Your WebView shell version **does not** need to match your device's |
| 91 | WebView version. We recommend using the latest WebView shell build |
| 92 | regardless of your WebView version to make sure you have the latest |
| 93 | features and bug fixes of the shell app itself. |
| 94 | 1. Click `chrome-android.zip` to download the archived APKs. Unzip this and look |
| 95 | for a file named `SystemWebViewShell.apk`. |
| 96 | 1. Now you can install this like any other APK: |
| 97 | |
| 98 | ```sh |
| 99 | # Install adb if it's not already installed: |
| 100 | $ which adb || sudo apt install adb |
| 101 | |
| 102 | # Replace this path with the path to your downloaded APK |
| 103 | $ adb install -d -r ~/Downloads/chrome-android/SystemWebViewShell.apk |
| 104 | ``` |
| 105 | |
Nate Fischer | b5c00c2 | 2022-05-21 00:30:41 | [diff] [blame] | 106 | *** note |
| 107 | **Note:** on the Android emulator, this may fail to install and print the |
| 108 | `INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package ... signatures do not match |
| 109 | previously installed version` error message. This may require switching to a |
| 110 | physical device or compiling the WebView shell from source (see the |
| 111 | troubleshooting steps below). |
| 112 | *** |
| 113 | |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 114 | ## Troubleshooting |
| 115 | |
| 116 | ### INSTALL\_FAILED\_UPDATE\_INCOMPATIBLE: Package ... signatures do not match previously installed version |
| 117 | |
Nate Fischer | 3949c89 | 2020-09-21 16:40:59 | [diff] [blame] | 118 | This may be happening because the shell is preinstalled on your device (ex. this |
| 119 | is the case on all emulators). **The easiest way** to workaround this is to |
| 120 | [change the shell's package name in a local build](#building-for-the-emulator). |
Nate Fischer | e065042 | 2020-03-13 19:02:12 | [diff] [blame] | 121 | |
Nate Fischer | 3949c89 | 2020-09-21 16:40:59 | [diff] [blame] | 122 | If you don't want to (or can't) change the package name, then you may be able to |
| 123 | modify your device's system image. See the [manual steps for removing system |
| 124 | apps](removing-system-apps.md) and replace **com.google.android.webview** with |
| 125 | **org.chromium.webview_shell**. |