Skip to content

Add Chromium screenshot routes (HTML and URL)#74

Merged
Jaben merged 4 commits intodevelopfrom
feature/screenshot-routes
Mar 29, 2026
Merged

Add Chromium screenshot routes (HTML and URL)#74
Jaben merged 4 commits intodevelopfrom
feature/screenshot-routes

Conversation

@Jaben
Copy link
Copy Markdown
Member

@Jaben Jaben commented Mar 28, 2026

Summary

  • New request hierarchy: ScreenshotRequest (base) -> ScreenshotHtmlRequest, ScreenshotUrlRequest
  • New builder hierarchy: BaseScreenshotBuilder -> ScreenshotHtmlRequestBuilder, ScreenshotUrlRequestBuilder
  • ScreenshotProperties facet with device dimensions, format, quality, clip, omitBackground, optimizeForSpeed
  • DDD value objects: ScreenshotFormat (png/jpeg/webp), CompressionQuality (0-100), ScreenDimension (positive pixels)
  • Add ScreenshotHtmlAsync and ScreenshotUrlAsync methods to GotenbergSharpClient
  • API paths: /forms/chromium/screenshot/url, /forms/chromium/screenshot/html

Test plan

  • 16 unit tests covering value objects, builders, and serialization
  • 2 integration tests — HTML screenshot verified via PNG magic bytes, URL screenshot verified
  • Screenshot example console app added
  • README sections for HTML and URL screenshots added

Summary by CodeRabbit

Release Notes

  • New Features

    • Added screenshot functionality for capturing images from HTML content and URLs via new ScreenshotHtmlAsync and ScreenshotUrlAsync client methods with configurable properties (dimensions, format, quality, clipping).
  • Documentation

    • Added README sections documenting screenshot capabilities with usage examples.
  • Examples

    • Added new screenshot example project demonstrating HTML and URL screenshot capture workflows.
  • Tests

    • Added comprehensive test suite for screenshot functionality.

Introduce screenshot support for HTML and URL content with new request
hierarchy: ScreenshotRequest (base) -> ScreenshotHtmlRequest,
ScreenshotUrlRequest. Parallel builder hierarchy with
BaseScreenshotBuilder, ScreenshotHtmlRequestBuilder,
ScreenshotUrlRequestBuilder.

Add DDD value objects: ScreenshotFormat (png/jpeg/webp),
CompressionQuality (0-100), ScreenDimension (positive pixels).
Add ScreenshotProperties facet and ScreenshotPropertyBuilder.

Add ScreenshotHtmlAsync and ScreenshotUrlAsync methods to
GotenbergSharpClient. Include Screenshot example project and
README sections.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 28, 2026

Warning

Rate limit exceeded

@Jaben has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 20 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 20 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3470c5e6-8e1a-4c1b-a969-cc48e88c0c94

📥 Commits

Reviewing files that changed from the base of the PR and between 0abe5e5 and 1e192dc.

📒 Files selected for processing (7)
  • README.md
  • examples/Screenshot/Program.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/Facets/FacetBase.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs
  • src/Gotenberg.Sharp.Api.Client/GotenbergSharpClient.cs
  • src/Gotenberg.Sharp.Api.Client/Infrastructure/Constants.cs
  • test/GotenbergSharpClient.Tests/ScreenshotTests.cs
📝 Walkthrough

Walkthrough

Added screenshot functionality to the Gotenberg Sharp API Client with new value objects for validated dimensions and quality settings, request types for HTML and URL screenshots, fluent builders for configuration, and client methods to execute screenshot operations.

Changes

