Files
browser-helper/start-browser.ts
2025-12-25 15:29:55 +08:00

35 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { chromium } from 'playwright';
import { spawn } from 'node:child_process';
import path from 'node:path';
export const main = async () => {
// Chrome 路径和配置
const executablePath = 'C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe';
// 使用独立的用户数据目录,避免与 Chrome 冲突
const userDataDir = path.join(process.cwd(), 'browser-context');
const debugPort = 9223;
console.log('启动 Chrome...');
console.log(`端口: ${debugPort}`);
console.log(`用户数据目录: ${userDataDir}`);
// console.log('注意:需要手动登录账号和安装插件');
// 启动 Chrome带远程调试端口
const chromeProcess = spawn(executablePath, [
`--remote-debugging-port=${debugPort}`,
`--user-data-dir=${userDataDir}`,
], {
detached: false,
stdio: 'inherit',
});
chromeProcess.on('error', (err) => {
console.error('Chrome 启动失败:', err);
});
chromeProcess.on('exit', (code, signal) => {
console.log(`Chrome 进程退出,代码: ${code}, 信号: ${signal}`);
});
}
main();