How Firefox Portable Runs From a USB Without Leaving Traces
This article explains the technical mechanics behind Mozilla Firefox, Portable Edition, developed by PortableApps.com. It details how the software packages the browser application and user profile together using a specialized directory structure, a custom wrapper launcher, command-line redirection, and automated cleanup scripts to run entirely from a USB flash drive without leaving personal data on the host computer.
The Self-Contained Directory Structure
Standard installations of Firefox scatter files across a computer's
hard drive, placing executable files in the Program Files
directory and user data in the hidden AppData folder.
Firefox Portable solves this by consolidating everything into a single
root folder on the USB drive, divided into two main subdirectories:
- The
AppFolder: Contains the unmodified Mozilla Firefox binary files (such asfirefox.exeand its core libraries). Keeping the core application untouched ensures stability and makes updating the browser straightforward. - The
DataFolder: Houses the user profile, including bookmarks, browsing history, saved passwords, cookies, and installed extensions.
By keeping the App and Data folders in the
same parent directory, the software has everything it needs in one
physical location.
The Wrapper Launcher
Users do not click on firefox.exe to start the portable
browser. Instead, they run FirefoxPortable.exe, a custom
wrapper launcher built using the Nullsoft Scriptable Install System
(NSIS).
This launcher acts as a bridge between the host operating system and the Firefox application. When executed, the launcher initializes a controlled environment, prepares the user profile, starts the actual Firefox browser, and remains running silently in the background to monitor the session.
Command-Line Profile Redirection
Normally, when firefox.exe starts, it queries the
Windows operating system to find the current user's AppData
directory to load their profile.
The PortableApps launcher bypasses this default behavior by utilizing
a built-in Firefox command-line argument: -profile. When
FirefoxPortable.exe starts the main browser, it passes a
command similar to this:
firefox.exe -profile "X:\FirefoxPortable\Data\profile"
This forces the browser to read and write all user data directly to
the Data folder on the USB flash drive, completely ignoring
the host computer's hard drive.
Dynamic Path Updating
A major challenge for portable software is that USB flash drives are
assigned different drive letters (e.g., E:\,
F:\, G:\) depending on which computer they are
plugged into. While Firefox handles most profile data using relative
paths, certain extensions and configuration files hardcode the absolute
drive letter.
Before the browser window even opens, the PortableApps launcher
checks the current drive letter and compares it to the drive letter used
during the previous session. If the letter has changed, the launcher
rapidly scans the configuration files inside the Data
folder (such as prefs.js and extension databases) and
rewrites the old drive letter to match the new one.
Environment Variable Redirection
Web browsers rely heavily on the host operating system's temporary folders to cache media, stage downloads, and process data. To prevent these files from being left behind on the host PC, the launcher modifies the local environment variables exclusively for the Firefox session.
Before launching the browser, FirefoxPortable.exe
redirects the system's TEMP and TMP variables
to point to a temporary directory on the USB drive or a isolated folder
it controls. Because child processes inherit the environment variables
of their parent process, firefox.exe uses these redirected
paths instead of the host computer's default temporary folders.
Host System Sandboxing and Cleanup
Despite profile redirection, Firefox and its plugins still attempt to
write to the Windows Registry and create folders in the local
AppData directory for system integration and crash
reporting. The launcher handles this through a backup-and-restore
routine:
- Pre-Launch Backup: If the host computer already has
a local installation of Firefox, the launcher backs up existing Mozilla
registry keys and renames local
Mozillafolders inAppDataso they are not overwritten. - Session Monitoring: The launcher waits quietly while the user browses the web.
- Post-Session Cleanup: Once the user closes the
Firefox window, the launcher detects that
firefox.exehas terminated. It immediately deletes any registry keys or localAppDatafolders generated during the portable session, empties the redirected temporary folder, and restores the host computer's original registry backups and folder names.
Once this cleanup script finishes, FirefoxPortable.exe
closes itself, leaving the host machine in the exact state it was in
before the USB drive was inserted.