Skip to content

📸 Enhance Screenshot Directory UI and Fix File Saving #64

@ahelme

Description

@ahelme

📸 Screenshot Directory UI Enhancement & File Saving Fix

Problem Statement

Current screenshot functionality captures data but doesn't save files when using the UI button (direct flow). User needs better control over where screenshots are saved with improved UX.

Current Issues

  1. Missing File Saving: UI button captures screenshots but files aren't saved to disk
  2. Confusing Directory Input: Text field unclear about where files actually go
  3. No User Control: Can't easily choose save location
  4. Static UI Preview: Hardcoded placeholder instead of dynamic filename

Implementation Decision: Use HTTP Bridge for UI Clicks ✅

Chosen Approach: Option A - Use HTTP Bridge for UI clicks with proper circular dependency handling

Benefits:

  • Consistent saving mechanism (UI and MCP both use HTTP bridge)
  • Files saved to configured directory location
  • Reuses existing HTTP bridge file saving infrastructure
  • Centralized file management

Proposed Solution: Two-Phase Implementation

Phase 1: Fix File Saving (HTTP Bridge Method)

Implementation:

// Change UI button to use HTTP bridge (in screenshot.js)
const result = await this.captureViaBackground(
  selector,
  fullPage,
  smartFilename,
  format,
  quality,
  true  // sendToHttpBridge: true for UI clicks
);

// Properly handle circular dependency with improved WebSocket flow
// Background.js → HTTP bridge → WebSocket → Screenshot.js response

Circular Dependency Solution:

  • UI button → background.js → HTTP bridge (file saved) → WebSocket response → screenshot.js
  • Remove the circular loop by ensuring WebSocket response completes the flow
  • File saving happens in HTTP bridge, not triggered again by WebSocket

Phase 2: Enhance Directory UI

Current UI:

<input type="text" id="screenshot-path" placeholder="/path/to/screenshots" />

New Design:

<div class="input-row">
  <div style="width: 80%" class="directory-display">
    💾 /Users/username/Downloads/screenshots/
  </div>
  <div style="width: 20%">
    <button class="btn success" id="choose-directory-btn">Save to...</button>
  </div>
</div>

Add Clipboard Options:

<div style="display: flex; justify-content: space-between; align-items: center; margin-top: 2px;">
  <div style="font-size: 9px; color: #d4d4d8; font-weight: 500">
    Screenshots Directory:
  </div>
  <div style="display: flex; gap: 8px;">
    <label class="label" style="font-size: 8px;">
      <input type="checkbox" class="checkbox" id="add-to-clipboard-cb" />
      Add to Clipboard 📋
    </label>
    <label class="label" style="font-size: 8px;">
      <input type="checkbox" class="checkbox" id="auto-paste-cb" />
      Auto-Paste 📸 to Client
    </label>
  </div>
</div>

UI Changes Needed

1. Transform Directory Display (Panel 1)

  • Replace text input with read-only directory display
  • Add "Save to..." button (20% width, green success class)
  • Show current save location with folder emoji
  • Use monospace font for path clarity

2. Add Screenshot Options Checkboxes

  • Add to Clipboard 📋 - Copy screenshot to system clipboard
  • Auto-Paste 📸 to Client - Existing functionality (moved right)
  • Both checkboxes on same row, right-aligned

3. Add Directory Picker Functionality

  • "Save to..." button opens directory picker
  • Updates display when user selects new directory
  • Validates directory exists and is writable
  • Stores selection in extension settings

4. Update Screenshot Preview (Panel 2)

  • Replace hardcoded "page-title_2025-09-17_0001.png" with dynamic preview
  • Show actual next filename based on current page title
  • Update "Last" to show most recent actual screenshot

Technical Implementation

Phase 1: HTTP Bridge File Saving

// In screenshot.js - change UI button flow
async function captureScreenshot(options = {}) {
  // UI button now uses HTTP bridge for file saving
  const result = await this.captureViaBackground(
    selector,
    fullPage,
    filename,
    format,
    quality,
    true  // sendToHttpBridge: true
  );
  
  // Handle clipboard option
  if (settings.addToClipboard && result.success) {
    await this.copyToClipboard(result.data);
  }
}

Directory Picker (Phase 2)

// Use Chrome File System Access API
async function chooseDirectory() {
  const directoryHandle = await window.showDirectoryPicker();
  const directoryPath = await directoryHandle.name;
  settings.screenshotDirectory = directoryPath;
  updateDirectoryDisplay(directoryPath);
}

Clipboard Integration

// Add to clipboard functionality
async function copyToClipboard(screenshotData) {
  const blob = dataURLtoBlob(screenshotData);
  const item = new ClipboardItem({ 'image/png': blob });
  await navigator.clipboard.write([item]);
}

Files to Modify

Phase 1 (File Saving):

  1. screenshot.js - Change UI button to use sendToHttpBridge: true
  2. background.js - Ensure HTTP bridge flow works properly
  3. panel.js - Add clipboard settings handling

Phase 2 (UI Enhancement):

  1. panel-ui-change-test.html - Create test UI file
  2. panel.html - Final UI updates with new checkboxes
  3. panel.js - Directory picker logic + clipboard handling
  4. CSS updates for directory display styling

User Experience Flow

  1. File Saving Fixed: Screenshot button saves actual files via HTTP bridge
  2. Choose Options: Check "Add to Clipboard 📋" and/or "Auto-Paste 📸 to Client"
  3. Choose Location: Click "Save to..." → Select directory
  4. Visual Feedback: See current save location: 💾 /Users/me/Pictures/
  5. Take Screenshot:
    • File saved to chosen directory via HTTP bridge
    • Optionally copied to clipboard
    • Optionally auto-pasted to client

Settings Schema Update

settings = {
  // ... existing settings
  screenshotDirectory: '/Users/username/Downloads/screenshots/',
  addToClipboard: false,        // NEW: Copy to clipboard option
  autoPaste: false,             // Existing: Auto-paste to client
  saveMethod: 'http-bridge'     // Force HTTP bridge for consistency
}

Benefits

Files Actually Saved: Via HTTP bridge (consistent with MCP)
Clipboard Integration: Optional copy to system clipboard
User Control: Choose exact save location
Clear Feedback: See where files will be saved
Consistent UX: Matches system file picker patterns
No Circular Dependencies: Proper WebSocket flow handling
Visual Consistency: Matches existing panel design
Responsive Design: Works on all screen sizes

Testing Checklist

  • Phase 1: Screenshot files actually saved to disk via HTTP bridge
  • Phase 1: Circular dependency properly handled
  • Phase 1: Clipboard integration working
  • Phase 2: UI test file renders correctly
  • Phase 2: Directory display shows current path
  • Phase 2: "Save to..." button opens picker
  • Phase 2: New checkboxes function properly
  • Phase 2: Screenshots save to chosen location
  • Settings persist across extension reloads
  • Responsive layout at 800px, 600px breakpoints

Priority: High (Phase 1 critical - screenshots not saving!)
Difficulty: Medium
Agent: Agent D - Screenshot Visualizer
Implementation Decision: ✅ HTTP Bridge Method Chosen
Dependencies: None

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions