Skip to content

Commit 4d6cbf0

Browse files
committed
debug: temporary diagnostics for blank OG image investigation (to be reverted)
1 parent 3ed9da3 commit 4d6cbf0

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

pages/api/preview/[ranges].ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,28 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
7373

7474
const renderURL = `${endpoint}/_render/${ranges}`;
7575
console.log(renderURL);
76+
const consoleMessages: string[] = [];
77+
page.on('console', (msg) => consoleMessages.push(msg.text()));
78+
page.on('pageerror', (err) => consoleMessages.push(`pageerror: ${err}`));
7679
await page.goto(renderURL);
7780

7881
await page.waitForFunction('!!window._scrolled', {
7982
timeout: 1000,
8083
});
8184

85+
const diag = await page.evaluate(() => {
86+
const body = document.body;
87+
const rect = body.getBoundingClientRect();
88+
return {
89+
bodyTextLength: body.innerText?.length ?? -1,
90+
bodyHTMLLength: body.innerHTML?.length ?? -1,
91+
scrollY: window.scrollY,
92+
bodyRect: { width: rect.width, height: rect.height },
93+
bodyBg: getComputedStyle(body).backgroundColor,
94+
fontsReady: document.fonts.status,
95+
};
96+
});
97+
8298
const result = await page.screenshot({
8399
type: 'png',
84100
encoding: 'binary',
@@ -88,8 +104,12 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
88104
await browser.close();
89105

90106
res.setHeader('Content-Type', 'image/png');
91-
res.setHeader('Cache-Control', `max-age=${MAX_AGE}, public`);
92-
res.setHeader('Cache-Control', `s-maxage=${MAX_AGE}`);
107+
res.setHeader('Cache-Control', 'no-store');
108+
res.setHeader('X-Debug-Diag', JSON.stringify(diag));
109+
res.setHeader(
110+
'X-Debug-Console',
111+
JSON.stringify(consoleMessages.slice(0, 20))
112+
);
93113
res.send(result);
94114
};
95115

0 commit comments

Comments
 (0)