Lounge Started Apr 29, 2026 12:44 AM

按文件夹颜色区分的浏览器窗口

2 replies - 30 views - 0 thanks - 0 tippers - 1 watchers

Apr 29, 2026 12:44 AM Last edited Apr 29, 2026 1:04 AM
#1
browsers color-coded

$ cat README.md

Browser Instance Management Project

Architecture Overview

This project manages multiple isolated browser instances organized in a structured directory layout. Each browser instance runs with its own profile, configuration, and isolated XDG directories.

Directory Structure

/
├── 0001/                   # Folder 1 - Blue theme
│   ├── lw/                 # LibreWolf instances
│   │   ├── 1/              # Instance 1
│   │   │   ├── launch.sh   # Launch script
│   │   │   ├── profile/    # Browser profile
│   │   │   ├── home/       # Isolated HOME
│   │   │   ├── .config/    # XDG_CONFIG_HOME
│   │   │   ├── .cache/     # XDG_CACHE_HOME
│   │   │   ├── .local/     # XDG_DATA_HOME & XDG_STATE_HOME
│   │   │   └── runtime/    # XDG_RUNTIME_DIR
│   │   ├── 2/..8/         # Instances 2-8 (same structure)
│   │   └── [AppImage]      # LibreWolf AppImage
│   └── mlv/                # Mullvad Browser instances
│       ├── 1/..8/          # Instances 1-8
│       └── mullvad-browser/ # Browser binaries
│
├── 0002/                   # Folder 2 - Green theme (same structure)
├── 0003/                   # Folder 3 - Red theme (same structure)
└── archived/                # Archived browser configurations

Key Features

  • Isolated Profiles: Each instance maintains its own profile directory
  • XDG Directory Isolation: Complete separation of user directories per instance
  • Multi-Instance Support: 8 LibreWolf + 8 Mullvad Browser instances per folder
  • Color-Coded Folders: Visual distinction between folder groups (see below)
  • Audio Support: PulseAudio socket sharing for audio playback
  • Sandbox Compatibility: Filters harmless sandbox warnings

Color Coding Implementation

Purpose

Each folder (0001, 0002, 0003) has a distinct color scheme applied to the browser chrome (UI). This provides instant visual identification of which folder a browser belongs to when managing multiple instances.

Color Scheme

Folder Primary Color Tab Bar Color CSS Color Codes
0001 Blue Dark Blue #3498db / #2980b9
0002 Green Dark Green #2ecc71 / #27ae60
0003 Red Dark Red #e74c3c / #c0392b

Technical Implementation

The color coding uses Firefox's userChrome.css mechanism, which styles the browser's UI elements:

  1. userChrome.css: Created in each instance's profile/chrome/ directory
  2. user.js: Updated to enable custom stylesheets via toolkit.legacyUserProfileCustomizations.stylesheets

Files Modified

For each of the 48 browser instances (8 LW + 8 MLV × 3 folders):

  • Created: profile/chrome/userChrome.css
  • Modified: profile/user.js (appended preference if not present)

userChrome.css Example (0001 - Blue)

/* Color coding for folder 0001 - LW instance 1 */
#navigator-toolbox {
    background-color: #3498db !important;
}

#TabsToolbar {
    background-color: #2980b9 !important;
}

#nav-bar {
    background-color: #3498db !important;
}

user.js Addition

// Enable userChrome.css for color coding
user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);

Applying/Reapplying Color Coding

A script is provided to apply or reapply the color coding. The script automatically detects its location, so it can be run from anywhere:

./apply-color-coding.sh

Or from the project directory:

cd /path/to/sw
./apply-color-coding.sh

This script will:

  • Create chrome/ directories in all profile folders
  • Generate userChrome.css with folder-specific colors
  • Update user.js files to enable custom stylesheets

Verification

After applying, launch browsers from different folders:

  • 0001 browsers → Blue chrome (navigator toolbox and tabs)
  • 0002 browsers → Green chrome
  • 0003 browsers → Red chrome

Restart any running browser instances to see the changes.


Fingerprinting Considerations

The color coding approach has minimal fingerprinting risk:

  1. Browser chrome is not exposed to websites - The CSS modifications affect #navigator-toolbox and #TabsToolbar, which are browser UI elements inaccessible to web pages
  2. No DOM exposure - Unlike userContent.css (which affects web content), userChrome.css only styles the browser's own interface
  3. Preference flag undetectable - Setting toolkit.legacyUserProfileCustomizations.stylesheets = true is not exposed through standard web APIs

The existing privacy settings in prefs.js provide robust fingerprinting protection:

  • privacy.resistFingerprinting.letterboxing = true
  • privacy.fingerprintingProtection = true
  • privacy.trackingprotection.enabled = true

Launch Script Details

Each instance has a launch.sh script that:

  1. Sets up isolated XDG directories
  2. Configures PulseAudio for audio
  3. Sets LD_LIBRARY_PATH for codec libraries
  4. Launches the browser with:
  • -profile flag for isolated profile
  • -no-remote for multi-instance support
  • Filters harmless sandbox warnings

Example launch command:

./0001/lw/1/launch.sh

Browser Types

LibreWolf (lw)

  • AppImage-based deployment
  • Privacy-focused Firefox fork
  • Instance path: {folder}/lw/{instance}/

Mullvad Browser (mlv)

  • Tor-project based browser
  • Enhanced privacy and anonymity
  • Instance path: {folder}/mlv/{instance}/
  • Includes media playback settings in user.js

File Count Summary

