Wait for hydrated ChatGPT share messages
This commit is contained in:
+15
-2
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user