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.
This commit is contained in:
Lucas Smith
2025-08-02 00:39:48 +10:00
committed by GitHub
parent 20198b5b6c
commit 1e2388519c

View File

@ -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',
});