This commit is contained in:
949036910@qq.com
2026-05-29 00:42:58 +08:00
parent e6dec231ea
commit 22f24a565c
2 changed files with 36 additions and 8 deletions

View File

@@ -73,7 +73,11 @@ class DouyinBrowserManager {
constructor() {
this.browser = null;
this.isInitializing = false;
this.userDataPath = getRuntimeDataPath("browser-data", "douyin");
// 下载链路使用独立临时 profile避免与其他流程/遗留进程抢占同一目录锁。
this.userDataPath = getRuntimeDataPath(
"temp",
`douyin-pipeline-${process.pid}-${Date.now()}`
);
}
static getInstance() {
@@ -180,8 +184,10 @@ class DouyinBrowserManager {
const page = await this.browser.newPage();
await page.setUserAgent(DEFAULT_USER_AGENT);
await page.evaluateOnNewDocument(STEALTH_INIT_SCRIPT);
page.setDefaultNavigationTimeout(60000);
page.setDefaultTimeout(60000);
const pageTimeoutMs =
Number(process.env.AICLIENT_DOUYIN_PAGE_TIMEOUT_MS) || 90_000;
page.setDefaultNavigationTimeout(pageTimeoutMs);
page.setDefaultTimeout(pageTimeoutMs);
return page;
}
@@ -192,6 +198,16 @@ class DouyinBrowserManager {
this.browser = null;
console.log("浏览器管理器已关闭");
}
if (
this.userDataPath &&
this.userDataPath.includes(`${path.sep}temp${path.sep}douyin-pipeline-`)
) {
try {
fs.rmSync(this.userDataPath, { recursive: true, force: true });
} catch {
/* ignore temp dir cleanup errors */
}
}
} catch (error) {
console.error("关闭浏览器管理器失败:", error);
}