Cohort / File(s) Summary
Domain Value Objects
src/Gotenberg.Sharp.Api.Client/Domain/ValueObjects/ScreenDimension.cs, CompressionQuality.cs, ScreenshotFormat.cs
Added three value objects: ScreenDimension for validated pixel dimensions (positive integers), CompressionQuality for validated quality range (0–100), and ScreenshotFormat enum (Png, Jpeg, Webp) with form serialization extension.
Request Infrastructure
src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs, ScreenshotHtmlRequest.cs, ScreenshotUrlRequest.cs
Added abstract ScreenshotRequest base class with screenshot properties and conversion behaviors; sealed ScreenshotHtmlRequest for HTML-to-screenshot conversion; sealed ScreenshotUrlRequest for URL-to-screenshot conversion with URI validation and form serialization.
Screenshot Builders
src/Gotenberg.Sharp.Api.Client/Domain/Builders/BaseScreenshotBuilder.cs, ScreenshotHtmlRequestBuilder.cs, ScreenshotUrlRequestBuilder.cs
Added abstract base builder BaseScreenshotBuilder with fluent methods for screenshot properties, conversion behaviors, and assets; sealed concrete builders ScreenshotHtmlRequestBuilder and ScreenshotUrlRequestBuilder for fluent configuration and request building.
Property Builder & Facet
src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/ScreenshotPropertyBuilder.cs, src/Gotenberg.Sharp.Api.Client/Domain/Requests/Facets/ScreenshotProperties.cs, FacetBase.cs
Added ScreenshotPropertyBuilder for fluent screenshot property configuration (width, height, clip, format, quality, background omission, speed optimization); added ScreenshotProperties facet class with multipart form header bindings; updated FacetBase to serialize ScreenshotFormat enum values.
Client API & Infrastructure
src/Gotenberg.Sharp.Api.Client/GotenbergSharpClient.cs, src/Gotenberg.Sharp.Api.Client/Infrastructure/Constants.cs
Added four new public virtual methods to GotenbergSharpClient for screenshot endpoints (request and builder overloads for both HTML and URL); added screenshot API path and form field name constants to Constants.Gotenberg.Chromium.
Example & Project
examples/Screenshot/Program.cs, examples/Screenshot/Screenshot.csproj
Added console application demonstrating screenshot HTML and URL workflows with configuration loading, output file generation, and authentication support.
Tests
test/GotenbergSharpClient.Tests/ScreenshotTests.cs
Added comprehensive test suite covering value object validation, builder configuration, property serialization, and integration tests for authenticated screenshot operations with PNG validation.
Documentation
README.md
Added sections documenting HTML and URL screenshot capabilities with example usage of request builders and API calls.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Builder as ScreenshotHtmlRequestBuilder
    participant Request as ScreenshotHtmlRequest
    participant GotenbergClient as GotenbergSharpClient
    participant API as Gotenberg API

    Client->>Builder: new ScreenshotHtmlRequestBuilder()
    Client->>Builder: AddDocument(action)
    Builder->>Request: Configure Content (FullDocument)
    Client->>Builder: WithScreenshotProperties(action)
    Builder->>Request: Set screenshot properties
    Client->>Builder: BuildAsync()
    Builder->>Request: Validate & serialize
    Builder-->>Client: return Request
    Client->>GotenbergClient: ScreenshotHtmlAsync(builder)
    GotenbergClient->>Request: CreateApiRequest()
    GotenbergClient->>API: POST /forms/chromium/screenshot/html
    API-->>GotenbergClient: Stream (PNG bytes)
    GotenbergClient-->>Client: return Stream
Loading
sequenceDiagram
    participant Client
    participant Builder as ScreenshotUrlRequestBuilder
    participant Request as ScreenshotUrlRequest
    participant GotenbergClient as GotenbergSharpClient
    participant API as Gotenberg API

    Client->>Builder: new ScreenshotUrlRequestBuilder()
    Client->>Builder: SetUrl(url)
    Builder->>Request: Validate & assign Uri
    Client->>Builder: WithScreenshotProperties(action)
    Builder->>Request: Set screenshot properties
    Client->>Builder: BuildAsync()
    Builder->>Request: Validate & serialize
    Builder-->>Client: return Request
    Client->>GotenbergClient: ScreenshotUrlAsync(builder)
    GotenbergClient->>Request: CreateApiRequest()
    GotenbergClient->>API: POST /forms/chromium/screenshot/url
    API-->>GotenbergClient: Stream (JPEG bytes)
    GotenbergClient-->>Client: return Stream
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~28 minutes

Possibly Related PRs

  • PR #61: Modifies FacetBase value-to-form-content conversion pipeline; this PR adds ScreenshotFormat handling to the same conversion logic.
  • PR #63: Introduces domain-level request and facet infrastructure refactoring; this PR builds upon that infrastructure with screenshot-specific builders and requests.

