Skip to content

Commit 919e48c

Browse files
fix(extension): stop iframe hangs and add debug mode (#229)
chrome.scripting.executeScript({ allFrames: true }) could block forever on unresponsive cross-origin frames; add timeouts with main-frame fallbacks, raise snapshot depth for Draft.js widgets, and ship a debug-log UI for runs. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 03d375f commit 919e48c

15 files changed

Lines changed: 1052 additions & 304 deletions

‎runners/extension/agentContext.js‎

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { callLlm } from "./llm.js";
22
import { collectFrames } from "./frameDiscovery.js";
33
import { state } from "./state.js";
4+
import { dbg } from "./debugLog.js";
45

56
/**
67
* Merge homepage agent context with optional Advanced "business use case" text.
@@ -12,15 +13,40 @@ export function mergeBusinessContext(agentContext, extraBusinessUseCase) {
1213
return a || b || "";
1314
}
1415

16+
const CONTEXT_TIMEOUT_MS = 45_000;
17+
1518
/**
1619
* Use the reader LLM to infer what the on-page chat agent is from DOM snapshots.
1720
*/
1821
export async function summarizeAgentFromTab(tabId, readerCfg, siteUrl = "") {
22+
dbg("context", "summarizeAgentFromTab called", { tabId, siteUrl: String(siteUrl).slice(0, 120) });
23+
24+
return Promise.race([
25+
_summarizeAgentFromTabInner(tabId, readerCfg, siteUrl),
26+
new Promise((_, reject) =>
27+
setTimeout(
28+
() =>
29+
reject(
30+
new Error(`Agent context detection timed out after ${CONTEXT_TIMEOUT_MS / 1000}s`)
31+
),
32+
CONTEXT_TIMEOUT_MS
33+
)
34+
),
35+
]);
36+
}
37+
38+
async function _summarizeAgentFromTabInner(tabId, readerCfg, siteUrl) {
1939
let frames = [];
2040
try {
2141
frames = await collectFrames(tabId);
22-
} catch {
23-
// proceed with empty frames; prompt will note missing snapshot
42+
dbg("context", "Collected frames for agent summary", {
43+
count: frames.length,
44+
chatFrames: frames.filter((f) => (f.chatScore || 0) > 0).length,
45+
});
46+
} catch (e) {
47+
dbg("context", "Frame collection failed — proceeding with empty frames", {
48+
error: e instanceof Error ? e.message : String(e),
49+
});
2450
}
2551

2652
const top = frames.find((f) => f.frameId === 0);
@@ -78,8 +104,13 @@ export async function summarizeAgentFromTab(tabId, readerCfg, siteUrl = "") {
78104

79105
const summary = typeof out?.summary === "string" ? out.summary.trim() : "";
80106
if (!summary) {
107+
dbg("context", "Agent summary LLM returned empty summary");
81108
throw new Error("Agent summary LLM returned empty summary");
82109
}
110+
dbg("context", "Agent summary generated", {
111+
summaryLen: summary.length,
112+
preview: summary.slice(0, 300),
113+
});
83114
return summary;
84115
}
85116

0 commit comments

Comments
 (0)