mirror of
https://github.com/Tencent/BrowserSkill.git
synced 2026-09-10 13:01:23 +08:00
fix(vom): bug fix
This commit is contained in:
@@ -344,6 +344,11 @@ export default defineContentScript({
|
||||
renderControlOverlay();
|
||||
}
|
||||
|
||||
async function waitForRenderedOverlayUpdate(): Promise<void> {
|
||||
await new Promise<void>((resolve) => window.requestAnimationFrame(() => resolve()));
|
||||
await new Promise<void>((resolve) => window.requestAnimationFrame(() => resolve()));
|
||||
}
|
||||
|
||||
function clearCurrentAgentSession(): void {
|
||||
const sessionId = overlays.snapshot().activeSessionId;
|
||||
if (!sessionId) return;
|
||||
@@ -528,6 +533,7 @@ export default defineContentScript({
|
||||
};
|
||||
overlays.clearAgentHelpRequest(requestId);
|
||||
renderAll();
|
||||
await waitForRenderedOverlayUpdate();
|
||||
await chrome.runtime.sendMessage(msg).catch((err) => {
|
||||
console.debug("[bsk overlay] help finish failed", err);
|
||||
});
|
||||
|
||||
@@ -107,6 +107,30 @@ describe("handleRequestHelp", () => {
|
||||
expect(res).toMatchObject({ outcome: "continued", note: "ok", tab_id: 5 });
|
||||
});
|
||||
|
||||
it("does not refresh observations after the user returns control", async () => {
|
||||
const cdpSend = vi.fn(async () => ({}));
|
||||
const deps = baseDeps({
|
||||
cdp: { send: cdpSend } as unknown as RequestHelpDeps["cdp"],
|
||||
});
|
||||
const res = await handleRequestHelp(
|
||||
fakeManager("abcd", 99, 5),
|
||||
baseParams({ tab_id: 5 }),
|
||||
deps,
|
||||
);
|
||||
|
||||
expect(res).toMatchObject({ outcome: "continued", tab_id: 5 });
|
||||
expect(cdpSend).not.toHaveBeenCalledWith(
|
||||
expect.any(Number),
|
||||
"Accessibility.getFullAXTree",
|
||||
expect.anything(),
|
||||
);
|
||||
expect(cdpSend).not.toHaveBeenCalledWith(
|
||||
expect.any(Number),
|
||||
"DOMSnapshot.captureSnapshot",
|
||||
expect.anything(),
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards title into the help request message when provided", async () => {
|
||||
const deps = baseDeps();
|
||||
await handleRequestHelp(
|
||||
|
||||
@@ -304,11 +304,12 @@ async function cleanupHelp(help: ActiveHelpRequest): Promise<void> {
|
||||
);
|
||||
}
|
||||
|
||||
function finishHelp(
|
||||
async function finishHelp(
|
||||
help: ActiveHelpRequest,
|
||||
value: RequestHelpResult | RpcError,
|
||||
notifyContent = true,
|
||||
): void {
|
||||
waitForCleanup = false,
|
||||
): Promise<void> {
|
||||
if (help.settled) return;
|
||||
help.settled = true;
|
||||
activeHelpRequests.delete(help.requestId);
|
||||
@@ -317,7 +318,11 @@ function finishHelp(
|
||||
if (help.abortHandler) help.deps.signal?.removeEventListener("abort", help.abortHandler);
|
||||
clearRearmTimer(help.primaryTabId);
|
||||
for (const tabId of help.overlayTabIds) clearRearmTimer(tabId);
|
||||
if (notifyContent) void cleanupHelp(help);
|
||||
if (notifyContent) {
|
||||
const cleanup = cleanupHelp(help);
|
||||
if (waitForCleanup) await cleanup;
|
||||
else void cleanup;
|
||||
}
|
||||
help.resolve(value);
|
||||
}
|
||||
|
||||
@@ -386,12 +391,17 @@ async function rearmHelp(help: ActiveHelpRequest, tabId: number): Promise<boolea
|
||||
try {
|
||||
const legacyFinish = await refreshAndSendHelpOverlay(help, tabId);
|
||||
if (legacyFinish && !help.settled) {
|
||||
finishHelp(help, {
|
||||
outcome: legacyFinish.outcome,
|
||||
...(legacyFinish.note ? { note: legacyFinish.note } : {}),
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
});
|
||||
await finishHelp(
|
||||
help,
|
||||
{
|
||||
outcome: legacyFinish.outcome,
|
||||
...(legacyFinish.note ? { note: legacyFinish.note } : {}),
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
},
|
||||
true,
|
||||
true,
|
||||
);
|
||||
}
|
||||
return true;
|
||||
} catch {
|
||||
@@ -501,12 +511,17 @@ async function finishHelpFromContent(
|
||||
const match = await findHelpForTab(tabId, deps);
|
||||
if (match !== help) return;
|
||||
}
|
||||
finishHelp(help, {
|
||||
outcome: message.outcome,
|
||||
...(message.note ? { note: message.note } : {}),
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
});
|
||||
await finishHelp(
|
||||
help,
|
||||
{
|
||||
outcome: message.outcome,
|
||||
...(message.note ? { note: message.note } : {}),
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
},
|
||||
true,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
function attachHelpTabListener(deps: RequestHelpDeps): () => void {
|
||||
@@ -639,7 +654,7 @@ function startCompletionPolling(help: ActiveHelpRequest): void {
|
||||
}
|
||||
help.completionMatchedSince ??= now;
|
||||
if (now - help.completionMatchedSince < stableMs) return;
|
||||
finishHelp(help, {
|
||||
void finishHelp(help, {
|
||||
outcome: "completed",
|
||||
completed_by: "system",
|
||||
tab_id: help.primaryTabId,
|
||||
@@ -698,7 +713,7 @@ export async function handleRequestHelp(
|
||||
|
||||
return new Promise<RequestHelpResult | RpcError>((resolve) => {
|
||||
const timeoutTimer = setTimeout(() => {
|
||||
finishHelp(help, {
|
||||
void finishHelp(help, {
|
||||
outcome: "timed_out",
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
@@ -727,7 +742,8 @@ export async function handleRequestHelp(
|
||||
abortHandler: null,
|
||||
};
|
||||
|
||||
const onAbort = () => finishHelp(help, { code: "cancelled", message: "request_help aborted" });
|
||||
const onAbort = () =>
|
||||
void finishHelp(help, { code: "cancelled", message: "request_help aborted" });
|
||||
help.abortHandler = onAbort;
|
||||
activeHelpRequests.set(requestId, help);
|
||||
if (deps.signal?.aborted) {
|
||||
@@ -738,14 +754,19 @@ export async function handleRequestHelp(
|
||||
startCompletionPolling(help);
|
||||
|
||||
void sendCurrentHelpOverlay(help)
|
||||
.then((legacyFinish) => {
|
||||
.then(async (legacyFinish) => {
|
||||
if (!legacyFinish || help.settled) return;
|
||||
finishHelp(help, {
|
||||
outcome: legacyFinish.outcome,
|
||||
...(legacyFinish.note ? { note: legacyFinish.note } : {}),
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
});
|
||||
await finishHelp(
|
||||
help,
|
||||
{
|
||||
outcome: legacyFinish.outcome,
|
||||
...(legacyFinish.note ? { note: legacyFinish.note } : {}),
|
||||
tab_id: help.primaryTabId,
|
||||
resolved_targets: help.resolvedTargets,
|
||||
},
|
||||
true,
|
||||
true,
|
||||
);
|
||||
})
|
||||
.catch(() => {
|
||||
scheduleRearmForTab(tabId, deps);
|
||||
|
||||
Reference in New Issue
Block a user