Skip to content

feat(page): add page.pdf() passthrough to CDP Page.printToPDF - #2819

Open
nagalikith wants to merge 2 commits into
browserbase:mainfrom
nagalikith:feat/page-pdf
Open

feat(page): add page.pdf() passthrough to CDP Page.printToPDF#2819
nagalikith wants to merge 2 commits into
browserbase:mainfrom
nagalikith:feat/page-pdf

Conversation

@nagalikith

Copy link
Copy Markdown

first slice of #2744 — adds page.pdf() as a thin passthrough to CDP
Page.printToPDF, mirroring playwright's options (format, margins,
scale, header/footer templates, printBackground, preferCssPageSize,
pageRanges, tagged/outline, omitBackground, timeout).

headless chrome only (CDP limitation). python/go get regenerated types
for now, sdk wrappers can come later.

tests: unit + integration against local headless chrome 152

Add a Playwright-compatible pdf() across the protocol, extension, and
TypeScript SDK: paper format/size with px/in/cm/mm lengths, margins,
scale, header/footer templates, printBackground, preferCssPageSize,
pageRanges, tagged/outline, omitBackground, and timeout.

- protocol: register page.pdf schemas in the wire registry; spell the
  CSS-page-size option preferCssPageSize so the name survives the
  automatic camelCase <-> snake_case round-trip
- extension: render via Page.printToPDF on the main-frame session with
  a cached Browser.getVersion headless probe (new headless reports
  plain Chrome in product, so check userAgent too)
- sdk-ts: Page.pdf() returns bytes or writes options.path in Node;
  honor options.timeout for RPC response deadlines
- sdk-go: add PdfLength scalar union so generated models compile;
  regenerate Python/Go protocol types
- tests: Playwright->CDP mapping units, RPC routing case, and headless
  Chrome integration coverage
- format wins entirely over width/height (crPdf.ts semantics); without
  a format, letter defaults are overridden per axis
- replicate Playwright's falsy-zero coercion for paper dimensions
- replace the regex with suffix-based parsing accepting .5in / 1e2px /
  "+3cm" / "10 PX" / unitless pixels; non-CSS units like pt stay errors
- lowercase options.format client-side so "A4" works past the
  lowercase-only wire enum; export PdfOptions from the package root
@changeset-bot

changeset-bot Bot commented Aug 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 891fec6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 12 packages
Name Type
@browserbasehq/stagehand-protocol Minor
@browserbasehq/stagehand-python Patch
@browserbasehq/stagehand-extension Patch
@browserbasehq/stagehand-go Patch
@browserbasehq/stagehand Minor
@browserbasehq/stagehand-integrations Patch
@browserbasehq/stagehand-integrations-example-eve-facade Patch
@browserbasehq/stagehand-integrations-example-pi-facade Patch
@browserbasehq/stagehand-integrations-example-claude-code-facade Patch
@browserbasehq/stagehand-integrations-example-codex-facade Patch
@browserbasehq/stagehand-integrations-example-mastra-facade Patch
@browserbasehq/stagehand-integrations-example-vercel-ai-facade Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@github-actions

Copy link
Copy Markdown
Contributor

This PR is from an external contributor and must be approved by a stagehand team member with write access before CI can run.
Approving the latest commit mirrors it into an internal PR owned by the approver.
If new commits are pushed later, the internal PR stays open but is marked stale until someone approves the latest external commit and refreshes it.

@github-actions github-actions Bot added external-contributor Tracks PRs mirrored from external contributor forks. external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. labels Aug 25, 2026
@nagalikith

Copy link
Copy Markdown
Author

@shrey150 , could you review this?

Addresses a part of: #2744

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor:awaiting-approval Waiting for a stagehand team member to approve the latest external commit. external-contributor Tracks PRs mirrored from external contributor forks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant