Split MAX bot loops and make chats cache-first
This commit is contained in:
+14
-1
@@ -674,7 +674,10 @@ app.listen(port, () => {
|
||||
async function ensurePage(role = "default") {
|
||||
const normalizedRole = String(role || "default");
|
||||
const existing = pagesByRole.get(normalizedRole);
|
||||
if (existing && !existing.isClosed()) return existing;
|
||||
if (existing && !existing.isClosed()) {
|
||||
await waitForRolePageReady(existing, normalizedRole);
|
||||
return existing;
|
||||
}
|
||||
|
||||
await ensureContext();
|
||||
|
||||
@@ -695,9 +698,19 @@ async function ensurePage(role = "default") {
|
||||
pagesByRole.set(normalizedRole, rolePage);
|
||||
attachNetworkCapture(rolePage);
|
||||
await rolePage.goto(maxBaseUrl, { waitUntil: "domcontentloaded", timeout: 60000 });
|
||||
await waitForRolePageReady(rolePage, normalizedRole);
|
||||
return rolePage;
|
||||
}
|
||||
|
||||
async function waitForRolePageReady(rolePage, role) {
|
||||
if (role === "default") {
|
||||
return;
|
||||
}
|
||||
|
||||
await rolePage.waitForLoadState("domcontentloaded", { timeout: 15000 }).catch(() => {});
|
||||
await waitForLoginStage(rolePage, "Authorized", 15000).catch(() => false);
|
||||
}
|
||||
|
||||
async function ensureContext() {
|
||||
if (context) return;
|
||||
if (!contextInitialization) {
|
||||
|
||||
Reference in New Issue
Block a user