Skip to content

Cross-Browser Profile Support #54

Description

@bigboateng

Problem Statement

Currently, BrowserState stores browser profiles in a format optimized for Chromium-based browsers. When users try to use these profiles with Firefox or WebKit (Safari), the session data isn't properly transferred, leading to failed authentication and lost sessions.

Proposed Solution

Add native support for cross-browser profile migration within the BrowserState library. This would allow users to:

  1. Create a session in one browser (e.g., Chrome)
  2. Use that same session in another browser (e.g., Firefox or Safari)
  3. Maintain authentication and session state across browsers

SDK Design

New Types

// Browser types supported for profile migration
type BrowserType = 'chromium' | 'firefox' | 'webkit';

// Profile metadata to track browser-specific information
interface ProfileMetadata {
  browser: BrowserType;
  timestamp: number;
  sessionId: string;
  version: string;
  // Additional browser-specific metadata
  browserSpecific?: {
    chromium?: {
      profilePath: string;
    };
    firefox?: {
      profilePath: string;
    };
    webkit?: {
      profilePath: string;
    };
  };
}

// Options for mounting a session with a specific browser
interface MountOptions {
  browserType?: BrowserType;
  forceMigration?: boolean; // Force profile migration even if metadata suggests it's not needed
}

API Changes

class BrowserState {
  // Existing methods...

  /**
   * Mount a session with browser-specific profile handling
   * @param sessionId - The session ID to mount
   * @param options - Options for mounting the session
   * @returns The path to the browser-specific user data directory
   */
  async mount(sessionId: string, options?: MountOptions): Promise<string> {
    // Implementation would:
    // 1. Download session data from storage
    // 2. Check metadata for browser type
    // 3. If browser type doesn't match requested type, migrate profile
    // 4. Return path to browser-specific profile directory
  }

  /**
   * Get the browser-specific user data directory for a mounted session
   * @param sessionId - The session ID
   * @param browserType - The target browser type
   * @returns The path to the browser-specific user data directory
   */
  async getBrowserProfilePath(sessionId: string, browserType: BrowserType): Promise<string> {
    // Implementation would:
    // 1. Check if session is mounted
    // 2. Return path to browser-specific profile directory
    // 3. If profile doesn't exist, create it and migrate data
  }

  /**
   * Migrate a profile from one browser type to another
   * @param sourcePath - Path to source profile
   * @param targetBrowser - Target browser type
   * @returns Path to migrated profile
   */
  private async migrateProfile(
    sourcePath: string,
    targetBrowser: BrowserType
  ): Promise<string> {
    // Implementation would:
    // 1. Create target browser profile directory
    // 2. Copy and transform relevant files
    // 3. Update metadata
    // 4. Return path to new profile
  }
}

Profile Migration Strategy

  1. Metadata Tracking

    • Store browser type and version in profile metadata
    • Track which files are browser-specific
    • Maintain mapping of equivalent storage locations across browsers
  2. File Migration

    • Cookies: Convert between browser-specific formats
    • Local Storage: Copy and transform as needed
    • IndexedDB: Migrate database files
    • Cache: Handle browser-specific cache formats
  3. Browser-Specific Handling

    • Chromium: Use Default profile directory
    • Firefox: Create and manage profiles.ini
    • WebKit: Handle Safari-specific profile structure

Example Usage

// Initialize BrowserState
const browserState = new BrowserState({
  userId: 'user123',
  storageType: 'redis'
});

// Create session with Chrome
const chromePath = await browserState.mount('my-session', { browserType: 'chromium' });
// ... use with Chrome ...

// Use same session with Firefox
const firefoxPath = await browserState.mount('my-session', { browserType: 'firefox' });
// ... use with Firefox ...

// Use same session with Safari
const safariPath = await browserState.mount('my-session', { browserType: 'webkit' });
// ... use with Safari ...

Implementation Plan

  1. Phase 1: Core Migration

    • Add browser type tracking in metadata
    • Implement basic file copying between profiles
    • Support cookie migration between browsers
  2. Phase 2: Advanced Features

    • Add support for IndexedDB migration
    • Implement cache handling
    • Add browser-specific optimizations
  3. Phase 3: Testing & Stability

    • Add comprehensive cross-browser tests
    • Implement error handling and rollback
    • Document migration limitations

Limitations & Considerations

  1. Browser Compatibility

    • Some browser features may not be perfectly transferable
    • Browser-specific extensions won't be migrated
    • Certain security features may prevent full migration
  2. Performance

    • Profile migration may take time for large profiles
    • Need to optimize file copying and transformation
  3. Security

    • Ensure sensitive data is properly handled during migration
    • Maintain browser security features during transfer

Next Steps

  1. Create proof-of-concept implementation
  2. Add tests for cross-browser scenarios
  3. Document migration process and limitations
  4. Gather feedback from users
  5. Implement full solution based on feedback

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions