From 749ad2a01e332c25412b0ad9a667ffa56df271fa Mon Sep 17 00:00:00 2001 From: Josh Mabry Date: Sun, 13 Sep 2026 01:39:08 -0700 Subject: [PATCH 1/2] fix: repair the browser tab when Chrome's Gemini panel steals it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Seen live 2026-09-13 on merchantAgent: one Kill Team item priced, then every navigation failed with `net::ERR_BLOCKED_BY_CLIENT`. Chrome 149's built-in Gemini side panel (gemini.google.com/glic) opened on its own in the headed window as a `webview` target, and the pinned agent-browser (0.27.1) makes a newly discovered target the ACTIVE tab — so `open` navigated the panel, which Chrome refuses. (Upstream 0.34.0 fixed "event-discovered targets steal the active tab"; the core pin is still 0.27.1.) - `Browser.ensure_page_tab()`: one `tab list`; when the active tab is not an ordinary page (a `page` target on http(s)/about:blank that is not the Gemini panel), close the non-page targets, reselect the first web page, or open a new tab. Runs before every navigation. - A navigation that still fails with ERR_BLOCKED_BY_CLIENT is repaired and retried once; with nothing to repair it raises as before. - A read whose `location.href` is the panel (or chrome:// / devtools://) is treated as decided — the settle loop no longer spins ~10 s on it — and `_fetch` repairs the tab, re-navigates and re-reads once instead of reporting "couldn't find the results list". - Skill: ERR_BLOCKED_BY_CLIENT explained as a browser-tab problem, not an eBay one. - 142 host-free tests (was 135); 0.3.2. Not done: disabling the panel at launch (`--disable-features=Glic`) — the feature name for Chrome 149 could not be verified, and `--args` splits on commas, which would clobber the base `--disable-features=Translate`. The repair covers it whatever opens the panel. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_011UQ33xXfygwEkzbbJx3YwZ --- browser.py | 64 +++++++++++++++++++++++ protoagent.plugin.yaml | 2 +- pyproject.toml | 2 +- skills/ebay-pricing/SKILL.md | 4 ++ tests/test_plugin.py | 99 ++++++++++++++++++++++++++++++++++++ tools.py | 21 +++++++- 6 files changed, 189 insertions(+), 3 deletions(-) diff --git a/browser.py b/browser.py index 5e0aeaf..c0307b8 100644 --- a/browser.py +++ b/browser.py @@ -35,6 +35,13 @@ log = logging.getLogger("protoagent.plugins.ebay") +#: Chrome's refusal when a navigation is issued to a target that is not an ordinary web page. +_BLOCKED_MARKER = "ERR_BLOCKED_BY_CLIENT" +#: Chrome 149's built-in Gemini side panel. It can open on its own in a headed window, as a +#: ``webview`` target; the pinned agent-browser makes any newly discovered target the ACTIVE +#: tab, so every later navigation goes into the panel and fails with ERR_BLOCKED_BY_CLIENT. +_GEMINI_PANEL = "gemini.google.com/glic" + #: Chrome flag that clears ``navigator.webdriver``, which Chrome sets under CDP control and #: which Google's sign-in refuses ("this browser or app may not be secure"). The same flag #: protoAgent's core browser plugin uses for its ``stealth`` option — and nothing more. @@ -146,13 +153,70 @@ def close(self) -> None: _run(self._cmd("close"), timeout=self.timeout_s) self._session_ready = False + # ── tab hygiene ───────────────────────────────────────────────────────────── + def _tabs(self) -> list[dict]: + res = _run(self._cmd("tab", "list", "--json"), timeout=self.timeout_s) + if not res.ok: + return [] + try: + payload = json.loads((res.stdout or "").strip().splitlines()[-1]) + except (ValueError, IndexError): + return [] + tabs = (payload.get("data") or {}).get("tabs") if isinstance(payload, dict) else None + return tabs if isinstance(tabs, list) else [] + + @staticmethod + def is_web_page(tab: dict) -> bool: + """An ordinary tab we can navigate: a ``page`` target on http(s) or about:blank, and not + the Gemini side panel.""" + url = str(tab.get("url") or "") + return ( + str(tab.get("type") or "page") == "page" + and (url.startswith(("http://", "https://")) or url == "about:blank") + and _GEMINI_PANEL not in url + ) + + def ensure_page_tab(self) -> list[str]: + """Make the session's active tab an ordinary web page again if something stole it. + + Closes every non-page target (the Gemini panel is the one seen in the wild), selects the + first remaining web page, or opens a new tab when none is left. Returns the ids it + closed — empty when the active tab was already fine, which is the common case and costs + one ``tab list``.""" + tabs = self._tabs() + active = next((t for t in tabs if t.get("active")), None) + if not tabs or (active is not None and self.is_web_page(active)): + return [] + closed = [] + for t in tabs: + if ( + not self.is_web_page(t) + and t.get("tabId") + and _run(self._cmd("tab", "close", str(t["tabId"])), timeout=self.timeout_s).ok + ): + closed.append(str(t["tabId"])) + pages = [t for t in tabs if self.is_web_page(t) and str(t.get("tabId")) not in closed] + if pages: + _run(self._cmd("tab", str(pages[0]["tabId"])), timeout=self.timeout_s) + else: + _run(self._cmd("tab", "new"), timeout=self.timeout_s) + log.warning( + "[ebay] the browser's active tab was not a web page (closed %s) — restored an ordinary tab", + closed or "none", + ) + return closed or ["(reselected)"] + # ── actions ───────────────────────────────────────────────────────────────── def open(self, url: str) -> None: self.ensure_session() self._pace() + self.ensure_page_tab() # Flags on every navigation: a daemon that died (an operator's `close`, a newer # CLI's idle timeout) respawns with our profile instead of a blank one. res = _run(self._open_cmd(url), timeout=self.timeout_s) + if not res.ok and _BLOCKED_MARKER in (res.stderr + res.stdout) and self.ensure_page_tab(): + # Something took the tab between our check and the navigation — repaired; once more. + res = _run(self._open_cmd(url), timeout=self.timeout_s) if not res.ok: raise BrowserError(f"could not open {url}: {(res.stderr or res.stdout).strip()}") diff --git a/protoagent.plugin.yaml b/protoagent.plugin.yaml index 8a87151..5d470e5 100644 --- a/protoagent.plugin.yaml +++ b/protoagent.plugin.yaml @@ -1,6 +1,6 @@ id: ebay name: Marketplace prices (eBay + Amazon, via browser) -version: 0.3.1 +version: 0.3.2 description: >- Price research across eBay and Amazon — what an item actually SOLD for on eBay, what it is being asked on both, and where today's price sits against what we've recorded before. diff --git a/pyproject.toml b/pyproject.toml index 9f81fdc..60893ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "ebay-plugin" -version = "0.3.1" +version = "0.3.2" description = "Marketplace price research (eBay + Amazon) + seller economics for protoAgent, via a browser session" requires-python = ">=3.11" diff --git a/skills/ebay-pricing/SKILL.md b/skills/ebay-pricing/SKILL.md index c905172..7829f90 100644 --- a/skills/ebay-pricing/SKILL.md +++ b/skills/ebay-pricing/SKILL.md @@ -65,6 +65,10 @@ market claim. with it. - **challenge page** → eBay wants a human interaction; ask the operator to complete it. If it recurs, suggest raising `ebay.min_interval_s`. +- **net::ERR_BLOCKED_BY_CLIENT** on a navigation → something other than a web page held the + browser tab (Chrome's Gemini side panel does this on its own). The tools repair the tab and + retry once by themselves; if it still fails, retry the call once, then stop and report it — + this is not an eBay problem and not a market finding. - **couldn't find the results list** → eBay changed its markup. Run `ebay_page_probe` on the URL and report what it shows. This is a bug to file, not a market finding. diff --git a/tests/test_plugin.py b/tests/test_plugin.py index 98b61e7..91cf98a 100644 --- a/tests/test_plugin.py +++ b/tests/test_plugin.py @@ -620,3 +620,102 @@ def test_the_page_script_reports_the_new_fields(self): for key in ("headline_count", "related_rows_excluded", "query_rewritten"): assert key in RESULT_JS assert "Results matching fewer words" in RESULT_JS or "results matching fewer words" in RESULT_JS + + +def _tab_cli(monkeypatch, tab_lists, *, open_results=None): + """A CLI stub whose `tab list` answers come from `tab_lists` in order (the last repeats) + and whose `open` answers come from `open_results` in order (default: success).""" + monkeypatch.setattr(browser_mod.shutil, "which", lambda b: "/usr/bin/agent-browser") + calls, lists, opens = [], list(tab_lists), list(open_results or []) + + def fake(args, timeout): + calls.append(args) + if args[1:3] == ["tab", "list"]: + tabs = lists.pop(0) if len(lists) > 1 else (lists[0] if lists else []) + return browser_mod.Result(True, json.dumps({"success": True, "data": {"tabs": tabs}}), "") + if args[1] == "open" and args[2] != "about:blank" and opens: + return opens.pop(0) + return browser_mod.Result(True, "✓ Done\n", "") + + monkeypatch.setattr(browser_mod, "_run", fake) + return calls + + +_PAGE = {"tabId": "t1", "type": "page", "url": "https://www.ebay.com/", "active": True} +_PANEL = {"tabId": "t2", "type": "webview", "url": "https://gemini.google.com/glic?hl=en-US", "active": True} + + +class TestGeminiPanel: + """Chrome 149's Gemini side panel opens on its own as a `webview` target and the pinned CLI + makes it the ACTIVE tab; every navigation then fails with ERR_BLOCKED_BY_CLIENT. Seen live + on 2026-09-13: one item priced, then the run stopped.""" + + def test_a_normal_active_tab_costs_one_tab_list_and_nothing_else(self, monkeypatch, tmp_path): + calls = _tab_cli(monkeypatch, [[_PAGE]]) + b = Browser(profile=str(tmp_path), min_interval_s=0) + b.open("https://www.ebay.com/sch/i.html?_nkw=x") + assert not any(c[1:3] == ["tab", "close"] for c in calls) + assert [c[2] for c in calls if c[1] == "open"][-1].startswith("https://www.ebay.com/sch") + + def test_the_panel_is_closed_and_the_page_reselected_before_navigating(self, monkeypatch, tmp_path): + page = dict(_PAGE, active=False) + calls = _tab_cli(monkeypatch, [[page, _PANEL]]) + b = Browser(profile=str(tmp_path), min_interval_s=0) + b.open("https://www.ebay.com/") + closes = [c for c in calls if c[1:3] == ["tab", "close"]] + assert [c[3] for c in closes] == ["t2"] + assert ["/usr/bin/agent-browser", "tab", "t1", "--session", "ebay"] in [c for c in calls] or any( + c[1:3] == ["tab", "t1"] for c in calls + ) + nav = [i for i, c in enumerate(calls) if c[1] == "open" and c[2] == "https://www.ebay.com/"] + assert nav and nav[0] > calls.index(closes[0]) # repaired BEFORE navigating + + def test_no_page_left_opens_a_new_tab(self, monkeypatch, tmp_path): + calls = _tab_cli(monkeypatch, [[_PANEL]]) + Browser(profile=str(tmp_path), min_interval_s=0).open("https://www.ebay.com/") + assert any(c[1:3] == ["tab", "new"] for c in calls) + + def test_a_blocked_navigation_is_repaired_and_retried_once(self, monkeypatch, tmp_path): + blocked = browser_mod.Result(False, "", "✗ Navigation failed: net::ERR_BLOCKED_BY_CLIENT") + page = dict(_PAGE, active=False) + # first check: fine; then the panel appears before the navigation lands; after repair: fine + calls = _tab_cli(monkeypatch, [[_PAGE], [page, _PANEL], [_PAGE]], open_results=[blocked]) + b = Browser(profile=str(tmp_path), min_interval_s=0) + b.open("https://www.ebay.com/sch/i.html?_nkw=x") # must not raise + navs = [c for c in calls if c[1] == "open" and c[2].startswith("https://www.ebay.com/sch")] + assert len(navs) == 2 + + def test_a_blocked_navigation_with_nothing_to_repair_is_an_error(self, monkeypatch, tmp_path): + blocked = browser_mod.Result(False, "", "✗ Navigation failed: net::ERR_BLOCKED_BY_CLIENT") + _tab_cli(monkeypatch, [[_PAGE]], open_results=[blocked]) + with pytest.raises(BrowserError, match="ERR_BLOCKED_BY_CLIENT"): + Browser(profile=str(tmp_path), min_interval_s=0).open("https://www.ebay.com/") + + def test_the_panel_is_not_a_web_page(self): + assert Browser.is_web_page(_PAGE) and Browser.is_web_page({"type": "page", "url": "about:blank"}) + assert not Browser.is_web_page(_PANEL) + assert not Browser.is_web_page({"type": "page", "url": "https://gemini.google.com/glic"}) + assert not Browser.is_web_page({"type": "page", "url": "chrome://newtab/"}) + + def test_a_read_that_landed_on_the_panel_is_repaired_and_re_read(self, monkeypatch): + import ebay_plugin.tools as tools_mod + + class Hijacked(_StubBrowser): + def __init__(self): + super().__init__(None) + self.reads = [dict(url="https://gemini.google.com/glic?hl=en-US", found_container=False), _GOOD_PAGE] + self.repairs = 0 + + def ensure_page_tab(self): + self.repairs += 1 + return ["t2"] + + def eval_json(self, script): + return self.reads.pop(0) if len(self.reads) > 1 else self.reads[0] + + b = Hijacked() + monkeypatch.setattr(tools_mod, "Browser", lambda **kw: b) + monkeypatch.setattr(tools_mod, "_SETTLE_S", 0) + out = json.loads({t.name: t for t in build_tools({})}["ebay_price_check"].invoke({"query": "x"})) + assert out["ok"] is True and out["results_found"] == 2 + assert b.repairs == 1 and len(b.opened) == 2 diff --git a/tools.py b/tools.py index e3d3136..868d8b6 100644 --- a/tools.py +++ b/tools.py @@ -71,7 +71,11 @@ class EbayError(RuntimeError): def _is_undecided(data) -> bool: - """True while the page shows neither results nor a reason — i.e. mid-redirect.""" + """True while the page shows neither results nor a reason — i.e. mid-redirect. A read that + ran on the Gemini panel (or another non-page target) is DECIDED: waiting will not change it, + the tab has to be repaired, so the settle loop must not spin on it.""" + if isinstance(data, dict) and _hijacked(data): + return False return isinstance(data, dict) and not any( (data.get("count"), data.get("found_container"), data.get("signin_wall"), data.get("challenge")) ) @@ -150,6 +154,14 @@ def _fetch(browser: Browser, url: str, *, sold: bool): data = browser.eval_json(RESULT_JS) if not isinstance(data, dict): raise EbayError(f"unexpected response while reading {url}") + if _hijacked(data) and browser.ensure_page_tab(): + # The page we read was not ours (Chrome's Gemini panel took the tab after we navigated). + # The tab is repaired; navigate and read once more rather than report a false "no results". + browser.open(url) + browser.wait_for(_RESULTS_SELECTOR) + data = browser.eval_json(RESULT_JS) + if not isinstance(data, dict): + raise EbayError(f"unexpected response while reading {url}") if data.get("signin_wall"): raise EbayError( "eBay redirected to its sign-in page. The sold-listings view needs a signed-in " @@ -179,6 +191,13 @@ def _fetch(browser: Browser, url: str, *, sold: bool): return listings, dropped, _page_meta(data) +def _hijacked(data: dict) -> bool: + """The script ran somewhere that is not a marketplace page — the Gemini side panel, or a + chrome:// / devtools:// target that took the active tab.""" + url = str(data.get("url") or "") + return "gemini.google.com/glic" in url or url.startswith(("chrome://", "devtools://", "chrome-extension://")) + + def _page_meta(data: dict) -> dict: """What the page said about itself beyond the rows: eBay's own match count, how many padded "fewer words" rows were left out, and whether it rewrote the query.""" From e011018685a87d4da75ea8b615f24a145b1559b5 Mon Sep 17 00:00:00 2001 From: Josh Mabry Date: Sun, 13 Sep 2026 01:59:12 -0700 Subject: [PATCH 2/2] fix: own a labelled tab; reclaim it before every navigation and after any foreign read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review round 1 on this PR (FIX FIRST): the first cut closed every tab that was not http(s) — the operator's file://, data:, view-source: tabs too — and reselected whichever web tab agent-browser listed first, which could be the operator's Gmail; its re-read after a repair skipped the settle loop (the false "markup changed" error the redirect fix exists to prevent); session status could report signed_in:false when another tab answered. - The plugin owns ONE labelled tab (`ebaytab`). The launch step is now `tab ebaytab` / `tab new --label ebaytab` WITH the launch flags — verified live on a throwaway session: it launches Chrome on the requested profile with the stealth argument, is reused on repeat, and `open` lands in the labelled tab. The old `open about:blank` launch blanked whatever tab was active (could be the operator's). - Every navigation switches to that tab first (one CLI call, flags attached, so a dead daemon relaunches with OUR options instead of a default headless browser). - Only Chrome's panels are ever closed: `type == "webview"` or the Gemini URL. An ordinary page is never closed, whatever its URL. - ERR_BLOCKED_BY_CLIENT on a navigation → close panels, reclaim our tab, retry once. - tools: ONE read path (`_read_page`: navigate → wait → read → settle). A read whose host is not the requested site (panel, about:blank, an operator tab) reclaims the tab, re-navigates and reads again through the SAME settle loop — once. Used by sold and active searches, Amazon, session status (never a false "signed out": it says it could not check) and the page probe (reports landed_url). - 156 host-free tests (was 142): ordering asserted (switch immediately before each navigation; panel closed and tab reclaimed BETWEEN the two navigations), pages never closed, labelled-tab creation without navigating another tab, flags on tab commands, settle after reclaim, session status / probe / Amazon reclaim, host rules. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_011UQ33xXfygwEkzbbJx3YwZ --- browser.py | 117 ++++++++++------ skills/ebay-pricing/SKILL.md | 9 +- tests/test_plugin.py | 254 ++++++++++++++++++++++++----------- tools.py | 118 ++++++++++------ 4 files changed, 329 insertions(+), 169 deletions(-) diff --git a/browser.py b/browser.py index c0307b8..4a2527b 100644 --- a/browser.py +++ b/browser.py @@ -21,6 +21,18 @@ (The CLI's ``⚠ … ignored: daemon already running`` warning is printed client-side whenever a daemon exists and flags were given; it is noise, not a signal — the daemon applied them.) Verified live against agent-browser 0.27.1 by watching Chrome's ``--user-data-dir``. + +**The plugin owns one labelled tab.** The window is shared with the operator (they sign in +and browse there) and Chrome opens its own targets into it — the Gemini side panel, as a +``webview``. agent-browser 0.27.1 makes any newly discovered target the ACTIVE tab and runs +every command on the active tab, so navigating "the current tab" could mean navigating the +panel (Chrome refuses: ``net::ERR_BLOCKED_BY_CLIENT``) or one of the operator's tabs. So the +launch step is ``tab