diff --git a/lib/routes/nytimes/index.ts b/lib/routes/nytimes/index.ts index 7200c90e1aeaf3..5c0291c9393d9e 100644 --- a/lib/routes/nytimes/index.ts +++ b/lib/routes/nytimes/index.ts @@ -152,7 +152,7 @@ async function handler(ctx) { }) ); - browser.close(); + await browser.close(); return { title, diff --git a/lib/routes/nytimes/utils.ts b/lib/routes/nytimes/utils.ts index 02b05b1fdd3de9..83409e8ddcdf51 100644 --- a/lib/routes/nytimes/utils.ts +++ b/lib/routes/nytimes/utils.ts @@ -1,6 +1,7 @@ import cache from '@/utils/cache'; import { load } from 'cheerio'; import { parseDate } from '@/utils/parse-date'; +import { Browser } from 'puppeteer'; const ProcessImage = ($, e) => { const photo = $(e).find('figure').find('picture').find('img'); @@ -14,7 +15,7 @@ const ProcessImage = ($, e) => { return cover; }; -const PuppeterGetter = async (ctx, browser, link) => { +const PuppeterGetter = async (ctx, browser: Browser, link) => { const result = await cache.tryGet(`nyt: ${link}`, async () => { const page = await browser.newPage(); await page.setRequestInterception(true); @@ -28,7 +29,8 @@ const PuppeterGetter = async (ctx, browser, link) => { }); await page.goto(link); await page.waitForSelector('[data-testid=optimistic-truncator-message]', { hidden: true, timeout: 0 }); - const response = await page.evaluate(() => document.querySelector('body').innerHTML); + const response = await page.evaluate(() => document.querySelector('body')?.innerHTML); + await page.close(); return response; }); return result; diff --git a/lib/utils/puppeteer.ts b/lib/utils/puppeteer.ts index 24c36163244490..3e83e52905b5aa 100644 --- a/lib/utils/puppeteer.ts +++ b/lib/utils/puppeteer.ts @@ -9,8 +9,10 @@ import StealthPlugin from 'puppeteer-extra-plugin-stealth'; const options = { args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-infobars', '--window-position=0,0', '--ignore-certificate-errors', '--ignore-certificate-errors-spki-list', `--user-agent=${config.ua}`], - headless: true, + // headless: true, ignoreHTTPSErrors: true, + headless: false, + devtools: true, }; /** @@ -54,9 +56,9 @@ const outPuppeteer = async ( } : options )); - setTimeout(() => { - browser.close(); - }, 30000); + // setTimeout(() => { + // browser.close(); + // }, 30000); return browser; };