PSP-PersistentSessionsProtocol

@psp/core

Core library for the PersistentSessionsProtocol (PSP) - a unified approach for browser session persistence across frameworks.

npm version License: MIT

Overview

The PersistentSessionsProtocol (PSP) creates a standardized approach for browser automation tools to save, share, and restore session data across different frameworks and machines. This protocol bridges the critical gap in browser automation by providing a framework-agnostic method for persisting state, significantly reducing authentication friction and improving testing reliability.

This package (@psp/core) provides the core functionality and data structures needed to implement the protocol:

Installation

npm install @psp/core

Basic Usage

The core library is typically used alongside a framework-specific adapter:

import { LocalStorageProvider } from '@psp/core';
import { PlaywrightAdapter } from '@psp/playwright';

// Initialize storage provider
const storage = new LocalStorageProvider();

// Create adapter with storage
const adapter = new PlaywrightAdapter({ storage });

// Use the adapter with your framework

Storage Providers

The core package includes multiple storage providers:

import { 
  LocalStorageProvider, 
  CloudStorageProvider 
} from '@psp/core';

// Local file system storage
const localStorage = new LocalStorageProvider({
  basePath: './sessions'
});

// Cloud storage (AWS S3, Google Cloud Storage, Azure Blob)
const cloudStorage = new CloudStorageProvider({
  provider: 's3',
  bucket: 'my-sessions-bucket',
  region: 'us-west-2',
  credentials: {
    accessKeyId: process.env.AWS_ACCESS_KEY_ID,
    secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
  }
});

Creating Custom Adapters

You can implement custom adapters for any browser automation framework:

import { BaseAdapter, SessionState } from '@psp/core';

class MyCustomAdapter extends BaseAdapter {
  async captureState(target) {
    // Implement state capture logic specific to your framework
    // Should return a SessionState object
  }
  
  async applyState(target, state) {
    // Implement state restoration logic specific to your framework
  }
}

Data Model

The core library defines the data model for browser session state:

interface BrowserSessionState {
  // Protocol version
  version: string;
  
  // Creation timestamp
  timestamp: number;
  
  // Origin where the session was captured
  origin: string;
  
  // Storage state (cookies, localStorage, etc.)
  storage: StorageState;
  
  // Optional components
  dom?: DOMState;
  history?: HistoryState;
  network?: NetworkState;
  recording?: RecordingState;
}

API Documentation

Classes

Utilities

Contributing

Contributions are welcome! Please see the contributing guidelines for more information.

License

MIT