Skip to content

comet_screenshot tool not working - CDP captureScreenshot type mismatch #2

@whoiskjl

Description

@whoiskjl

Description

The comet_screenshot tool is not working properly. When called, it fails to return screenshot data.

Technical Analysis

Root Cause

The issue is in src/cdp-client.ts at line 1113:

async screenshot(format: "png" | "jpeg" = "png"): Promise<ScreenshotResult> {
  this.ensureConnected();
  return this.client!.Page.captureScreenshot({ format }) as Promise<ScreenshotResult>;
}

Problems identified:

  1. ensureConnected() is not being awaited, which means the connection check happens asynchronously but doesn't block execution
  2. The type assertion as Promise<ScreenshotResult> may be hiding a runtime type mismatch
  3. No error handling if the CDP method fails or returns unexpected data
  4. Missing additional CDP parameters that might be required for reliable screenshots

Expected Type

From src/types.ts line 27:

export interface ScreenshotResult {
  data: string; // Base64 encoded
}

Proposed Fix

Update the screenshot method in src/cdp-client.ts:

async screenshot(format: "png" | "jpeg" = "png"): Promise<ScreenshotResult> {
  await this.ensureConnected(); // Add await
  
  try {
    const result = await this.client!.Page.captureScreenshot({ 
      format,
      captureBeyondViewport: false // Add CDP options
    });
    
    if (!result || !result.data) {
      throw new Error("Screenshot returned no data");
    }
    
    return { data: result.data };
  } catch (error) {
    throw new Error(`Screenshot failed: ${error instanceof Error ? error.message : String(error)}`);
  }
}

Environment

  • Platform: Windows
  • Version: 2.5.0 (current main branch)

Impact

Users cannot capture screenshots of the current browser state, which is essential for debugging and monitoring agentic browsing tasks.Platform:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions