Skip to content

Feature: PDF generation support for extension mode #44

@parkerhancock

Description

@parkerhancock

Feature Request

Add PDF generation support (page.pdf()) for extension mode. Currently, Playwright's page.pdf() works in standalone mode but fails in extension mode because the Chrome extension's CDP connection doesn't handle Page.printToPDF responses correctly (the base64-encoded PDF data is too large for the WebSocket message handling).

Use Case

Automating document workflows that need to save pages as PDFs:

  • Archiving web pages
  • Generating reports from dashboards
  • Saving receipts/invoices

Proposed Solution

Intercept Page.printToPDF commands in the relay server:

  1. Forward the command to the extension
  2. Save the PDF data to a temp file (~/.dev-browser/pdfs/{id}.pdf)
  3. Return a download URL instead of raw base64 data
  4. Auto-cleanup temp files after 5 minutes
// Usage remains the same
const pdfBuffer = await page.pdf({ format: 'A4' });

// Relay intercepts and provides file-based transfer for large PDFs

Working Implementation

I have this working in my fork:

Features:

  • Intercepts Page.printToPDF in relay
  • Saves to ~/.dev-browser/pdfs/ with UUID filename
  • Adds /pdf/:id endpoint for downloads
  • Auto-cleanup after 5 minutes
  • Includes test script at scripts/test-pdf.ts

Happy to submit a PR if there's interest.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions