Skip to content

Add error handling and validation to screenshot viewer#31

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/add-error-handling-screenshot-viewer
Draft

Add error handling and validation to screenshot viewer#31
Copilot wants to merge 4 commits intomainfrom
copilot/add-error-handling-screenshot-viewer

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 20, 2025

The screenshot viewer in AdminPanel.tsx lacked error handling for base64 data processing, risking runtime crashes on invalid input and memory leaks from unreleased object URLs.

Changes

  • Extracted handleViewScreenshot function from inline handler with try-catch-finally structure
  • Validation chain:
    • Regex check (/^data:[^;]+;base64,/) for proper data URL format
    • Split validation before array access to prevent undefined
    • 10MB size limit on base64 data to prevent browser hangs
  • Error recovery: Toast notifications with specific messages for different failure modes (missing data, invalid format, oversized payload, atob failure)
  • Resource cleanup: URL.revokeObjectURL() in finally block with 1000ms delay for new window load

Before:

onClick={() => {
  const base64Data = number.screenshot?.split(',')[1];
  const byteCharacters = atob(base64Data || '');
  // ... direct blob creation and window.open, no error handling
}}

After:

onClick={() => handleViewScreenshot(number.screenshot)}

// Separate function with:
// - Pre-flight validation (format, size)
// - try-catch around atob/Blob operations
// - finally block ensuring URL cleanup
// - Toast feedback for all error paths
Original prompt

This section details on the original issue you should resolve

<issue_title>Harden screenshot viewer: Add error handling for invalid base64 data</issue_title>
<issue_description>## Description

The screenshot viewer functionality in AdminPanel.tsx (lines ~464-478) currently lacks error handling when processing base64 data, which can lead to runtime crashes if invalid or malformed data is encountered.

Current Issue

  • No validation of base64 data before processing
  • can throw errors on invalid input
  • Large payloads can cause browser hangs
  • Missing error feedback to users
  • URL object leaks if errors occur during processing

Proposed Solution

  • Wrap base64 parsing and blob creation in try/catch blocks
  • Validate base64 data exists before processing
  • Add size limits for base64 data
  • Provide user feedback via toast notifications on errors
  • Ensure proper cleanup of object URLs in finally blocks

References

Files Affected

Priority

Medium - Security and user experience improvement</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 20, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 3 commits December 20, 2025 13:02
Co-authored-by: surendrakumar6350 <147039763+surendrakumar6350@users.noreply.github.com>
Co-authored-by: surendrakumar6350 <147039763+surendrakumar6350@users.noreply.github.com>
Co-authored-by: surendrakumar6350 <147039763+surendrakumar6350@users.noreply.github.com>
Copilot AI changed the title [WIP] Add error handling for invalid base64 data in screenshot viewer Add error handling and validation to screenshot viewer Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden screenshot viewer: Add error handling for invalid base64 data

2 participants