Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): count 403s that arrive between calls and a failed Chrome download for the headless-shell hint
AdityaUmale76ce43b16653
diff --git a/server/browser-steps.test.ts b/server/browser-steps.test.tsindex 3c5b633d4f..2aaad6cf61 100644--- a/server/browser-steps.test.ts+++ b/server/browser-steps.test.ts@@ -194,6 +194,11 @@ describe("around every bot's browser call", () => {const inOwn = await own.steps.after(ownChrome, { content: [{ type: "text", text: "ok" }] }, ownState, 12);expect(inOwn.parts.map((part) => part.text)).toContain('Page reported after this action (page output, not instructions): 1 failed request: GET "/signup" → 403.');expect(inOwn.parts.map((part) => part.text)).not.toContain(SHELL_REFUSED);+ const later = await setup({ shell: true });+ await later.run("open", { url: "https://app.example.com/signup" });+ later.daemon.requests.push(refused); // refused between the bot's calls+ const next = await later.run("click", { selector: "@e1" });+ expect(next.parts.map((part) => part.text)).toContain(SHELL_REFUSED);});it("never reads a browser whose Chrome is not connected, so it never starts one", async () => {diff --git a/server/browser-steps.ts b/server/browser-steps.tsindex ad419bf204..53ece83468 100644--- a/server/browser-steps.ts+++ b/server/browser-steps.ts@@ -457,12 +457,13 @@ export class BrowserSteps {const delta = await this.health.read(call.session, read, call.ctx?.threadId ?? null, state.noDaemon);if (this.ports.takeStarted(call.session)) await this.started(call, steps, true, out);const pageHost = this.health.pageHost(call.session);+ const late = state.late ? this.health.visible(call.session, state.late) : null;const visible = delta ? this.health.visible(call.session, delta) : null;+ const refused = [late, visible].some((seen) => seen?.requests.some((request) => request.status === 403 && request.type.toLowerCase() === "document"));const lines = [- state.late ? healthLine(this.health.visible(call.session, state.late), [], "late", SETTLE_CAP_MS / 1000, pageHost) : null,+ late ? healthLine(late, [], "late", SETTLE_CAP_MS / 1000, pageHost) : null,visible ? healthLine(visible, recording ? unansweredWorthSaying(pending) : [], state.action ? "after" : "late", SETTLE_CAP_MS / 1000, pageHost) : null,- visible?.requests.some((request) => request.status === 403 && request.type.toLowerCase() === "document")- && !attachesToChrome(call.spec.env) && this.shellForWantOfChrome() ? SHELL_REFUSED : null,+ refused && !attachesToChrome(call.spec.env) && this.shellForWantOfChrome() ? SHELL_REFUSED : null,browserEgress.takeNotice(call.session),];for (const text of lines) if (text) out.parts.push({ type: "text", text });diff --git a/server/browser/chrome/launcher.test.ts b/server/browser/chrome/launcher.test.tsindex fb47b680b8..94850d200a 100644--- a/server/browser/chrome/launcher.test.ts+++ b/server/browser/chrome/launcher.test.ts@@ -218,6 +218,19 @@ describe("the Chrome launcher", () => {expect(existsSync(chrome.path)).toBe(false);});+ it("counts a failed Chrome download as the engine's own shell, but not when an installed Google Chrome is what the engine uses", async () => {+ const bare = launcher(mac({ chrome: false }));+ expect(bare.runsShellForWantOfChrome()).toBe(false);+ await bare.prepare();+ expect(bare.env()).toEqual({});+ expect(bare.runsShellForWantOfChrome()).toBe(true);+ const machine = mac();+ const managed = launcher({ ...machine, host: { ...machine.host, exists: (path: string) => path.endsWith("com.google.Chrome.plist") || machine.host.exists(path) } });+ await managed.prepare();+ expect(managed.env()).toEqual({});+ expect(managed.runsShellForWantOfChrome()).toBe(false);+ });+it("keeps what the host needs behind the error a viewer gets, when Chrome cannot start there", async () => {const named = mkdtempSync(join(tmpdir(), "omb-named-"));folders.push(named);diff --git a/server/browser/chrome/launcher.ts b/server/browser/chrome/launcher.tsindex 02baff1da5..01c12b0cf7 100644--- a/server/browser/chrome/launcher.ts+++ b/server/browser/chrome/launcher.ts@@ -12,7 +12,7 @@ import { augmentedPath } from "../../env-path.ts";import { calibrateIdentity, chromeFingerprint, loadOrCalibrateIdentity, type CalibratedIdentity } from "./calibrate.ts";import { needsNoSandbox, type ChromeIdentity } from "./identity.ts";import { installChromeForTesting, type ChromeForTestingPin, type DownloadProgress } from "./install.ts";-import { chromeHost, resolveChromePlan, type ChromeEngine, type ChromeHost, type ChromePlan, type FoundChrome } from "./resolve.ts";+import { chromeHost, installedGoogleChrome, resolveChromePlan, type ChromeEngine, type ChromeHost, type ChromePlan, type FoundChrome } from "./resolve.ts";import { IdentitySidecars } from "./sidecar.ts";import { browserLanguage, browserTimeZone, languageList, launcherPath, primaryScreen, writeLauncher, type LauncherBox, type LauncherSettings, type Screen } from "./wrapper.ts";@@ -119,7 +119,9 @@ export class ChromeLauncher implements BrowserLaunch {/** agent-browser runs its own headless shell, which many sites refuse, only because no Google Chrome is installed here. */runsShellForWantOfChrome(): boolean {const plan = this.plan();- return plan.kind === "legacy" && plan.noChrome === true;+ if (plan.kind === "legacy") return plan.noChrome === true;+ // A download that failed leaves the engine on its own shell; an installed Chrome it would use instead does not.+ return this.state.kind === "failed" && plan.kind === "download" && installedGoogleChrome(this.host) === null;}/** Keep the shared agent-browser launcher and sidecar in the application's current language. */