Wait for hydrated ChatGPT share messages

This commit is contained in:
Codex
2026-07-08 02:25:33 +00:00
parent 11229e911f
commit 202c7a4466
2 changed files with 162 additions and 2 deletions
+15 -2
View File
@@ -101,8 +101,21 @@ async function extractConversation(browser: Browser, sourceUrl: string): Promise
const page = await context.newPage();
page.setDefaultTimeout(config.captureTimeoutMs);
await page.goto(sourceUrl, { waitUntil: "domcontentloaded", timeout: config.captureTimeoutMs });
await page.waitForLoadState("networkidle", { timeout: Math.min(config.captureTimeoutMs, 60_000) }).catch(() => undefined);
await page.waitForTimeout(2500);
await page
.waitForFunction(
() => {
const bodyText = document.body?.innerText || document.body?.textContent || "";
if (/verify you are human|captcha|unusual activity/i.test(bodyText)) return true;
if (document.querySelectorAll("[data-message-author-role]").length > 0) return true;
const markdown = document.querySelector("main .markdown, main [class*=markdown]");
if ((markdown?.textContent || "").trim().length > 0) return true;
return /(?:^|\s)(You said:|ChatGPT said:)/.test(bodyText);
},
{ timeout: config.captureTimeoutMs }
)
.catch(() => undefined);
await page.waitForLoadState("networkidle", { timeout: 5_000 }).catch(() => undefined);
await page.waitForTimeout(1000);
const extracted = await page.evaluate(() => {
function cleanHtml(root: Element): string {