Skip to content

Websocket error: SessionID: {uuid} [object ErrorEvent] #125

@zalmanlew

Description

@zalmanlew

What were you trying to do?

await pdfDoc.save();

within a Cloudflare Worker

How did you attempt to do it?

  1. Load a PDF Buffer (generated from puppeteer)
  2. Add some properties
  3. Encrypt the PDF (password protect edits)
  4. Save the PDF

What actually happened?

I added a bunch of debug logs - it's returning this error on await pdfDoc.save();

Websocket error: SessionID: {uuid} [object ErrorEvent]

Despite the error, the application continues as the error is only logged and not thrown.

What did you expect to happen?

No error logged

How can we reproduce the issue?

In a Cloudflare worker (or other V8 Isolate)

const html = '<!DOCTYPE html><html><body><h1>Hello, world!</h1></body></html>';

const browser = await puppeteer.launch(env.BROWSER);
const page = await browser.newPage();
await page.setContent(html);
const pdfBuffer = await page.pdf({ printBackground: true, margin: { top: 0, right: 0, bottom: 0, left: 0 } });
await browser.close();

const pdfDoc = await PDFDocument.load(pdfBuffer);

pdfDoc.setProducer("foo");
pdfDoc.setCreator("bar");
pdfDoc.encrypt({
  ownerPassword: "somerandomstring",
  userPassword: "", // empty string = allow anyone to view
  permissions: {
    printing: "highResolution",
    modifying: false, // disallow edits
    copying: true, // allow copying text
    annotating: false,
    fillingForms: false,
    contentAccessibility: false,
    documentAssembly: false,
  },
});

const finalPdf = await pdfDoc.save();

Version

2.5.3

What environment are you running pdf-lib in?

Other

Checklist

  • My report includes a Short, Self Contained, Correct (Compilable) Example.
  • I have attached all PDFs, images, and other files needed to run my SSCCE.

Additional Notes

Not sure where the error is coming from. It doesn't throw but it is logged.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions