win, linux: unify & improve Firefox clean-up #273

This commit unifies some of the logic, documentation and naming for
Firefox clean-up with improvements on both Linux and Windows platforms.

Windows:

- 'Clear browsing history and cache':
  - Not recommend.
  - Align script name and logic with Linux implementation.
  - New documentation and not including the script in recommendation
    provides safety against unintended data loss as discussed in #273.
- 'Clear Firefox user profiles, settings, and data':
  - Rename to 'Clear all Firefox user information and preferences' for
    improved clarity.
  - Add more documentation.

Linux:

- Replace `DeleteFromFirefoxProfiles` with
  `DeleteFilesFromFirefoxProfiles`.
- Migrate implementation to Python:
  - Add more user-friendly outputs.
  - Exclude removing directory itself for additional safety.

Both Linux and Windows:

- Improve documentation for:
  - 'Clear Firefox user profiles, settings, and data'
  - 'Clear Firefox history'
This commit is contained in:
undergroundwires
2023-11-02 13:18:54 +01:00
parent ca81f68ff1
commit 0466b86f10
2 changed files with 199 additions and 93 deletions

View File

@@ -707,15 +707,9 @@ actions:
- -
category: Clear Firefox history category: Clear Firefox history
docs: |- docs: |-
Mozilla Firefox, or simply Firefox, is a free and open-source web browser developed by the Mozilla Foundation and This category encompasses a series of scripts aimed at helping users manage and delete their browsing history and related data in Mozilla Firefox.
its subsidiary the Mozilla Corporation [1].
Firefox stores user-related data in user profiles [2]. The scripts are designed to target different aspects of user data stored by Firefox, providing users options for maintaining privacy and freeing up disk space.
See also [the Firefox homepage](https://web.archive.org/web/20221029214632/https://www.mozilla.org/en-US/firefox/).
[1]: https://web.archive.org/web/20221029145113/https://en.wikipedia.org/wiki/Firefox "Firefox | Wikipedia | en.wikipedia.org"
[2]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org"
children: children:
- -
name: Clear Firefox cache name: Clear Firefox cache
@@ -755,9 +749,13 @@ actions:
# Snap installation # Snap installation
rm -rfv ~/snap/firefox/common/.mozilla/firefox/Crash\ Reports/* rm -rfv ~/snap/firefox/common/.mozilla/firefox/Crash\ Reports/*
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: crashes/ pathGlob: crashes/*
-
function: DeleteFilesFromFirefoxProfiles
parameters:
pathGlob: crashes/events/*
- -
name: Clear Firefox cookies name: Clear Firefox cookies
docs: |- docs: |-
@@ -765,41 +763,37 @@ actions:
[1]: https://web.archive.org/web/20221029140816/https://kb.mozillazine.org/Cookies.sqlite "Cookies.sqlite - MozillaZine Knowledge Base | kb.mozillazine.org" [1]: https://web.archive.org/web/20221029140816/https://kb.mozillazine.org/Cookies.sqlite "Cookies.sqlite - MozillaZine Knowledge Base | kb.mozillazine.org"
call: call:
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: cookies.sqlite pathGlob: cookies.sqlite
- -
name: Clear Firefox browsing history (URLs, downloads, bookmarks, visits, etc.) name: Clear Firefox browsing history (URLs, downloads, bookmarks, visits, etc.)
# This script (name, documentation and code) is same in Linux and Windows collections.
# Changes should be done at both places.
# Marked: refactor-with-partials
docs: |- docs: |-
The file "places.sqlite" stores the annotations, bookmarks, favorite icons, input history, keywords, and browsing history (a record of visited pages) [1]. This script targets the Firefox browsing history, including URLs, downloads, bookmarks, and site visits, by deleting specific database entries.
The tables include [1]:
- `moz_anno_attributes`: Annotation Attributes
- `moz_annos`: Annotations
- `moz_bookmarks`: Bookmarks
- `moz_bookmarks_roots`: Bookmark roots i.e. places, menu, toolbar, tags, unfiled
- `moz_favicons`: Favorite icons - including URL of icon
- `moz_historyvisits`: A history of the number of times a site has been visited
- `moz_inputhistory`: A history of URLs typed by the user
- `moz_items_annos`: Item annotations
- `moz_keywords`: Keywords
- `moz_places`: Places/Sites visited - referenced by `moz_historyvisits`
URL data is stored in the `moz_places` table. However, this table is connected to `moz_annos`, `moz_bookmarks`, and `moz_inputhistory` and `moz_historyvisits`.
As these entries are connected to each other, we'll delete all of them at the same time [2].
**Bookmarks**: Firefox stores various user data in a file named `places.sqlite`. This file includes:
Firefox bookmarks are stored in tables such as `moz_bookmarks`, `moz_bookmarks_folders`, `moz_bookmarks_roots` [3].
There are also not very well documented tables, such as `moz_bookmarks_deleted` [4].
**Downloads:** - Annotations, bookmarks, and favorite icons (`moz_anno_attributes`, `moz_annos`, `moz_favicons`) [1]
Firefox downloads are stored in the 'places.sqlite' database, within the 'moz_annos' table [5]. - Browsing history, a record of pages visited (`moz_places`, `moz_historyvisits`) [1]
The entries in `moz_annos` are linked to `moz_places` that store the actual history entry (`moz_places.id = moz_annos.place_id`) [6]. - Keywords and typed URLs (`moz_keywords`, `moz_inputhistory`) [1]
Associated URL information is stored within the 'moz_places' table [5]. - Item annotations (`moz_items_annos`) [1]
Downloads have been historically stored in `downloads.rdf` for Firefox 2.x and below [7]. - Bookmark roots such as places, menu, toolbar, tags, unfiled (`moz_bookmarks_roots`) [1]
Starting with Firefox 3.x they're stored in `downloads.sqlite` [7].
**Favicons:** The `moz_places` table holds URL data, connecting to various other tables like `moz_annos`, `moz_bookmarks`, `moz_inputhistory`, and `moz_historyvisits` [2].
Firefox favicons are stored in the `favicons.sqlite` database, within the `moz_icons` table [5]. Due to these connections, the script removes entries from all relevant tables simultaneously to maintain database integrity.
Older versions of Firefox stored Favicons in the 'places.sqlite' database, within the `moz_favicons` table [5].
**Bookmarks**: Stored across several tables (`moz_bookmarks`, `moz_bookmarks_folders`, `moz_bookmarks_roots`) [3], with additional undocumented tables like `moz_bookmarks_deleted` [4].
**Downloads**: Stored in the 'places.sqlite' database, within the 'moz_annos' table [5]. The entries in `moz_annos` are linked to `moz_places` that store the actual history entry
(`moz_places.id = moz_annos.place_id`) [6]. Associated URL information is stored within the 'moz_places' table [5]. Downloads have been historically stored in `downloads.rdf` for Firefox 2.x
and below [7], and `downloads.sqlite` later on [7].
**Favicons**: Older Firefox versions stored favicons in `places.sqlite` within the `moz_favicons` table [5], while newer versions use `favicons.sqlite` and the `moz_icons` table [5].
By executing this script, users can ensure their Firefox browsing history, bookmarks, and downloads are thoroughly removed, contributing to a cleaner and more private browsing experience.
[1]: https://web.archive.org/web/20221029141626/https://kb.mozillazine.org/Places.sqlite "Places.sqlite - MozillaZine Knowledge Base | kb.mozillazine.org" [1]: https://web.archive.org/web/20221029141626/https://kb.mozillazine.org/Places.sqlite "Places.sqlite - MozillaZine Knowledge Base | kb.mozillazine.org"
[2]: https://web.archive.org/web/20221030160803/https://wiki.mozilla.org/images/0/08/Places.sqlite.schema.pdf "Places.sqlite.schema.pdf | Mozilla Wiki" [2]: https://web.archive.org/web/20221030160803/https://wiki.mozilla.org/images/0/08/Places.sqlite.schema.pdf "Places.sqlite.schema.pdf | Mozilla Wiki"
@@ -810,21 +804,21 @@ actions:
[7]: https://web.archive.org/web/20221029145712/https://kb.mozillazine.org/Downloads.rdf "Downloads.rdf | MozillaZine Knowledge Base | kb.mozillazine.org" [7]: https://web.archive.org/web/20221029145712/https://kb.mozillazine.org/Downloads.rdf "Downloads.rdf | MozillaZine Knowledge Base | kb.mozillazine.org"
call: call:
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: downloads.rdf pathGlob: downloads.rdf
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: downloads.sqlite pathGlob: downloads.sqlite
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: places.sqlite pathGlob: places.sqlite
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: favicons.sqlite pathGlob: favicons.sqlite
- -
name: Clear Firefox logins name: Clear Firefox logins
docs: |- docs: |-
@@ -837,17 +831,17 @@ actions:
[2]: https://web.archive.org/web/20221029145757/https://bugzilla.mozilla.org/show_bug.cgi?id=1593467 "1593467 - Automatically restore from logins-backup.json when logins.json is missing or corrupt | Bugzilla | mozilla.org | bugzilla.mozilla.org" [2]: https://web.archive.org/web/20221029145757/https://bugzilla.mozilla.org/show_bug.cgi?id=1593467 "1593467 - Automatically restore from logins-backup.json when logins.json is missing or corrupt | Bugzilla | mozilla.org | bugzilla.mozilla.org"
call: call:
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: logins.json pathGlob: logins.json
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: logins-backup.json pathGlob: logins-backup.json
- -
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: signons.sqlite pathGlob: signons.sqlite
- -
name: Clear Firefox autocomplete history name: Clear Firefox autocomplete history
docs: |- docs: |-
@@ -856,9 +850,9 @@ actions:
[1]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org" [1]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org"
call: call:
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: formhistory.sqlite pathGlob: formhistory.sqlite
- -
name: Clear Firefox "Multi-Account Containers" data name: Clear Firefox "Multi-Account Containers" data
docs: |- docs: |-
@@ -866,9 +860,9 @@ actions:
[1]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org" [1]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org"
call: call:
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: containers.json pathGlob: containers.json
- -
name: Clear Firefox open tabs and windows data name: Clear Firefox open tabs and windows data
docs: |- docs: |-
@@ -878,9 +872,9 @@ actions:
[1]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org" [1]: https://web.archive.org/web/20221029145152/https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data "Profiles - Where Firefox stores your bookmarks, passwords and other user data | Firefox Help | support.mozilla.org"
call: call:
function: DeleteFromFirefoxProfiles function: DeleteFilesFromFirefoxProfiles
parameters: parameters:
path: sessionstore.jsonlz4 pathGlob: sessionstore.jsonlz4
- -
category: Clear system and kernel usage data category: Clear system and kernel usage data
docs: |- docs: |-
@@ -3493,16 +3487,66 @@ functions:
>&2 echo "Failed, $service does not exist." >&2 echo "Failed, $service does not exist."
fi fi
- -
name: DeleteFromFirefoxProfiles name: Comment
# 💡 Purpose:
# Adds a comment in the executed code for better readability and debugging.
# This function does not affect the execution flow but helps in understanding the purpose of subsequent code.
parameters:
- name: codeComment
optional: true
- name: revertCodeComment
optional: true
call:
function: RunInlineCode
parameters:
code: '{{ with $codeComment }}# {{ . }}{{ end }}'
revertCode: '{{ with $revertCodeComment }}# {{ . }}{{ end }}'
-
name: DeleteFiles
parameters:
- name: fileGlob
call:
-
function: Comment
parameters:
codeComment: >-
Delete files matching pattern: "{{ $fileGlob }}"
-
function: RunPython3Code
parameters: parameters:
- name: path # file or folder in profile file
code: |- code: |-
# {{ $path }}: Global installation import glob
rm -rfv ~/.mozilla/firefox/*/{{ $path }} import os
# {{ $path }}: Flatpak installation path = '{{ $fileGlob }}'
rm -rfv ~/.var/app/org.mozilla.firefox/.mozilla/firefox/*/{{ $path }} expanded_path = os.path.expandvars(os.path.expanduser(path))
# {{ $path }}: Snap installation print(f'Deleting files matching pattern: {expanded_path}')
rm -rfv ~/snap/firefox/common/.mozilla/firefox/*/{{ $path }} paths = glob.glob(expanded_path)
if not paths:
print('Skipping, no paths found.')
for path in paths:
if not os.path.isfile(path):
print(f'Skipping folder: "{path}".')
continue
os.remove(path)
print(f'Successfully delete file: "{path}".')
print(f'Successfully deleted {len(paths)} file(s).')
-
name: DeleteFilesFromFirefoxProfiles
parameters:
- name: pathGlob # file or folder in profile file
call:
- # Global installation
function: DeleteFiles
parameters:
fileGlob: ~/.mozilla/firefox/*/{{ $pathGlob }}
- # Flatpak installation
function: DeleteFiles
parameters:
fileGlob: ~/.var/app/org.mozilla.firefox/.mozilla/firefox/*/{{ $pathGlob }}
- # Snap installation
function: DeleteFiles
parameters:
fileGlob: ~/snap/firefox/common/.mozilla/firefox/*/{{ $pathGlob }}
- -
name: CleanTableFromFirefoxProfileDatabase name: CleanTableFromFirefoxProfileDatabase
parameters: parameters:

View File

@@ -523,39 +523,88 @@ actions:
directoryGlob: '%LOCALAPPDATA%\Google\Chrome\User Data' directoryGlob: '%LOCALAPPDATA%\Google\Chrome\User Data'
- -
category: Clear Firefox history category: Clear Firefox history
docs: |-
This category encompasses a series of scripts aimed at helping users manage and delete their browsing history and related data in Mozilla Firefox.
The scripts are designed to target different aspects of user data stored by Firefox, providing users options for maintaining privacy and freeing up disk space.
children: children:
- -
name: Clear browsing history and cache name: Clear Firefox browsing history (URLs, downloads, bookmarks, visits, etc.)
recommend: standard # This script (name, documentation and code) is same in Linux and Windows collections.
code: |- # Changes should be done at both places.
set ignoreFiles="content-prefs.sqlite" "permissions.sqlite" "favicons.sqlite" # Marked: refactor-with-partials
for %%d in ("%APPDATA%\Mozilla\Firefox\Profiles\" docs: |-
"%USERPROFILE%\Local Settings\Application Data\Mozilla\Firefox\Profiles\" This script targets the Firefox browsing history, including URLs, downloads, bookmarks, and site visits, by deleting specific database entries.
) do (
IF EXIST %%d ( Firefox stores various user data in a file named `places.sqlite`. This file includes:
FOR /d %%p IN (%%d*) DO (
for /f "delims=" %%f in ('dir /b /s "%%p\*.sqlite" 2^>nul') do ( - Annotations, bookmarks, and favorite icons (`moz_anno_attributes`, `moz_annos`, `moz_favicons`) [1]
set "continue=" - Browsing history, a record of pages visited (`moz_places`, `moz_historyvisits`) [1]
for %%i in (%ignoreFiles%) do ( - Keywords and typed URLs (`moz_keywords`, `moz_inputhistory`) [1]
if %%i == "%%~nxf" ( - Item annotations (`moz_items_annos`) [1]
set continue=1 - Bookmark roots such as places, menu, toolbar, tags, unfiled (`moz_bookmarks_roots`) [1]
)
) The `moz_places` table holds URL data, connecting to various other tables like `moz_annos`, `moz_bookmarks`, `moz_inputhistory`, and `moz_historyvisits` [2].
if not defined continue ( Due to these connections, the script removes entries from all relevant tables simultaneously to maintain database integrity.
del /q /s /f %%f
) **Bookmarks**: Stored across several tables (`moz_bookmarks`, `moz_bookmarks_folders`, `moz_bookmarks_roots`) [3], with additional undocumented tables like `moz_bookmarks_deleted` [4].
)
) **Downloads**: Stored in the 'places.sqlite' database, within the 'moz_annos' table [5]. The entries in `moz_annos` are linked to `moz_places` that store the actual history entry
) (`moz_places.id = moz_annos.place_id`) [6]. Associated URL information is stored within the 'moz_places' table [5]. Downloads have been historically stored in `downloads.rdf` for Firefox 2.x
) and below [7], and `downloads.sqlite` later on [7].
-
name: Clear Firefox user profiles, settings, and data **Favicons**: Older Firefox versions stored favicons in `places.sqlite` within the `moz_favicons` table [5], while newer versions use `favicons.sqlite` and the `moz_icons` table [5].
By executing this script, users can ensure their Firefox browsing history, bookmarks, and downloads are thoroughly removed, contributing to a cleaner and more private browsing experience.
[1]: https://web.archive.org/web/20221029141626/https://kb.mozillazine.org/Places.sqlite "Places.sqlite - MozillaZine Knowledge Base | kb.mozillazine.org"
[2]: https://web.archive.org/web/20221030160803/https://wiki.mozilla.org/images/0/08/Places.sqlite.schema.pdf "Places.sqlite.schema.pdf | Mozilla Wiki"
[3]: https://web.archive.org/web/20221029145432/https://wiki.mozilla.org/Places:BookmarksComments "Places:BookmarksComments | MozillaWiki | wiki.mozilla.org"
[4]: https://web.archive.org/web/20221029145447/https://github.com/mozilla/application-services/issues/514 "Add a `moz_bookmarks_deleted` table for tombstones · Issue #514 · mozilla/application-services | GitHub | github.com"
[5]: https://web.archive.org/web/20221029145535/https://www.foxtonforensics.com/browser-history-examiner/firefox-history-location "Mozilla Firefox History Location | Firefox History Viewer | foxtonforensics.com"
[6]: https://web.archive.org/web/20221029145550/https://support.mozilla.org/en-US/questions/1319253 "Where does Firefox store SQLITE download history | Firefox Support Forum | Mozilla Support | support.mozilla.org"
[7]: https://web.archive.org/web/20221029145712/https://kb.mozillazine.org/Downloads.rdf "Downloads.rdf | MozillaZine Knowledge Base | kb.mozillazine.org"
call: call:
- -
function: DeleteFilesFromFirefoxProfiles
parameters:
pathGlob: downloads.rdf
-
function: DeleteFilesFromFirefoxProfiles
parameters:
pathGlob: downloads.sqlite
-
function: DeleteFilesFromFirefoxProfiles
parameters:
pathGlob: places.sqlite
-
function: DeleteFilesFromFirefoxProfiles
parameters:
pathGlob: favicons.sqlite
-
name: Clear all Firefox user information and preferences
docs: |-
This script performs a reset of Mozilla Firefox, erasing all user profiles, settings, and personalized data to restore the
browser to its default state.
Firefox user profiles, encompassing bookmarks, browsing history, passwords, extensions, themes, and preferences [1].
These folders are in:
- `C:\Documents and Settings\<Windows login/user name>\Application Data\Mozilla\Firefox\Profiles\<profile folder>` on Windows XP and earlier [1],
- `%APPDATA%\Mozilla\Firefox\Profiles\<profile folder>` on Windows 10 and later [1].
**Considerations**:
- Using this script results in a total loss of all personalized Firefox data.
- If your goal is solely to clear browsing data while retaining settings and extensions, this script is not recommended.
- Close Firefox before running this script to prevent potential issues.
[1]: https://web.archive.org/web/20231101125909/https://kb.mozillazine.org/Profile_folder_-_Firefox#Windows "Profile folder - Firefox - MozillaZine Knowledge Base | kb.mozillazine.org"
call:
- # Windows XP
function: ClearDirectoryContents function: ClearDirectoryContents
parameters: parameters:
directoryGlob: '%LOCALAPPDATA%\Mozilla\Firefox\Profiles' directoryGlob: '%LOCALAPPDATA%\Mozilla\Firefox\Profiles'
- - # Windows Vista and newer
function: ClearDirectoryContents function: ClearDirectoryContents
parameters: parameters:
directoryGlob: '%APPDATA%\Mozilla\Firefox\Profiles' directoryGlob: '%APPDATA%\Mozilla\Firefox\Profiles'
@@ -11760,3 +11809,16 @@ functions:
if ($skippedCount -gt 0) { if ($skippedCount -gt 0) {
Write-Host "Skipped $($skippedCount) items." Write-Host "Skipped $($skippedCount) items."
} }
-
name: DeleteFilesFromFirefoxProfiles
parameters:
- name: pathGlob # File name inin profile file
call:
- # Windows XP
function: DeleteFiles
parameters:
fileGlob: '%USERPROFILE%\Local Settings\Application Data\Mozilla\Firefox\Profiles\*\{{ $pathGlob }}'
- # Windows Vista and newer
function: DeleteFiles
parameters:
fileGlob: '%APPDATA%\Mozilla\Firefox\Profiles\*\{{ $pathGlob }}'