It's not possible with Chrome on a non-rooted device unless an app has access to Chrome's data directory, which could be the case if that app is owned by Google, or it's a Chrome plugin. Both type of apps doesn't exist as of now. So the short answer i.e. without root access, would be NO, you can't automatically clear browsing data on exit in Chrome for Android.
That said, somebody owning a rooted device may come looking for an answer in future. Here we go with a solution!
Note that this solution is reached by Trial and error. I experimented something and it seemed to work perfectly on my devices running Android 4.2.1, 4.4.2 and 5.0.2, and using Chrome v43.0.2357.93, which means I don't claim any knowledge of what the files (mentioned below) actually do or are used for.
About Chrome's data directory
- Location of Chrome's data directory is
- Most of the browsing data (e.g. History, Top sites, Web Data, Cookies, Log in Data) is under
/data/data/com.android.chrome/app_chrome/Default, which is the profile path.
- Opened tabs are under
0 is the UID of primary user.
All we're going to do is delete the files responsible for resuming the previous browsing data when Chrome is loaded again. We'll simply use a script to delete those files and the deletion will be automated by tasker.
rm -f $data_ac_dir/History* $data_ac_dir/Web\ Data* $data_ac_dir/Cookies* $data_ac_dir/Visited\ Links $data_ac_dir/Favicons* $data_ac_dir/Top\ Sites* $data_ac_dir/Login\ Data* $data_dir/app_tabs/0/* $data_dir/app_chrome/Local\ State;
The script is very simple.
- First line is a shebang.
- Lines starting with
data are creating variable and feeding directory location as the value.
rm -f is to remove forcefully the files viz. History, Web Data, Cookies, Web Links, Favicons, Top Sites, Login Data, app tabs, Local State.
* is a wildcard.
Note that this solution would not affect the Bookmarks or Preferences.
However, if you want even Bookmarks and Preferences to be cleared, simply add the following command in a new line at the bottom of the script:
rm -f $data_ac_dir/Preferences $data_ac_dir/Bookmarks*;
Save the file as
.sh is important), push it into the root directory (
/sdcard) of internal SD card and make it executable using adbas:
adb shell su -c 'chmod 667 /sdcard/Del_chrome_data.sh'
If you use a terminal app, do:
chmod 667 /sdcard/Del_chrome_data.sh
chmod to know about its usage.
Also, I do not change my script permissions in the manner noted above. I simply make them executable in my Linux machine and then push them into my Android device.
Instructions for Tasker
Install and launch Tasker. Its accessibility service needs to be turned on for application based profile.
Go to Settings → Accessibility → Tasker →On→OK.
- Under Tasks create a task named
Create an action in it through
+ → Code → Run Shell, and fill these details:
- Check use Root
- Store Errors in:
- Under Profiles create an application based profile through
+ → Application → choose All, and Invert at the bottom → select Chrome.
- Link the task
Del_chrome_data in it.
(Here is the exported profile, in case you run into trouble.)
Now, you may simply launch Chrome, do your browsing, open other apps, come back to Chrome, and nothing would seem to be affected.
Remove the Chrome from recent tasks list, launch Chrome, and voila! you would notice that the previous browsing data has been purged automatically.
You can also configure Tasker to run the task based on time, if you desire time based removal of browsing data.
Note: It took around 2-5 seconds on my devices to purge the files. Perhaps, those devices are slow.
We're good to go!