Poem

🐰 Hops with joy across the form fields,
Building screenshots like a harvest yields,
Pixels dance from HTML and URL with grace,
Fluent builders set the perfect case!
PNG, JPEG, Webp—choices bright,
Quality and dimensions set just right! 🎞️

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Chromium screenshot routes (HTML and URL)' accurately and concisely summarizes the main objective of the pull request: adding two new screenshot API endpoints with their supporting infrastructure.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/screenshot-routes

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 and usage tips.

@Jaben
Copy link
Copy Markdown
Member Author

Jaben commented Mar 29, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
examples/Screenshot/Program.cs (3)

64-69: Response stream should be disposed after use.

Same issue as the HTML screenshot—the response stream from ScreenshotUrlAsync should be disposed.

Proposed fix
-    var response = await sharpClient.ScreenshotUrlAsync(builder);
+    await using var response = await sharpClient.ScreenshotUrlAsync(builder);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/Screenshot/Program.cs` around lines 64 - 69, The response stream
returned by ScreenshotUrlAsync is not disposed; change the code to ensure the
response stream is disposed by using an async using for the response (e.g.,
await using var response = await sharpClient.ScreenshotUrlAsync(builder)) before
creating/writing the file, so the response stream is closed after CopyToAsync
completes; update the block around ScreenshotUrlAsync, the response variable,
and the file write to use async disposal.

44-49: Response stream should be disposed after use.

The Stream returned by ScreenshotHtmlAsync is not disposed after being copied to the file. While the file stream is properly disposed via await using, the response stream will remain open.

Proposed fix
-    var response = await sharpClient.ScreenshotHtmlAsync(builder);
+    await using var response = await sharpClient.ScreenshotHtmlAsync(builder);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/Screenshot/Program.cs` around lines 44 - 49, The response Stream
returned from sharpClient.ScreenshotHtmlAsync(builder) is not disposed; wrap
that stream in a using/await using (e.g., await using var response = await
sharpClient.ScreenshotHtmlAsync(builder)) before calling
response.CopyToAsync(file) so the response stream is disposed after copy,
keeping the existing file creation/await using for the file intact and returning
resultPath as before.

28-70: Consider reusing a single GotenbergSharpClient instance.

Both ScreenshotFromHtml and ScreenshotFromUrl create their own client via CreateClient(options), which instantiates a new HttpClient each time. For a console app example, this works, but it's more idiomatic to reuse a single HttpClient/client instance.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/Screenshot/Program.cs` around lines 28 - 70, Both ScreenshotFromHtml
and ScreenshotFromUrl call CreateClient(options) creating a new
GotenbergSharpClient/HttpClient each time; change the code to create a single
shared GotenbergSharpClient and reuse it instead of instantiating per method —
either instantiate one client once (e.g., a static/shared field) and reference
it inside ScreenshotFromHtml and ScreenshotFromUrl, or refactor both methods to
accept a GotenbergSharpClient parameter; ensure CreateClient(options) is only
called once and the same client instance is used for both ScreenshotHtmlAsync
and ScreenshotUrlAsync.
test/GotenbergSharpClient.Tests/ScreenshotTests.cs (2)

119-133: Consider using async assertions to avoid blocking .Result calls.

The synchronous .Result calls on ReadAsStringAsync() work but can mask exceptions. FluentAssertions supports async operations.

Example using async pattern
-        httpContents.FirstOrDefault(c =>
-            c.Headers.ContentDisposition?.Name == "width")!
-            .ReadAsStringAsync().Result.Should().Be("1920");
+        var widthContent = httpContents.FirstOrDefault(c =>
+            c.Headers.ContentDisposition?.Name == "width")!;
+        (await widthContent.ReadAsStringAsync()).Should().Be("1920");

