How to Customize the Firefox Profile Path for Browser Automation in MoneyPrinterV2

MoneyPrinterV2 stores Firefox profile paths per social-media account in JSON cache files and injects them into Selenium via the -profile command-line argument, enabling stateful browser automation across YouTube, Twitter, and affiliate marketing workflows.

MoneyPrinterV2 is an open-source automation framework that relies on persistent Firefox profiles to maintain login sessions for multiple accounts. To customize the Firefox profile path for browser automation in MoneyPrinterV2, you modify the configuration layer in src/config.py, the account creation logic in src/main.py, or the cached account records that provider classes consume when launching Selenium.

How MoneyPrinterV2 Manages Firefox Profiles

The application follows a three-tier configuration strategy that separates global defaults from per-account overrides.

Configuration API

In src/config.py, the function get_firefox_profile_path() reads the global firefox_profile entry from config.json. This serves as a fallback default when no account-specific path is provided.

Account Creation Flow

When you create a new account via the CLI in src/main.py, the application prompts for a profile directory and stores it under the firefox_profile key in the account record. This value is then serialized to a cache file (e.g., .mp/cache_youtube.json).

Selenium Integration

Each provider class—such as YouTube, Twitter, and AFM—receives the stored path during instantiation. The constructor validates the directory exists using os.path.isdir(self._fp_profile_path) and raises a ValueError if the path is invalid. Upon validation, the class appends the -profile argument to the Firefox options before initializing the WebDriver.

Three Methods to Customize the Firefox Profile Path

You can override the default behavior using one of three approaches, depending on whether you need an interactive, manual, or global solution.

1. Interactive Setup During Account Creation

Run the application and select "Create a new account." When prompted with Enter the path to the Firefox profile:, supply the absolute path to your profile directory.


# src/main.py (excerpt)

fp_profile = question(" => Enter the path to the Firefox profile: ")
account_data = {
    "firefox_profile": fp_profile,
    # additional account metadata...

}
add_account("youtube", account_data)

This method stores the path in the local account cache and uses it for all subsequent sessions tied to that account.

2. Edit Cached Account JSON Directly

Locate the account cache file for the specific provider (e.g., .mp/cache_youtube.json or .mp/cache_twitter.json) and modify the firefox_profile value. This approach is useful for bulk updates or correcting typos without recreating accounts.


# View current configuration

cat .mp/cache_youtube.json | jq .

# Edit the firefox_profile field to the new directory path

Ensure the new path points to a valid Firefox profile directory containing files such as prefs.js and user.js.

3. Global Default in config.json

Add a firefox_profile key to the root config.json file. While the provider classes prioritize per-account values, they can fall back to this global setting via get_firefox_profile_path() when no account-specific path is supplied.

Validation and Error Handling

The provider constructors enforce strict validation. In src/classes/YouTube.py (lines 86-89), the code checks:

if not os.path.isdir(self._fp_profile_path):
    raise ValueError(f"Firefox profile path does not exist: {self._fp_profile_path}")

If the directory is missing, the automation stops immediately. The profile directory must be a complete Firefox profile folder, not merely an empty directory.

Code Implementation Examples

Launching Firefox with Custom Profile

The following excerpt from src/classes/YouTube.py demonstrates how the customized path is applied to Selenium:


# src/classes/YouTube.py (excerpt)

self.options.add_argument("-profile")
self.options.add_argument(self._fp_profile_path)  # Custom path injected here

self.browser = webdriver.Firefox(
    service=self.service, 
    options=self.options
)

This pattern is identical across Twitter.py and AFM.py, ensuring consistent profile handling regardless of the target platform.

Preflight Validation Script

The repository includes scripts/preflight_local.py, which validates that configured profile paths exist before the main automation loop begins, preventing mid-process failures due to missing directories.

Summary

  • MoneyPrinterV2 isolates Firefox profiles per account to maintain distinct login states for YouTube, Twitter, and affiliate marketing automation.
  • Customize the path via interactive CLI prompts during account creation, by editing JSON cache files directly, or by setting a global default in config.json.
  • Provider classes in src/classes/ validate paths using os.path.isdir() and pass the directory to Selenium via the -profile argument.
  • Invalid paths raise ValueError immediately, ensuring automation only proceeds with accessible, valid Firefox profiles.

Frequently Asked Questions

Where does MoneyPrinterV2 store the Firefox profile path for each account?

The path is stored in account-specific JSON cache files located in the .mp/ directory (e.g., cache_youtube.json, cache_twitter.json) under the firefox_profile key. These files are created when you run the account creation workflow in src/main.py.

What happens if I provide an invalid Firefox profile path?

The constructor in each provider class (such as YouTube.py) validates the path using os.path.isdir(). If the directory does not exist, the application raises a ValueError with a descriptive message and halts execution before launching the browser.

Can I use the same Firefox profile for multiple MoneyPrinterV2 accounts?

Yes, multiple account records can reference the same absolute path in their respective cache files. However, concurrent automation sessions using the same profile may cause conflicts; ensure only one process accesses a given profile simultaneously to avoid corruption.

How do I find my existing Firefox profile directory on my system?

Firefox profiles are typically located in your user home directory under .mozilla/firefox/ (Linux/macOS) or %APPDATA%\Mozilla\Firefox\Profiles\ (Windows). Look for directories ending in .default-release or similar. You can also enter about:profiles in Firefox's address bar to view exact paths for all registered profiles.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →