Category filter

Script to clear browser history on Mac

Every webpage the user visits is logged and stored by the corresponding web browser on the device. The browsing history includes download history, search history, cookies, cache, etc., which ultimately accumulates over time. Admins can remove the browser history of users to avoid leakage of this information or free up storage space. This document provides the custom script to remotely delete the browsing history logged by Google Chrome and Firefox apps on macOS devices using the Execute Custom Script action.

Scripting Language – Bash

File extension – .sh

Disclaimer:

The Sample Scripts provided below are adapted from third-party Open-Source sites.

Delete Google Chrome browsing history

Google Chrome app stores the browsing history of a user on a file named History in the location “Library/Application Support/Google/Chrome/Default” on macOS devices. Delete this file using the rm command to erase the browsing history on Google Chrome.

Replace <user name> with the target username on the device.

For example:

LOGGED_USER=stat -f%Su /dev/console
sudo su $LOGGED_USER -c 'rm -R /Users/testacc/Library/Application\ Support/Google/Chrome/Default/History'

Delete Firefox browsing history

The Firefox app stores the browsing history of a user on a file in the location “Library/Application Support/Firefox/Profiles” on macOS devices. The file name will differ depending on the storage device. Use the rm command to delete all files under the Profiles folder. It’s worth noting that deleting all files will also remove bookmarks and caches stored by Firefox.

Replace <user name> with the target username on the device.

For example:

LOGGED_USER=stat -f%Su /dev/console
sudo su $LOGGED_USER -c 'rm -R /Users/testacc/Library/Application\ Support/Firefox/Profiles'

Notes:

  • In Bash, before inserting space while defining user names, we use a backslash ‘\’ to separate the characters. This will prevent the shell interpreter from interpreting the space as a separator and assuming they were two different arguments. Hence, if the user name is New User, we write it as New\ User.
  • It is recommended to manually validate the script execution on a system before executing the action in bulk.
  • Hexnode will not be responsible for any damage/loss to the system on the behavior of the script.

  • Sample Script Repository