Use dedicated Chrome profile for image automation

This commit is contained in:
Loma Bot Ops
2026-11-23 22:51:57 +07:00
parent ac4d3bf7a5
commit 7d6f42b964
3 changed files with 21 additions and 12 deletions
+7 -4
View File
@@ -75,16 +75,19 @@ async function image(body, dir) {
if (await page.getByTestId("login-button").isVisible() || await login.isVisible()) {
throw new Error("ChatGPT login required: run node scripts/chatgpt-login.mjs");
}
const editor = page.locator('#prompt-textarea');
await editor.waitFor({ state: "visible", timeout: 30_000 }).catch(() => {
const editor = page.locator('#prompt-textarea, [role="textbox"][contenteditable="true"]').first();
await editor.waitFor({ state: "visible", timeout: 45_000 }).catch(() => {
throw new Error("ChatGPT composer unavailable: verify the dedicated browser profile");
});
await editor.fill(`Create an image now. Return the generated image, not a prompt. Aspect ratio: ${body.size === "landscape" ? "3:2" : "1:1"}.\n${body.prompt}`);
await editor.press("Enter");
const downloadButton = page.locator('[data-message-author-role="assistant"]').getByRole("button", { name: /download|ดาวน์โหลด/i }).last();
await downloadButton.waitFor({ state: "visible", timeout: 200_000 }).catch(() => {
const generatedImage = page.getByTestId("generated-image-preview").last();
await generatedImage.waitFor({ state: "visible", timeout: 200_000 }).catch(() => {
throw new Error("ChatGPT image generation or download unavailable");
});
await generatedImage.click();
const downloadButton = page.getByRole("button", { name: /^(download|ดาวน์โหลด)$/i }).last();
await downloadButton.waitFor({ state: "visible", timeout: 20_000 });
const downloadEvent = page.waitForEvent("download", { timeout: 20_000 });
await downloadButton.click();
const download = await downloadEvent;