Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: let the browser agent follow search-result redirect links shown on the page (#14642)

Daniel Han05c9ab16b849
diff --git a/studio/frontend/src/features/browser/agent/executor.ts b/studio/frontend/src/features/browser/agent/executor.ts
index a37dc18c768..d6db5d41996 100644
--- a/studio/frontend/src/features/browser/agent/executor.ts
+++ b/studio/frontend/src/features/browser/agent/executor.ts
@@ -574,7 +574,7 @@ async function observe(tab: BrowserTab, context: Run, note?: string, op: Record<
if (fresh.loading || tabUrl(fresh) !== tabUrl(tab)) {
return { ok: false, error: "the page changed while it was being read; take a snapshot again." };
}
- if (op.op === "snapshot" || op.op === "find") context.session.pageLinks = new Set(context.fullAccess === true ? [] : answer.links ?? []);
+ if (op.op === "snapshot" || op.op === "find") context.session.pageLinks = new Set(context.fullAccess === true ? [] : linkedPages(answer.links ?? []));
return {
ok: true,
url: tabUrl(fresh),
@@ -660,6 +660,20 @@ function redirectChain(url: string): string[] {
return chain;
}
+/** A page's links, with each search-result redirect's landing page too: the tab opens that page,
+ * and the link to it is on the page, so following it is as linked as any other link there. */
+function linkedPages(links: string[]): string[] {
+ return links.flatMap((link) =>
+ redirectChain(link).flatMap((url) => {
+ try {
+ return [new URL(url).href];
+ } catch {
+ return [];
+ }
+ }),
+ );
+}
+
function redirectEnd(url: string): string {
const chain = redirectChain(url);
return chain[chain.length - 1];
diff --git a/studio/frontend/tests/browser-agent-redirect-gate.test.ts b/studio/frontend/tests/browser-agent-redirect-gate.test.ts
index c0b6e4768c0..9e4c201895c 100644
--- a/studio/frontend/tests/browser-agent-redirect-gate.test.ts
+++ b/studio/frontend/tests/browser-agent-redirect-gate.test.ts
@@ -73,7 +73,7 @@ test("a plain search page the user asked for still opens without a question", as
assert.equal(await askedBy(navigate("c1", context, "https://www.google.com/search?q=qwen"), "google.com"), null);
});
-test("a redirect link the open page shows is asked about before it loads, not after", async () => {
+test("a redirect link the open page shows opens its target without a question, like any link there", async () => {
const context = run("d");
show("d");
assert.equal(await askedBy(navigate("d1", context, "https://www.google.com/search?q=qwen"), "google.com"), null);
@@ -81,10 +81,33 @@ test("a redirect link the open page shows is asked about before it loads, not af
links = [wrapped];
await snapshot("d2", context);
links = [];
- assert.deepEqual(await askedBy(navigate("d3", context, wrapped), "result.example"), { host: "result.example", openedFirst: false });
+ assert.equal(await askedBy(navigate("d3", context, wrapped), "result.example"), null);
+ assert.equal(opened().includes("https://result.example/page"), true, "the linked result did not open");
+ // Being on the page links only that result: another site the model names still asks.
+ assert.equal(
+ (await askedBy(navigate("d4", context, `https://www.google.com/url?q=${encodeURIComponent("https://unlisted.example/")}`), "unlisted.example"))
+ ?.host,
+ "unlisted.example",
+ );
});
-test("a clicked redirect link is asked about at its target before the tab loads it", async () => {
+test("a redirect link the page shows is still refused when its target is blocked", async () => {
+ const context = run("f");
+ show("f");
+ assert.equal(await askedBy(navigate("f1", context, "https://www.google.com/search?q=qwen"), "google.com"), null);
+ const wrapped = "https://www.google.com/url?q=https://blocked.example/page&sa=U";
+ links = [wrapped];
+ await snapshot("f2", context);
+ links = [];
+ await runBrowserAction(
+ { id: "f3", sessionId: "s", op: "navigate", url: wrapped, direction: "down", policy: { allowedDomains: [], blockedDomains: ["blocked.example"] } },
+ context,
+ );
+ assert.equal(pending(), null);
+ assert.equal(opened().includes("blocked.example/page"), false, "the blocked target was opened");
+});
+
+test("a clicked search-result redirect link opens its target without a question", async () => {
const context = run("e");
show("e");
assert.equal(await askedBy(navigate("e1", context, "https://www.google.com/search?q=qwen"), "google.com"), null);
@@ -100,7 +123,8 @@ test("a clicked redirect link is asked about at its target before the tab loads
try {
await snapshot("e2", context);
const click = runBrowserAction({ id: "e3", sessionId: "s", op: "click", ref: "r5", direction: "down", policy }, context);
- assert.deepEqual(await askedBy(click, "clicked.example"), { host: "clicked.example", openedFirst: false });
+ assert.equal(await askedBy(click, "clicked.example"), null);
+ assert.equal(opened().includes("https://clicked.example/page"), true, "the clicked result did not open");
} finally {
globals.__frameAgent = original;
links = [];