This would require making the test method async Task.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/GotenbergSharpClient.Tests/ScreenshotTests.cs` around lines 119 - 133,
Convert the test to use async/await: change the test method signature to async
Task and replace blocking .Result calls on ReadAsStringAsync() with await
expressions (call ReadAsStringAsync() with await) when asserting values from
ToHttpContent() results; for each check that currently uses
httpContents.FirstOrDefault(...).ReadAsStringAsync().Result, await
ReadAsStringAsync() into a variable and assert with FluentAssertions (e.g.,
content.Should().Be("...")), keeping references to ToHttpContent() and
ReadAsStringAsync().

184-197: Integration tests require running Gotenberg service.

The CreateAuthenticatedClient method connects to localhost:3000. Consider adding a category or attribute to skip these tests when the service isn't available, or document the CI setup requirements.

#!/bin/bash
# Check if there are test categories or setup documentation for integration tests
rg -n "Category|Explicit|Ignore|Skip" --type=cs test/
fd -i "readme" test/
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/GotenbergSharpClient.Tests/ScreenshotTests.cs` around lines 184 - 197,
Tests that call CreateAuthenticatedClient rely on a running Gotenberg service at
localhost:3000; mark those tests as integration-only so CI/locals without the
service can skip them. Add a test attribute/category (e.g.,
[Trait("Category","Integration")] for xUnit, [Category("Integration")] for
NUnit, or [TestCategory("Integration")] for MSTest) to the test class/methods in
ScreenshotTests that use CreateAuthenticatedClient, or add an [Explicit]/[Skip]
attribute if your framework supports it; alternatively update project test docs
to state that Gotenberg must be running for integration tests (reference
symbols: CreateAuthenticatedClient, GotenbergSharpClientOptions,
AddGotenbergSharpClient).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@README.md`:
- Around line 495-529: Add the missing using for the ScreenshotFormat enum so
the README examples are copy/paste-ready: update the "Required Using Statements"
section to include the namespace that exposes ScreenshotFormat (used by
ScreenshotHtmlRequestBuilder and ScreenshotUrlRequestBuilder), e.g. add the
appropriate using/import line for the value-object namespace that defines
ScreenshotFormat so the snippets compile without adding extra qualifiers.

In `@src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs`:
- Around line 26-33: ScreenshotRequest.ToHttpContent must not include
base.ToHttpContent because that adds PdfOutputOptions (PdfFormat, EnablePdfUa,
Flatten, GenerateTaggedPdf, Metadata) which are rejected by Gotenberg v8
screenshot endpoints; remove the call to base.ToHttpContent and instead return
only the allowed parts (e.g., this.ScreenshotProperties.ToHttpContent(),
this.ConversionBehaviors.ToHttpContent(), this.Config.IfNullEmptyContent()).
Also ensure HtmlConversionBehaviors.UserAgent is excluded for screenshot
requests — either omit it when building ConversionBehaviors content or
filter/clear UserAgent before calling ConversionBehaviors.ToHttpContent() so the
deprecated field is never sent.

---

Nitpick comments:
In `@examples/Screenshot/Program.cs`:
- Around line 64-69: The response stream returned by ScreenshotUrlAsync is not
disposed; change the code to ensure the response stream is disposed by using an
async using for the response (e.g., await using var response = await
sharpClient.ScreenshotUrlAsync(builder)) before creating/writing the file, so
the response stream is closed after CopyToAsync completes; update the block
around ScreenshotUrlAsync, the response variable, and the file write to use
async disposal.
- Around line 44-49: The response Stream returned from
sharpClient.ScreenshotHtmlAsync(builder) is not disposed; wrap that stream in a
using/await using (e.g., await using var response = await
sharpClient.ScreenshotHtmlAsync(builder)) before calling
response.CopyToAsync(file) so the response stream is disposed after copy,
keeping the existing file creation/await using for the file intact and returning
resultPath as before.
- Around line 28-70: Both ScreenshotFromHtml and ScreenshotFromUrl call
CreateClient(options) creating a new GotenbergSharpClient/HttpClient each time;
change the code to create a single shared GotenbergSharpClient and reuse it
instead of instantiating per method — either instantiate one client once (e.g.,
a static/shared field) and reference it inside ScreenshotFromHtml and
ScreenshotFromUrl, or refactor both methods to accept a GotenbergSharpClient
parameter; ensure CreateClient(options) is only called once and the same client
instance is used for both ScreenshotHtmlAsync and ScreenshotUrlAsync.

In `@test/GotenbergSharpClient.Tests/ScreenshotTests.cs`:
- Around line 119-133: Convert the test to use async/await: change the test
method signature to async Task and replace blocking .Result calls on
ReadAsStringAsync() with await expressions (call ReadAsStringAsync() with await)
when asserting values from ToHttpContent() results; for each check that
currently uses httpContents.FirstOrDefault(...).ReadAsStringAsync().Result,
await ReadAsStringAsync() into a variable and assert with FluentAssertions
(e.g., content.Should().Be("...")), keeping references to ToHttpContent() and
ReadAsStringAsync().
- Around line 184-197: Tests that call CreateAuthenticatedClient rely on a
running Gotenberg service at localhost:3000; mark those tests as
integration-only so CI/locals without the service can skip them. Add a test
attribute/category (e.g., [Trait("Category","Integration")] for xUnit,
[Category("Integration")] for NUnit, or [TestCategory("Integration")] for
MSTest) to the test class/methods in ScreenshotTests that use
CreateAuthenticatedClient, or add an [Explicit]/[Skip] attribute if your
framework supports it; alternatively update project test docs to state that
Gotenberg must be running for integration tests (reference symbols:
CreateAuthenticatedClient, GotenbergSharpClientOptions,
AddGotenbergSharpClient).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 5bfebafc-be3d-4ce2-9544-0bc006a4ed5f

📥 Commits

Reviewing files that changed from the base of the PR and between 09b6c02 and 0abe5e5.

📒 Files selected for processing (18)
  • README.md
  • examples/Screenshot/Program.cs
  • examples/Screenshot/Screenshot.csproj
  • src/Gotenberg.Sharp.Api.Client/Domain/Builders/BaseScreenshotBuilder.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Builders/Faceted/ScreenshotPropertyBuilder.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Builders/ScreenshotHtmlRequestBuilder.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Builders/ScreenshotUrlRequestBuilder.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/Facets/FacetBase.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/Facets/ScreenshotProperties.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotHtmlRequest.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotUrlRequest.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/ValueObjects/CompressionQuality.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/ValueObjects/ScreenDimension.cs
  • src/Gotenberg.Sharp.Api.Client/Domain/ValueObjects/ScreenshotFormat.cs
  • src/Gotenberg.Sharp.Api.Client/GotenbergSharpClient.cs
  • src/Gotenberg.Sharp.Api.Client/Infrastructure/Constants.cs
  • test/GotenbergSharpClient.Tests/ScreenshotTests.cs

Comment on lines +26 to +33
public HtmlConversionBehaviors ConversionBehaviors { get; set; } = new();

protected override IEnumerable<HttpContent> ToHttpContent()
{
return this.ScreenshotProperties.ToHttpContent()
.Concat(this.ConversionBehaviors.ToHttpContent())
.Concat(this.Config.IfNullEmptyContent())
.Concat(base.ToHttpContent());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether screenshot builders/requests can set or emit PDF/output-specific options.
fd -i 'BaseScreenshotBuilder.cs|BuildRequestBase.cs|ScreenshotRequest.cs|*Screenshot*Builder*.cs|*Screenshot*Request*.cs'
rg -n --iglob '*Screenshot*Builder*.cs' --iglob '*Screenshot*Request*.cs' --iglob '*BuildRequestBase.cs' 'PdfOutput|SetPdfOutputOptions|HtmlConversionBehaviors|ConversionBehaviors'

Repository: ChangemakerStudios/GotenbergSharpApiClient

Length of output: 1913


🌐 Web query:

For Gotenberg v8 Chromium screenshot endpoints (/forms/chromium/screenshot/url and /forms/chromium/screenshot/html), which multipart form fields are officially supported? Are waitDelay, waitForExpression, userAgent, extraHttpHeaders, cookies, failOnConsoleExceptions, emulatedMediaType, skipNetworkIdleEvent, pdfa, pdfua, flatten, generateTaggedPdf, and metadata accepted?

💡 Result:

For Gotenberg v8 Chromium screenshot endpoints (/forms/chromium/screenshot/url and /forms/chromium/screenshot/html), the officially supported multipart form fields are those shared across Chromium routes, particularly the rendering and HTTP/networking options documented for screenshot-html and markdown, and referenced as available for screenshot/url. Core viewport fields (explicitly listed): - width (default 800) - height (default 600) - clip (default false) Image format fields: - format (png, jpeg, webp; default png) - quality (0-100 for jpeg; default 100) - omitBackground (default false) - optimizeForSpeed (default false) From navigation/rendering sections (explicitly mentioned or listed in docs for screenshots): - waitDelay - waitForExpression - emulatedMediaType (likely as emulatedMediaFeatures json) - extraHttpHeaders (as HTTP Headers) - cookies (json array) - failOnConsoleExceptions (default false) - skipNetworkIdleEvent PDF-specific fields like pdfa, pdfua, flatten, generateTaggedPdf are NOT supported on screenshot endpoints (they produce images, not PDFs). userAgent is deprecated in v8 and not supported. metadata is supported for image XMP metadata via PDF Engines module. For /screenshot/url, requires 'url' form field (string, required). For /screenshot/html, requires 'files' with index.html (and optional assets). These endpoints function similarly to their PDF counterparts but output images. Evidence from official docs confirms these fields under "Rendering Behavior" (Viewport, Image Format, JavaScript & Dynamic Content with wait options, Emulated Media Features, Wait Delay/Expression/Selector) and "HTTP & Networking" (Cookies, HTTP Headers, etc.). v8 release notes state screenshot routes have "wait before rendering, emulated media type, custom HTTP headers, invalid HTTP status codes, console exceptions". Troubleshooting mentions skipNetworkIdleEvent for screenshots. Deprecated userAgent not available.

Citations:


🏁 Script executed:

fd -type f -name "PdfOutputOptions.cs" -o -name "HtmlConversionBehaviors.cs"

Repository: ChangemakerStudios/GotenbergSharpApiClient

Length of output: 256


🏁 Script executed:

rg -A 30 "class PdfOutputOptions" --type cs

Repository: ChangemakerStudios/GotenbergSharpApiClient

Length of output: 7096


🏁 Script executed:

rg -A 30 "class HtmlConversionBehaviors" --type cs

Repository: ChangemakerStudios/GotenbergSharpApiClient

Length of output: 3977


🏁 Script executed:

cat src/Gotenberg.Sharp.Api.Client/Domain/Requests/Facets/HtmlConversionBehaviors.cs

Repository: ChangemakerStudios/GotenbergSharpApiClient

Length of output: 3919


🏁 Script executed:

cat src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs

Repository: ChangemakerStudios/GotenbergSharpApiClient

Length of output: 1500


Base class's PdfOutputOptions fields leak into screenshot requests, causing 4xx errors.

Line 33 calls base.ToHttpContent(), which includes PdfOutputOptions fields (PdfFormat, EnablePdfUa, Flatten, GenerateTaggedPdf, Metadata). Gotenberg v8 screenshot endpoints reject these PDF-only options. If a user configures any PdfOutputOptions field via the builder, the screenshot request will fail with 4xx.

Additionally, HtmlConversionBehaviors.UserAgent is marked [Obsolete("Deprecated in Gotenberg v8+")] and is not supported by screenshot endpoints.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Gotenberg.Sharp.Api.Client/Domain/Requests/ScreenshotRequest.cs` around
lines 26 - 33, ScreenshotRequest.ToHttpContent must not include
base.ToHttpContent because that adds PdfOutputOptions (PdfFormat, EnablePdfUa,
Flatten, GenerateTaggedPdf, Metadata) which are rejected by Gotenberg v8
screenshot endpoints; remove the call to base.ToHttpContent and instead return
only the allowed parts (e.g., this.ScreenshotProperties.ToHttpContent(),
this.ConversionBehaviors.ToHttpContent(), this.Config.IfNullEmptyContent()).
Also ensure HtmlConversionBehaviors.UserAgent is excluded for screenshot
requests — either omit it when building ConversionBehaviors content or
filter/clear UserAgent before calling ConversionBehaviors.ToHttpContent() so the
deprecated field is never sent.

Jaben added 3 commits March 28, 2026 22:19
Resolve conflicts in FacetBase.cs (keep both screenshot and chromium
type serialization cases), GotenbergSharpClient.cs (keep both screenshot
and PDF engine methods), and README.md (keep screenshot sections).
@Jaben Jaben merged commit 24dfe86 into develop Mar 29, 2026
3 checks passed
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.

1 participant