Skip to content

Customize captures with before callbacks and driver context - #8

Open
stevebauman wants to merge 5 commits into
masterfrom
feature/before-capture
Open

stevebauman wants to merge 5 commits into
masterfrom
feature/before-capture

Conversation

@stevebauman

@stevebauman stevebauman commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

I've added before() so you can customize a capture without creating a custom driver. Callbacks receive a driver-specific context implementing Contracts\CaptureContext. Its driver() method returns the actual driver instance, so you can use match or instanceof when the customization depends on the driver.

The Chrome context exposes page() for the loaded browser page before image bounds are measured or PDF preparation begins. The Gotenberg context exposes request() for the prepared request before it's sent, with a set() method for multipart fields and access to its URL and Guzzle options.

Custom drivers can implement the same context contract and expose their own resources. The hook is available on source, image, and PDF builders. Multiple callbacks run in registration order, output builders retain independent callback lists, and callback exceptions propagate through the existing cleanup.

Validated with 319 unit and feature tests, real Chrome capture tests, and Pint. Gotenberg request customization is verified using Guzzle's mock handler; its live service tests remain for CI.

This touches the Chrome capture construction also changed in #6, so those changes may need reconciling depending on merge order.

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