Morning improvements

This commit is contained in:
Andras Schmelczer 2026-03-17 13:29:03 +00:00
parent 3e9fba5303
commit 53fff3efaa
41 changed files with 2438 additions and 637 deletions

View file

@ -226,11 +226,22 @@ export async function initialize(appUrl: string): Promise<void> {
await warmPool();
}
export async function takeScreenshot(url: string): Promise<Buffer> {
export async function takeScreenshot(url: string, authHeader?: string): Promise<Buffer> {
const page = await acquirePage();
const t0 = performance.now();
try {
// Inject Authorization header on API requests so the headless browser
// is authenticated (required for licensed users outside the free zone).
// Page-level routes take precedence over the context-level cache route,
// so only /api/ requests are affected — static assets still use the cache.
if (authHeader) {
await page.route('**/api/**', async (route) => {
const headers = { ...route.request().headers(), authorization: authHeader };
await route.continue({ headers });
});
}
const response = await page.goto(url, {
waitUntil: 'domcontentloaded',
timeout: NAVIGATION_TIMEOUT,
@ -265,6 +276,11 @@ export async function takeScreenshot(url: string): Promise<Buffer> {
return Buffer.from(screenshot);
} finally {
// Remove page-level auth route before returning page to pool
// so the next screenshot doesn't inherit stale credentials
if (authHeader) {
await page.unrouteAll({ behavior: 'wait' }).catch(() => {});
}
await releasePage(page);
}
}