Skip to content

fix(screenshot): keep the capture binary until it is returned - #938

Merged
Kikobeats merged 1 commit into
masterfrom
Kikobeats/white-base64-6491a0dd
Sep 20, 2026
Merged

Kikobeats merged 1 commit into
masterfrom
Kikobeats/white-base64-6491a0dd

Conversation

@Kikobeats

@Kikobeats Kikobeats commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

What

encoding: 'base64' is one of the page.screenshot options this package promises to support, but it made puppeteer return a string instead of a Uint8Array. Under the default waitUntil: 'auto', the blank-page check then handed that string to sharp as image bytes:

Error: Input buffer contains unsupported image format
  at is-white-screenshot.js:58
  at takeScreenshot (src/index.js:211)

The overlay path decodes with sharp too, so it had the same problem.

encoding is now pulled out of the options given to page.screenshot, and applied once at the return. Every path (auto, an explicit waitUntil, fullPage, element, overlay) sees real bytes, and path writes stay binary as puppeteer intends. The encode is zero-copy (Buffer.from(buffer, byteOffset, byteLength)), and it only touches byte arrays, so overlay + path, which returns sharp's toFile info object, passes through untouched.

How it was tested

New regression test in packages/screenshot/test/index.js, covering auto, an explicit waitUntil: 'load', fullPage, overlay, and encoding: 'binary':

  • Without the fix: fails with the exact production error, Input buffer contains unsupported image format.
  • With the fix: passes.

Full packages/screenshot suite: everything passes except graphics features, which fails identically on master here (it needs WebGL through ANGLE, which this macOS host lacks). Lint clean.

Outcome

This was 14 events / 5 users over 14 days in the Microlink API's Sentry (MICROLINK-API-QEV), where every screenshot.encoding=base64 request was a 500. That metric should go to zero.

🤖 Generated with Claude Code


Note

Low Risk
Localized screenshot return-path change with a focused regression test; no auth or data-handling impact.

Overview
Fixes encoding: 'base64' breaking the default waitUntil: 'auto' path (and overlay): Puppeteer was returning a string, which sharp used for blank-page detection treated as raw bytes and threw Input buffer contains unsupported image format.

encoding is now stripped from options passed to page.screenshot, so internal steps always see binary. encodeScreenshot applies base64 only on the final return (zero-copy from the byte buffer). Overlay is awaited before encoding. encoding: 'binary' and non-buffer returns (e.g. path) pass through unchanged.

Adds a regression test covering auto, explicit load, fullPage, overlay, and binary encoding.

Reviewed by Cursor Bugbot for commit b9b30a1. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features
    • Added an encoding option for screenshots, including support for returning captures as base64 strings.
    • Preserved binary output when binary encoding is selected or no encoding is specified.
    • Encoding applies consistently across full-page, wait-condition, and overlay captures.

`encoding: 'base64'` is a documented page.screenshot option, but it made
puppeteer hand back a string, and the blank-page check under
`waitUntil: 'auto'` passed it to sharp as image bytes: "Input buffer
contains unsupported image format". The overlay decodes with sharp too.

Capture binary and encode once at the return, so every path (auto, a
fixed waitUntil, fullPage, element, overlay) sees real bytes. `path`
writes stay binary as puppeteer intends.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9117d4a0-4767-4a9d-ad31-4f72720eae17

📥 Commits

Reviewing files that changed from the base of the PR and between ccea4fa and b9b30a1.

📒 Files selected for processing (2)
  • packages/screenshot/src/index.js
  • packages/screenshot/test/index.js

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The screenshot API now accepts an encoding option. With encoding: 'base64', it returns a base64 string for raw and overlay captures. Other values preserve the existing binary output.

Changes

Screenshot encoding

Layer / File(s) Summary
Encoding return path
packages/screenshot/src/index.js, packages/screenshot/test/index.js
The screenshot callback accepts encoding. Base64 encoding applies to the selected raw or overlay image. Tests cover waitUntil, fullPage, overlay captures, and binary output.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: keeping screenshot captures in binary form until the function returns them.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 79.904% — Kikobeats/white-base64-6491a0dd into master. No base build found for master.

@Kikobeats
Kikobeats merged commit 352757e into master Sep 20, 2026
25 checks passed
@Kikobeats
Kikobeats deleted the Kikobeats/white-base64-6491a0dd branch September 20, 2026 09:43
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.

2 participants