From 1e2388519c58d52094214a6f7ecb2164dc854b22 Mon Sep 17 00:00:00 2001 From: Lucas Smith Date: Sat, 2 Aug 2025 00:39:48 +1000 Subject: [PATCH] hotfix: certificate pdfs are blank when using browserless (#1935) Certificates have suddenly become blank when using browserless and Chrome CDP. This change introduces a workaround that involves reloading the certificate pdf. Which is hacky but seems to work for now, a better solution should be found in the future. --- .../server-only/htmltopdf/get-certificate-pdf.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/lib/server-only/htmltopdf/get-certificate-pdf.ts b/packages/lib/server-only/htmltopdf/get-certificate-pdf.ts index 1d7a284ea..09bf07232 100644 --- a/packages/lib/server-only/htmltopdf/get-certificate-pdf.ts +++ b/packages/lib/server-only/htmltopdf/get-certificate-pdf.ts @@ -46,7 +46,7 @@ export const getCertificatePdf = async ({ documentId, language }: GetCertificate await page.context().addCookies([ { - name: 'language', + name: 'lang', value: lang, url: NEXT_PUBLIC_WEBAPP_URL(), }, @@ -57,6 +57,19 @@ export const getCertificatePdf = async ({ documentId, language }: GetCertificate timeout: 10_000, }); + // !: This is a workaround to ensure the page is loaded correctly. + // !: It's not clear why but suddenly browserless cdp connections would + // !: cause the page to render blank until a reload is performed. + await page.reload({ + waitUntil: 'networkidle', + timeout: 10_000, + }); + + await page.waitForSelector('h1', { + state: 'visible', + timeout: 10_000, + }); + const result = await page.pdf({ format: 'A4', });