Fix unfurler navigation race condition

This commit is contained in:
Mononaut 2022-08-30 18:19:43 +00:00
parent c289f821e4
commit 313d8d6a53
No known key found for this signature in database
GPG Key ID: 61B952CAF4838F94

View File

@ -97,15 +97,20 @@ class Server {
throw new Error('failed to access open graph service');
}
}
// wait for navigation to complete
await page.waitForFunction(
(path) => window.location.pathname.includes(path),
{},
path
);
// wait for preview component to initialize
await page.waitForSelector('meta[property="og:preview:loading"]', { timeout: config.PUPPETEER.RENDER_TIMEOUT || 3000 })
const waitForReady = await page.$('meta[property="og:preview:loading"]');
let success = true;
if (waitForReady != null) {
success = await Promise.race([
page.waitForSelector('meta[property="og:preview:ready"]', { timeout: config.PUPPETEER.RENDER_TIMEOUT || 3000 }).then(() => true),
page.waitForSelector('meta[property="og:preview:fail"]', { timeout: config.PUPPETEER.RENDER_TIMEOUT || 3000 }).then(() => false)
])
}
success = await Promise.race([
page.waitForSelector('meta[property="og:preview:ready"]', { timeout: config.PUPPETEER.RENDER_TIMEOUT || 3000 }).then(() => true),
page.waitForSelector('meta[property="og:preview:fail"]', { timeout: config.PUPPETEER.RENDER_TIMEOUT || 3000 }).then(() => false)
])
if (success) {
const screenshot = await page.screenshot();
return screenshot;