Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
dzx-dzx committed Oct 25, 2024
1 parent 3715992 commit 97b5439
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/routes/nytimes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ async function handler(ctx) {
})
);

browser.close();
await browser.close();

return {
title,
Expand Down
6 changes: 4 additions & 2 deletions lib/routes/nytimes/utils.ts
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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);
Expand All @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions lib/utils/puppeteer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

/**
Expand Down Expand Up @@ -54,9 +56,9 @@ const outPuppeteer = async (
}
: options
));
setTimeout(() => {
browser.close();
}, 30000);
// setTimeout(() => {
// browser.close();
// }, 30000);

return browser;
};
Expand Down

0 comments on commit 97b5439

Please sign in to comment.