From 9dc45d9db334d636f74c2f0c0c0a23c2b9f5161f Mon Sep 17 00:00:00 2001 From: Mononaut Date: Tue, 30 Aug 2022 21:53:52 +0000 Subject: [PATCH] hotfix to rollback broken unfurler --- unfurler/src/index.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/unfurler/src/index.ts b/unfurler/src/index.ts index 305a0a4c2..ff5e6963a 100644 --- a/unfurler/src/index.ts +++ b/unfurler/src/index.ts @@ -99,20 +99,15 @@ 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; - 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 (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) + ]) + } if (success) { const screenshot = await page.screenshot(); return screenshot;