From 55419d6aedf48eef0ec05af00289113af75d7a48 Mon Sep 17 00:00:00 2001 From: Janghoon Lee <44862514+its-janghoon@users.noreply.github.com> Date: Fri, 13 Nov 2026 10:51:31 +0000 Subject: [PATCH] fix(browser): say when a site blocks the built-in browser MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Asked for Coupang prices, the headless browser got "Access Denied", and the model quietly answered from web search snippets as if it had read them on Coupang, without telling the person to connect their Chrome. - browser/blocked.ts: one helper that reads the title and the start of a short page for Access Denied, 403 Forbidden, captchas (also 보안문자 / 자동입력 방지), robot checks and Cloudflare challenges. - A blocked reading from the built-in browser is tried once in the person's Chrome when it is linked now. Otherwise the result starts with `Blocked: showed ...`, which tells the model to tell the person, to say an answer from search results comes from search results and not the site, and (once per session) how to connect their Chrome. The TUI gets metadata.connect for its how-to-connect line. - The browser tool description says shops, bookings, sign-ins and bot checks need the browser tool, not web search. The browser and web search descriptions both say to state when an answer comes from search results because the site blocked the browser. --- packages/redrob/src/browser/blocked.ts | 29 +++++++ packages/redrob/src/browser/extension.ts | 48 ++++++++++++ packages/redrob/src/browser/tool.ts | 6 +- packages/redrob/src/tool/browser.ts | 15 +++- packages/redrob/src/tool/browser.txt | 4 + packages/redrob/src/tool/websearch.txt | 1 + packages/redrob/test/browser/blocked.test.ts | 81 ++++++++++++++++++++ 7 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 packages/redrob/src/browser/blocked.ts create mode 100644 packages/redrob/test/browser/blocked.test.ts diff --git a/packages/redrob/src/browser/blocked.ts b/packages/redrob/src/browser/blocked.ts new file mode 100644 index 0000000000..31a7576480 --- /dev/null +++ b/packages/redrob/src/browser/blocked.ts @@ -0,0 +1,29 @@ +/** + * Whether a page is a bot check or an access block rather than the site itself: shops and + * ticketing sites (Coupang, for one) answer a headless browser with "Access Denied", a 403, a + * captcha or a Cloudflare challenge. Read from the page's title and the start of its text only; + * a long page that merely mentions a captcha is the site. + */ +const SIGNS: ReadonlyArray = [ + [/\baccess denied\b/i, "Access Denied"], + [/\b403\b.{0,20}\bforbidden\b|\bforbidden\b.{0,20}\b403\b|^\s*403\b/i, "403 Forbidden"], + [/just a moment|checking your browser|cf-chl|attention required.{0,20}cloudflare|cloudflare ray id/i, "a Cloudflare check"], + [/\bcaptcha\b|recaptcha|hcaptcha|보안 ?문자|자동입력 ?방지/i, "a captcha"], + [/are you (?:a )?(?:human|robot)|not a robot|verify (?:you are|that you're) (?:a )?human|unusual traffic|로봇이 아닙니다/i, "a robot check"], + [/request (?:was )?blocked|pardon our interruption|bot detected|접근이 (?:차단|거부)/i, "a block page"], +] + +/** Only a page this short can be a block page; the site's own pages are longer. */ +const MAX_BLOCK_TEXT = 3_000 + +/** What blocked the page ("Access Denied", "a captcha", ...), or undefined when it is the site. */ +export function blocked(page: { readonly title: string; readonly text: string }): string | undefined { + const text = page.text.length > MAX_BLOCK_TEXT ? undefined : page.text + for (const [sign, name] of SIGNS) { + if (sign.test(page.title)) return name + if (text !== undefined && sign.test(text)) return name + } + return undefined +} + +export * as BlockedPage from "./blocked" diff --git a/packages/redrob/src/browser/extension.ts b/packages/redrob/src/browser/extension.ts index 9806f93709..1070ef75b1 100644 --- a/packages/redrob/src/browser/extension.ts +++ b/packages/redrob/src/browser/extension.ts @@ -15,6 +15,7 @@ */ import * as Channels from "@redrob-code/server/channels" import * as Registry from "@/daemon/registry" +import { BlockedPage } from "./blocked" export type Action = "open" | "read" | "click" | "type" | "scroll" | "wait" | "screenshot" @@ -339,6 +340,53 @@ export const CONNECT = "Tell the person once, in their language: to let Redrob Code use their own Chrome with their sign-ins, they install the Redrob extension in Chrome and connect it with the same Redrob account (extension Settings → Redrob chat → Connect). The next browser step then asks them to press Allow in Chrome." /** The first line of every result: which browser the action ran in, and why not the person's own. */ +/** + * A reading from the built-in browser that turned out to be a block page: try the person's Chrome + * once when it is linked now (`retried`), else the note for the result (`blockedNote`). Undefined + * when the page is the site. + */ +export async function onBlocked( + reading: { readonly url: string; readonly title: string; readonly text: string }, + context: Context, +): Promise<{ retried: Result & { kind: "extension" } } | { note: string; connect: boolean } | undefined> { + const sign = BlockedPage.blocked(reading) + if (!sign) return undefined + if (await linked(context.observe)) { + const again = await act({ action: "open", url: reading.url }, context).catch(() => undefined) + if (again?.kind === "extension") return { retried: again } + } + const { text, connect } = blockedNote(context.sessionID, sign, reading.url) + return { note: text, connect } +} + +/** The person's Chrome is linked to the engine service right now. */ +export async function linked(observe?: () => Promise): Promise { + const read = observe ?? (await observer().catch(() => undefined)) + return (await read?.().catch(() => undefined))?.state === "ready" +} + +/** + * The lines a blocked page in the built-in browser gets (BlockedPage.blocked): nothing on it came + * from the site; the person is told their own Chrome is needed, with how to connect it once per + * session; and an answer from search results has to say so. `connect` is true when the + * how-to-connect line was given this time. + */ +export function blockedNote(sessionID: string, sign: string, url: string): { text: string; connect: boolean } { + const state = session(sessionID) + const connect = !state.hinted + state.hinted = true + let host = url + try { + host = new URL(url).hostname + } catch {} + const text = [ + `Blocked: ${host} showed ${sign} to this headless browser, so nothing below is the site's content. Tell the person the site blocked the built-in browser and that their own Chrome is needed for it.`, + `If you answer from search results instead, say so plainly: the answer comes from search results, not from ${host}, and may be out of date.`, + ...(connect ? [CONNECT] : []), + ].join("\n") + return { text, connect } +} + export function line(result: Result): string { if (result.kind === "extension") return `Browser: the person's own Chrome (${result.browser}), through the Redrob extension.` const base = `Browser: Redrob Code's own Chromium on this machine (headless).${result.reason ? ` The person's Chrome is not used: ${result.reason}.` : ""}` diff --git a/packages/redrob/src/browser/tool.ts b/packages/redrob/src/browser/tool.ts index c17c0f68e7..7c13b1bf7b 100644 --- a/packages/redrob/src/browser/tool.ts +++ b/packages/redrob/src/browser/tool.ts @@ -77,7 +77,11 @@ async function act(input: Input, sessionID: string): Promise( } const reading = yield* Effect.promise(() => run(params)) + // A bot check or block page: the person's Chrome when it is linked now, else say so plainly. + const block = yield* Effect.promise(() => + UserBrowser.onBlocked(reading, { sessionID: ctx.sessionID, signal: ctx.abort }), + ) + if (block && "retried" in block) + return { + title: `${params.action} ${block.retried.url} (your Chrome)`, + output: `${UserBrowser.line(block.retried)}\n${block.retried.text}`, + metadata: { action: params.action, url: block.retried.url, browser: "chrome" as const }, + } + const note = block ? `${block.note}\n\n` : "" return { title: `${params.action} ${reading.url}`, - output: `${lead}URL: ${reading.url}\nTitle: ${reading.title}\n\n${reading.text}`, - metadata: { ...meta, url: reading.url }, + output: `${lead}${note}URL: ${reading.url}\nTitle: ${reading.title}\n\n${reading.text}`, + metadata: { ...meta, url: reading.url, ...(block?.connect ? { connect: true } : {}) }, } // A rejected promise dies with its error, which becomes the tool call's error text. }).pipe(Effect.orDie), diff --git a/packages/redrob/src/tool/browser.txt b/packages/redrob/src/tool/browser.txt index ae407d7889..131ac54513 100644 --- a/packages/redrob/src/tool/browser.txt +++ b/packages/redrob/src/tool/browser.txt @@ -11,4 +11,8 @@ Actions: Every action except screenshot returns a fresh reading. Element numbers belong to the reading they came from: after the page changes (navigation, a new tab, the user taking over), read again before using a number. +Use this tool, not web search, when the answer has to come from a site itself: prices and stock in a shop, bookings, anything behind a sign-in, or a site with a bot check. It runs in the person's own Chrome whenever that is linked. A result starting with `Blocked:` means the site showed a bot check or access block to the headless browser: nothing on that page is the site's content. Tell the person, and pass on how to connect their Chrome when the result says it. + +If the site blocked you and you answer from search results instead, say so plainly: the answer comes from search results, not from the site, and may be out of date. + The user may watch the browser and take it over. While they hold it, your next browser action waits until they hand it back (up to 10 minutes), and the result starts with a line saying what they did. Password fields are hidden in pictures. In the person's Chrome, sign-ins, payments and anything their approval setting asks about are their step there: the action waits for them. diff --git a/packages/redrob/src/tool/websearch.txt b/packages/redrob/src/tool/websearch.txt index ad5238cbd5..b38aeee25d 100644 --- a/packages/redrob/src/tool/websearch.txt +++ b/packages/redrob/src/tool/websearch.txt @@ -9,6 +9,7 @@ Usage notes: - Search types when available: 'auto' (balanced), 'fast' (quick results), 'deep' (comprehensive search) - Configurable context length for optimal LLM integration - Domain filtering and advanced search options available + - Results are snippets about a site, not the site itself. For prices or stock in a shop, bookings, or anything behind a sign-in, use the browser tool. When you answer from search results because a site blocked the browser or could not be opened, say so plainly: the answer comes from search results, not from the site, and may be out of date. The current year is {{year}}. You MUST use this year when searching for recent information or current events - Example: If the current year is 2026 and the user asks for "latest AI news", search for "AI news 2026", NOT "AI news 2025" diff --git a/packages/redrob/test/browser/blocked.test.ts b/packages/redrob/test/browser/blocked.test.ts new file mode 100644 index 0000000000..64a02fe35c --- /dev/null +++ b/packages/redrob/test/browser/blocked.test.ts @@ -0,0 +1,81 @@ +import { afterEach, describe, expect, test } from "bun:test" +import { BlockedPage } from "../../src/browser/blocked" +import { UserBrowser } from "../../src/browser/extension" +import BROWSER from "../../src/tool/browser.txt" +import WEBSEARCH from "../../src/tool/websearch.txt" + +afterEach(() => UserBrowser.reset()) + +describe("BlockedPage.blocked", () => { + const cases: Array<[string, string, string]> = [ + ["Access Denied", "- heading \"Access Denied\" [level=1]\n- text: You don't have permission to access", "Access Denied"], + ["403 Forbidden", "- heading \"403 Forbidden\"", "403 Forbidden"], + ["Just a moment...", "- text: Checking your browser before accessing", "a Cloudflare check"], + ["", "- text: Please complete the CAPTCHA to continue", "a captcha"], + ["Robot check", "- text: Are you a robot?", "a robot check"], + ["네이버", "- text: 자동입력 방지 문자를 입력해 주세요", "a captcha"], + ["Pardon Our Interruption", "- text: something about your browser", "a block page"], + ] + for (const [title, text, sign] of cases) + test(`sees ${sign} (${title || text.slice(0, 20)})`, () => { + expect(BlockedPage.blocked({ title, text })).toBe(sign) + }) + + test("the site itself is not a block, even a long page that mentions a captcha", () => { + expect(BlockedPage.blocked({ title: "쿠팡! | 에어팟 프로 3", text: "- link \"에어팟 프로 3\"\n- text: 329,000원" })).toBeUndefined() + expect(BlockedPage.blocked({ title: "Example Domain", text: "This domain is for use in documentation examples." })).toBeUndefined() + const long = `${"- text: product row\n".repeat(300)}- text: we use reCAPTCHA on sign-in` + expect(BlockedPage.blocked({ title: "Shop", text: long })).toBeUndefined() + }) +}) + +describe("a blocked page in the built-in browser", () => { + const page = { url: "https://www.coupang.com/np/search?q=airpods", title: "Access Denied", text: "- heading \"Access Denied\"" } + const off = async () => ({ state: "none" as const }) + + test("says the site blocked it, tells the model to say so, and how to connect once per session", async () => { + const first = await UserBrowser.onBlocked(page, { sessionID: "ses_b", observe: off }) + expect(first && "note" in first).toBe(true) + if (!first || !("note" in first)) return + expect(first.note.startsWith("Blocked: www.coupang.com showed Access Denied")).toBe(true) + expect(first.note).toContain("the answer comes from search results, not from www.coupang.com") + expect(first.note).toContain(UserBrowser.CONNECT) + expect(first.connect).toBe(true) + const again = await UserBrowser.onBlocked(page, { sessionID: "ses_b", observe: off }) + if (!again || !("note" in again)) throw new Error("expected a note") + expect(again.note).not.toContain(UserBrowser.CONNECT) + expect(again.connect).toBe(false) + }) + + test("a page that is the site gets nothing", async () => { + expect(await UserBrowser.onBlocked({ ...page, title: "쿠팡", text: "- text: 329,000원" }, { sessionID: "ses_c", observe: off })).toBeUndefined() + }) + + test("retries in the person's Chrome when it is linked", async () => { + const answer = "URL: https://www.coupang.com/np/search?q=airpods\nTitle: 쿠팡\n\n- text: 329,000원" + let n = 0 + const ask = async (request: { method: string; path: string }) => { + if (request.path.startsWith("/browser/task?chatId=")) return { status: 404, browser: { state: "ready" as const, name: "Chrome" } } + if (request.method === "POST") return { status: 200, body: { id: `t${++n}` }, browser: { state: "ready" as const, name: "Chrome" } } + return { status: 200, body: { id: "t1", state: "done", events: [], answer }, browser: { state: "ready" as const, name: "Chrome" } } + } + const result = await UserBrowser.onBlocked(page, { + sessionID: "ses_r", + ask, + observe: async () => ({ state: "ready" as const, name: "Chrome" }), + }) + expect(result && "retried" in result && result.retried.text).toBe(answer) + }) +}) + +describe("the tool descriptions", () => { + test("the browser tool is for shops, bookings, sign-ins and bot checks, and a block is said", () => { + expect(BROWSER).toContain("prices and stock in a shop, bookings, anything behind a sign-in, or a site with a bot check") + expect(BROWSER).toContain("the answer comes from search results, not from the site") + }) + + test("web search says snippets are not the site, and to say so", () => { + expect(WEBSEARCH).toContain("use the browser tool") + expect(WEBSEARCH).toContain("the answer comes from search results, not from the site") + }) +})