Add browse pdf command to save pages as PDF#1910
Conversation
Uses CDP Page.printToPDF to generate PDFs with configurable paper format (letter, legal, a4, a3), orientation, scale, and background printing. Saves to file when path given, returns base64 otherwise. Usage: browse pdf ./page.pdf # save as PDF browse pdf ./page.pdf --landscape # landscape orientation browse pdf ./page.pdf --format a4 # A4 paper size browse pdf # returns base64 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 57ab187 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types 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 |
There was a problem hiding this comment.
3 issues found across 2 files
Confidence score: 4/5
- This PR is likely safe to merge, with mostly input-validation and release-process issues rather than clear runtime breakage (top severity is 5/10).
- In
packages/cli/src/index.ts,--scaleis not validated, so invalid values silently falling back in daemon mode can produce unexpected output and make misconfiguration harder to detect. - In
packages/cli/src/index.ts, unknown--formatvalues are coerced toletterinstead of being rejected, and.changeset/add-pdf-command.mdtargets an ignored package so the release note/version bump will be a no-op. - Pay close attention to
packages/cli/src/index.ts,.changeset/add-pdf-command.md- tighten CLI argument validation and confirm release metadata targets a publishable package.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name=".changeset/add-pdf-command.md">
<violation number="1" location=".changeset/add-pdf-command.md:2">
P2: This changeset references a package that is configured as ignored, so the release note/version bump will be a no-op.</violation>
</file>
<file name="packages/cli/src/index.ts">
<violation number="1" location="packages/cli/src/index.ts:1603">
P2: Unknown `--format` values are silently converted to letter instead of being rejected.</violation>
<violation number="2" location="packages/cli/src/index.ts:2819">
P2: `--scale` is not validated, so invalid values are silently coerced to the default scale in daemon mode.</violation>
</file>
Architecture diagram
sequenceDiagram
participant User
participant CLI as CLI (Commander)
participant Exec as Command Executor
participant Browser as Browser (CDP Session)
participant FS as Local Filesystem
User->>CLI: browse pdf [path] --format a4 --landscape
CLI->>Exec: NEW: runCommand("pdf", opts)
Note over Exec: Maps format (a4/letter) to<br/>paperWidth & paperHeight
Exec->>Browser: NEW: Page.printToPDF (CDP)
Note right of Browser: landscape, scale, printBackground,<br/>preferCSSPageSize: true
Browser-->>Exec: { data: base64_string }
alt path provided
Exec->>FS: NEW: writeFile(path, Buffer from base64)
Exec-->>CLI: { saved: path }
else no path
Exec-->>CLI: { base64: string }
end
CLI-->>User: Output JSON or status message
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| @@ -0,0 +1,5 @@ | |||
| --- | |||
| "@browserbasehq/browse-cli": minor | |||
There was a problem hiding this comment.
P2: This changeset references a package that is configured as ignored, so the release note/version bump will be a no-op.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At .changeset/add-pdf-command.md, line 2:
<comment>This changeset references a package that is configured as ignored, so the release note/version bump will be a no-op.</comment>
<file context>
@@ -0,0 +1,5 @@
+---
+"@browserbasehq/browse-cli": minor
+---
+
</file context>
Reject invalid scale values (must be 0.1-2) and unknown format values (must be letter, legal, a4, or a3) with clear error messages instead of silently falling back. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/cli/src/index.ts">
<violation number="1" location="packages/cli/src/index.ts:2814">
P2: Scale validation is too permissive because `parseFloat` accepts invalid trailing characters (e.g. `1abc`). Use strict numeric parsing so malformed `--scale` values are rejected.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| .action(async (filePath: string | undefined, cmdOpts) => { | ||
| const opts = program.opts<GlobalOpts>(); | ||
| try { | ||
| const scale = parseFloat(cmdOpts.scale); |
There was a problem hiding this comment.
P2: Scale validation is too permissive because parseFloat accepts invalid trailing characters (e.g. 1abc). Use strict numeric parsing so malformed --scale values are rejected.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/cli/src/index.ts, line 2814:
<comment>Scale validation is too permissive because `parseFloat` accepts invalid trailing characters (e.g. `1abc`). Use strict numeric parsing so malformed `--scale` values are rejected.</comment>
<file context>
@@ -2811,12 +2811,24 @@ program
.action(async (filePath: string | undefined, cmdOpts) => {
const opts = program.opts<GlobalOpts>();
try {
+ const scale = parseFloat(cmdOpts.scale);
+ if (isNaN(scale) || scale < 0.1 || scale > 2) {
+ console.error("Error: --scale must be a number between 0.1 and 2");
</file context>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
browse pdf [path]command using CDPPage.printToPDF--landscape,--format(letter/legal/a4/a3),--scale,--no-backgroundUsage
Test results
pdf /tmp/test.pdfpdf --landscape --format a4pdf(base64 output)🤖 Generated with Claude Code