Component Count
Total instances per folder 16 (8 LW + 8 MLV)
Total instances (all folders) 48
userChrome.css files created 48
user.js files updated 48
Color schemes 3 (one per folder)

Troubleshooting

Colors not showing after applying:

  • Ensure browsers are restarted after applying the color coding
  • Verify userChrome.css exists in profile/chrome/ directory
  • Check that toolkit.legacyUserProfileCustomizations.stylesheets is set to true in user.js

To remove color coding:

# Remove all chrome directories (run from project root)
find 0001 0002 0003 \
  -path "*/profile/chrome" -type d -exec rm -rf {} \; 2>/dev/null

Project Maintenance

  • Script location: Relative to project root (apply-color-coding.sh)
  • Last applied: Check file timestamps on userChrome.css files
  • To modify colors: Edit the color definitions in apply-color-coding.sh and re-run
  • Portability: Script uses relative paths and can be run from any location
0 thanks - 0 tippers - 1 watchers

Replies

Page 1 of 1 - 2 total
Apr 29, 2026 1:05 AM Edited Apr 29, 2026 1:05 AM
#2

$ cat apply-color-coding.sh

#!/bin/bash
# apply-color-coding.sh - Apply folder-based color coding to all browser instances

# Get script directory (works even if called via symlink)
BASE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FOLDERS="0001 0002 0003"
BROWSERS="lw mlv"
INSTANCES="1 2 3 4 5 6 7 8"

# Color definitions
declare -A PRIMARY_COLORS
PRIMARY_COLORS[0001]="#3498db"
PRIMARY_COLORS[0002]="#2ecc71"
PRIMARY_COLORS[0003]="#e74c3c"

declare -A TAB_COLORS
TAB_COLORS[0001]="#2980b9"
TAB_COLORS[0002]="#27ae60"
TAB_COLORS[0003]="#c0392b"

for folder in $FOLDERS; do
    for browser in $BROWSERS; do
        for instance in $INSTANCES; do
            PROFILE_DIR="$BASE/$folder/$browser/$instance/profile"
            
            if [ -d "$PROFILE_DIR" ]; then
                echo "Processing: $folder/$browser/$instance"
                
                # Create chrome directory
                mkdir -p "$PROFILE_DIR/chrome"
                
                # Create userChrome.css with folder-specific colors
                cat > "$PROFILE_DIR/chrome/userChrome.css" <<EOF
/* Color coding for folder $folder - ${browser^^} instance $instance */
#navigator-toolbox {
    background-color: ${PRIMARY_COLORS[$folder]} !important;
}

#TabsToolbar {
    background-color: ${TAB_COLORS[$folder]} !important;
}

#nav-bar {
    background-color: ${PRIMARY_COLORS[$folder]} !important;
}
EOF
                
                # Check if user.js exists
                if [ -f "$PROFILE_DIR/user.js" ]; then
                    # Append preference if not already present
                    if ! grep -q "toolkit.legacyUserProfileCustomizations.stylesheets" "$PROFILE_DIR/user.js"; then
                        echo '' >> "$PROFILE_DIR/user.js"
                        echo '// Enable userChrome.css for color coding' >> "$PROFILE_DIR/user.js"
                        echo 'user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);' >> "$PROFILE_DIR/user.js"
                    fi
                else
                    # Create new user.js
                    cat > "$PROFILE_DIR/user.js" <<EOF
// Enable userChrome.css for color coding
user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);
EOF
                fi
                
                echo "  ✓ Applied ${PRIMARY_COLORS[$folder]} to $folder/$browser/$instance"
            fi
        done
    done
done

echo ""
echo "Color coding applied successfully!"
echo "Restart browsers to see changes."
0 thanks - 0 tippers
Apr 29, 2026 1:05 AM
#3

$ cat 0001/lw/1/launch.sh

#!/bin/bash
set -euo pipefail

# Get script directory (resolves even if called via symlink)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Redirect all user/system directories to within this folder
export HOME="${SCRIPT_DIR}/home"
export XDG_CONFIG_HOME="${SCRIPT_DIR}/.config"
export XDG_CACHE_HOME="${SCRIPT_DIR}/.cache"
export XDG_DATA_HOME="${SCRIPT_DIR}/.local/share"
export XDG_STATE_HOME="${SCRIPT_DIR}/.local/state"
export XDG_RUNTIME_DIR="${SCRIPT_DIR}/runtime"

# Create directories with proper permissions
mkdir -p "${SCRIPT_DIR}/profile" "${HOME}" "${XDG_CONFIG_HOME}" "${XDG_CACHE_HOME}" \
       "${XDG_DATA_HOME}" "${XDG_STATE_HOME}" "${XDG_RUNTIME_DIR}"
chmod 700 "${XDG_RUNTIME_DIR}"

# Allow access to system PulseAudio for audio
export PULSE_SERVER="unix:/run/user/$(id -u)/pulse/native"

# Allow AppImage to find system codec libraries
export LD_LIBRARY_PATH="/usr/lib:${LD_LIBRARY_PATH:-}"

# Launch AppImage with local profile and multi-instance support
# Filter harmless warnings when unprivileged user namespaces are disabled
exec "${SCRIPT_DIR}/LibreWolf-150.0.1-2.x86_64.AppImage" \
  -profile "${SCRIPT_DIR}/profile" \
  -no-remote \
  "$@" 2>&1 | grep -v -E "Sandbox.*EPERM|mesa_glthread|Glycin.*sandbox" >&2
0 thanks - 0 tippers

Post A Reply

You must be logged in to reply. Login or register.