Skip to content

Add option to get screenshot as a buffer#304

Open
Christian-Holbrook wants to merge 1 commit into
v4from
screenshot-as-buffer
Open

Add option to get screenshot as a buffer#304
Christian-Holbrook wants to merge 1 commit into
v4from
screenshot-as-buffer

Conversation

@Christian-Holbrook

@Christian-Holbrook Christian-Holbrook commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Adds returnBuffer option to captureScreenshot() that returns a Buffer instead of writing to disk.

Closes #172


API

  // Existing behavior - returns file path
  const path = await rokuDeploy.captureScreenshot({ host, password });


  // New behavior - returns Buffer
  const buffer = await rokuDeploy.captureScreenshot({ host, password, returnBuffer: true });

Why Overloads?

TypeScript overloads provide proper return type inference based on the options passed:

// TypeScript knows this is Promise<Buffer>
const buffer = await captureScreenshot({ host, password, returnBuffer: true });

// TypeScript knows this is Promise<string>
const path = await captureScreenshot({ host, password });

Without overloads, the return type would be Promise<string | Buffer>, requiring users to narrow the type manually:

  // Without overloads - awkward
  const result = await captureScreenshot({ host, password, returnBuffer: true });
  if (Buffer.isBuffer(result)) {
    // now we can use it as Buffer
  }

This pattern follows the existing convention in the codebase (see getDeviceInfo() with its enhance option).

@Christian-Holbrook Christian-Holbrook changed the base branch from master to v4 July 2, 2026 17:03
@TwitchBronBron TwitchBronBron added this to the v4.0.0 milestone Jul 2, 2026
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.

Support getting screenshot as stream instead of file

2 participants