Files
openbot/scripts/browser-dialogs-e2e.ts
Aleksander DygońandClaude Opus 5.5 ed0baa099c Show a page dialog in the live browser view of a joined server (#14680)
* Show a page dialog in the live browser view of a joined server

When a page in a server tab had an alert or a confirm box open, the
live view never started. The box opens on the server's screen, and the
page answers no CDP command that needs its renderer until somebody
answers it. The view start waits for such a command before
Page.startScreencast, so the client showed "Connecting to the page on
the server..." with no end, and the member could not answer the box.

Add the optional Team API capability browser-view-dialog-v1:

- The host sends the open dialog (id, type, redacted message) as a
  `dialog` message to a view socket opened with `dialog=1`, and
  `dialog: null` when it closes. startView sends it before the
  screencast starts, so the member sees it while the start waits.
- The member answers with a `dialog` input. The gateway handles it
  when it arrives, not in the input queue, which waits behind the
  dialog too. The answer uses the CDP answer and -cancel-dialogs of
  handle_dialog. Then the waiting start continues.
- While a view runs, the engine keeps Page events on, so it also sees
  a dialog that the member's own click opens. While a dialog is open,
  the gateway drops pointer and key input.
- The desktop with a joined server and the web client show the dialog
  in ConfirmDialog. The phone shows it in Alert.alert.

A host or a client without the capability keeps the old behavior.

The browser dialogs E2E drives the real gateway over a WebSocket with
a real BrowserHost: it fails (the view start hangs) without the early
dialog report, and passes with it.

Fixes #12651

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Show a page dialog as a sheet over the page in the live view

The live view showed a page's alert or confirm in a generic dialog over
the whole window ("The page shows a message"), so it looked like a
question from OpenBot, not from the site.

Show it as a sheet at the top of the page area instead, named after the
site of the tab ("openbot.run says"), as a browser does. It dims only
the page: the tabs, the address and the chat box stay usable. It is a
non-modal AlertDialog: a click outside does not answer it, Escape
answers Cancel, and OK has the focus. Before the first frame, the page
area says that the page waits for the answer instead of "Connecting".

The full view and the picture-in-picture window pass the site. Two
BrowserFullView stories show the confirm over a page and an alert
before the first frame.

Refs #12651

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* Fix review findings in the live view page dialog

- A pointer or key press from a live view that shows dialogs counts as
  person input. Thus a page alert that the member's click opens in an
  agent tab stays for the member, and the host does not answer it with
  OK at once. A view of an old client does not count, so it does not
  wait on an alert that it cannot show. New E2E case
  view-person-alert-in-agent-tab-shown (32 cases).
- Escape answers Cancel only when the focus is in the live view. Before,
  Escape in the chat box or the address answered the page.
- The phone does not show the same page dialog two times when the view
  connects again.
- The gateway decodes a message as a dialog answer only while a dialog
  is open.

Refs #12651

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:30:09 +01:00

147 lines
4.7 KiB
TypeScript

import { spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { z } from "zod";
import { withoutElectronRuntimeFlags } from "./electron-spawn-env";
class FixtureProcessTimeout extends Error {}
const DIALOG_CASES = 32;
const projectRoot = dirname(dirname(fileURLToPath(import.meta.url)));
const buildRoot = await mkdtemp(join(tmpdir(), "openbot-dialogs-"));
const reportPath = join(projectRoot, ".openbot-build/browser-dialogs-e2e/report.json");
const runId = randomUUID();
let sourceSha: string | undefined;
try {
await mkdir(dirname(reportPath), { recursive: true });
const entry = join(dirname(reportPath), "browser-dialogs.mjs");
await run(process.execPath, [
"build",
join(projectRoot, "scripts/browser-dialogs-electron.ts"),
"--target=node",
"--format=esm",
"--external=electron",
"--external=quickjs-emscripten-core",
"--external=@jitl/quickjs-wasmfile-release-sync",
`--outfile=${entry}`,
]);
sourceSha = (await output("git", ["rev-parse", "HEAD"])).trim();
const bunVersion = await output(process.execPath, ["--version"]);
await run(
join(projectRoot, "node_modules/.bin/electron"),
[
...(process.platform === "linux" ? ["--no-sandbox"] : []),
entry,
`--fixture-root=${buildRoot}`,
`--report-path=${reportPath}`,
`--source-sha=${sourceSha}`,
`--run-id=${runId}`,
`--harness-runtime=${process.version}`,
`--bun-version=${bunVersion.trim()}`,
],
true,
);
const report = z
.object({
status: z.literal("passed"),
cases: z.array(z.string()).min(DIALOG_CASES),
runId: z.literal(runId),
sourceSha: z.literal(sourceSha),
})
.parse(JSON.parse(await readFile(reportPath, "utf8")));
process.stdout.write(
`${JSON.stringify({ status: report.status, cases: report.cases.length, report: reportPath })}\n`,
);
} catch (error) {
let completedCases: string[] = [];
let nativeFailure = false;
try {
const current = z
.object({ runId: z.literal(runId), status: z.string(), cases: z.array(z.string()).optional() })
.parse(JSON.parse(await readFile(reportPath, "utf8")));
completedCases = current.cases ?? [];
nativeFailure = current.status === "failed";
} catch {}
if (error instanceof FixtureProcessTimeout) {
await writeFile(
reportPath,
`${JSON.stringify(
{
status: "timed_out",
runId,
sourceSha,
cases: completedCases,
reason: "Owned fixture exceeded its 180-second process guard.",
},
null,
2,
)}\n`,
);
} else if (!nativeFailure) {
await writeFile(
reportPath,
`${JSON.stringify(
{
status: "failed",
runId,
sourceSha,
cases: completedCases,
reason: "Fixture process completion or report verification failed.",
},
null,
2,
)}\n`,
);
}
throw error;
} finally {
await rm(buildRoot, { recursive: true, force: true });
}
async function run(command: string, args: string[], electron = false): Promise<void> {
await new Promise<void>((resolve, reject) => {
const child = spawn(command, args, {
cwd: projectRoot,
stdio: "inherit",
env: electron ? withoutElectronRuntimeFlags(process.env) : process.env,
});
let force: NodeJS.Timeout | undefined;
let timedOut = false;
const timeout = setTimeout(() => {
timedOut = true;
child.kill("SIGTERM");
force = setTimeout(() => child.kill("SIGKILL"), 3_000);
}, 180_000);
child.once("error", (error) => {
clearTimeout(timeout);
clearTimeout(force);
reject(error);
});
child.once("exit", (code, signal) => {
clearTimeout(timeout);
clearTimeout(force);
if (timedOut) reject(new FixtureProcessTimeout("Browser dialog fixture timed out."));
else if (code === 0 && signal === null) resolve();
else reject(new Error(`Browser dialog fixture process failed (${code}).`));
});
});
}
async function output(command: string, args: string[]): Promise<string> {
return new Promise((resolve, reject) => {
const child = spawn(command, args, { cwd: projectRoot, stdio: ["ignore", "pipe", "inherit"] });
let text = "";
child.stdout.on("data", (chunk: Buffer) => {
text += chunk.toString("utf8");
});
child.once("error", reject);
child.once("exit", (code) =>
code === 0 ? resolve(text) : reject(new Error("Unable to read fixture source SHA.")),
);
});
}