import "dotenv/config"; import path from "node:path"; import { spawn } from "node:child_process"; import { existsSync } from "node:fs"; // Log in using ordinary Chrome before Playwright opens this dedicated profile. const profile = path.resolve(process.env.CHATGPT_PROFILE_DIR || ".data/chatgpt-profile"); const chrome = process.env.CHATGPT_CHROME_BIN || (process.platform === "win32" ? ["C:\\Program Files\\Google\\Chrome\\Application\\chrome.exe", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"].find(existsSync) : "google-chrome"); if (!chrome) throw new Error("Chrome executable not found; set CHATGPT_CHROME_BIN"); console.log("Log in and finish verification in this dedicated Chrome window. Confirm the chat composer is visible, then close Chrome before restarting the worker."); const child = spawn(chrome, [`--user-data-dir=${profile}`, "--no-first-run", "https://chatgpt.com/"], { stdio: "inherit", windowsHide: false }); await new Promise((resolve, reject) => { child.once("error", reject); child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`Chrome exited with code ${code}`))); });