Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .github/scripts/baidu-tongji.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function detectLanguageFromHtml($) {
// 获取页面标题和语言
async function getPageTitleAndLang(url) {
let browser;
let page;

try {
browser = await puppeteer.launch({
Expand All @@ -167,7 +168,7 @@ async function getPageTitleAndLang(url) {
],
});

const page = await browser.newPage();
page = await browser.newPage();

await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36');

Expand Down Expand Up @@ -247,6 +248,13 @@ async function getPageTitleAndLang(url) {
title: url.split("/").pop() || url,
lang,
};
} finally {
try {
if (page) await page.close();
} catch (_) {}
try {
if (browser) await browser.close();
} catch (_) {}
}
}

Expand Down Expand Up @@ -341,6 +349,7 @@ async function main() {

// 保存到 JSON(写入 contents/static/json)
saveToJsonFile(updatedData, "static/json/baidu_tongji_data.json");
process.exit(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding process.exit(0) at line 352 might force the script to exit before any pending asynchronous operations complete. Since Node.js will exit automatically when the event loop is empty, this explicit exit call might not be necessary and could potentially cause issues with resource cleanup or logging.

} catch (error) {
process.exit(1);
}
Expand Down
Loading