Skip to content

An agentic browser harness: an AI side panel & orb in your own logged-in Chrome, Edge, Arc, Brave or even Firefox run by the agent/subscription you already use (Claude Code, Codex, Antigravity). Free, open source, no API key. Also an MCP server.

fix(a-eye): skip every element Browsentic draws into a page, so neither the user's pick nor the agent's can outline or land on the rail, a toast card or the hands-free mic

Shahriar3f5fbfcaf6a4
diff --git a/src/lib/actions/page/lens.test.ts b/src/lib/actions/page/lens.test.ts
new file mode 100644
index 0000000..6e12977
--- /dev/null
+++ b/src/lib/actions/page/lens.test.ts
@@ -0,0 +1,60 @@
+import { afterEach, describe, expect, it, vi } from 'vitest';
+import { OVERLAY_ATTRIBUTE } from '@/lib/overlay';
+import { pickWithLens, type LensOutcome } from './lens';
+
+function stage() {
+ const button = document.createElement('button');
+ button.textContent = 'Sign in';
+ document.body.append(button);
+ const orb = document.createElement('div');
+ orb.setAttribute(OVERLAY_ATTRIBUTE, '');
+ document.documentElement.append(orb);
+ return { button, orb };
+}
+
+function pointAt(target: Element) {
+ vi.spyOn(document, 'elementFromPoint').mockReturnValue(target);
+ window.dispatchEvent(new PointerEvent('pointermove', { clientX: 10, clientY: 10 }));
+}
+
+function clickAt(target: Element) {
+ vi.spyOn(document, 'elementFromPoint').mockReturnValue(target);
+ window.dispatchEvent(new MouseEvent('click', { clientX: 10, clientY: 10, bubbles: true, cancelable: true }));
+}
+
+function settled(pick: Promise<LensOutcome>) {
+ let outcome: LensOutcome | null = null;
+ void pick.then((value) => (outcome = value));
+ return () => outcome;
+}
+
+describe('pickWithLens', () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ document.body.innerHTML = '';
+ for (const host of document.querySelectorAll(`[${OVERLAY_ATTRIBUTE}]`)) host.remove();
+ });
+
+ it('picks the page element under the click', async () => {
+ const { button } = stage();
+ const pick = pickWithLens({ timeoutMs: 5_000 });
+ pointAt(button);
+ clickAt(button);
+ await expect(pick).resolves.toEqual({ picked: button });
+ });
+
+ it('never picks an overlay the extension drew, even right after hovering the page', async () => {
+ const { button, orb } = stage();
+ const pick = pickWithLens({ timeoutMs: 5_000 });
+ const outcome = settled(pick);
+
+ pointAt(button);
+ pointAt(orb);
+ clickAt(orb);
+ await Promise.resolve();
+ expect(outcome()).toBeNull();
+
+ window.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape' }));
+ await expect(pick).resolves.toEqual({ cancelled: true });
+ });
+});
diff --git a/src/lib/actions/page/lens.ts b/src/lib/actions/page/lens.ts
index a775325..80b5c00 100644
--- a/src/lib/actions/page/lens.ts
+++ b/src/lib/actions/page/lens.ts
@@ -1,3 +1,5 @@
+import { isOverlay } from '@/lib/overlay';
+
export type LensOutcome = { picked: Element } | { cancelled: true } | { timedOut: true };
const HOST_ID = 'browsentic-a-eye';
@@ -71,7 +73,9 @@ export function pickWithLens({ hint, timeoutMs }: { hint?: string; timeoutMs: nu
const onClick = (event: MouseEvent) => {
swallow(event);
- const target = hovered ?? document.elementFromPoint(event.clientX, event.clientY);
+ const under = document.elementFromPoint(event.clientX, event.clientY);
+ if (under && isOverlay(under)) return;
+ const target = hovered ?? under;
if (target && target !== document.documentElement) settle({ picked: target });
};
@@ -106,6 +110,11 @@ export function pickWithLens({ hint, timeoutMs }: { hint?: string; timeoutMs: nu
for (const [type, listener, options] of listeners) window.addEventListener(type, listener, options);
function aim(target: Element | null): void {
+ if (target && isOverlay(target)) {
+ hovered = null;
+ box.hidden = true;
+ return;
+ }
if (!target || target === host || target === document.documentElement) return;
hovered = target;
draw(target);
diff --git a/src/lib/overlay.ts b/src/lib/overlay.ts
new file mode 100644
index 0000000..9731df8
--- /dev/null
+++ b/src/lib/overlay.ts
@@ -0,0 +1,4 @@
+/** Set on every host the extension draws into a page, so nothing that picks from the page can land on one. */
+export const OVERLAY_ATTRIBUTE = 'data-browsentic-overlay';
+
+export const isOverlay = (element: Element): boolean => element.hasAttribute(OVERLAY_ATTRIBUTE);
diff --git a/src/lib/rail/host.ts b/src/lib/rail/host.ts
index a6a5b25..4e66f71 100644
--- a/src/lib/rail/host.ts
+++ b/src/lib/rail/host.ts
@@ -1,4 +1,5 @@
import { browser } from 'wxt/browser';
+import { OVERLAY_ATTRIBUTE } from '@/lib/overlay';
import {
RAIL_CHANNEL,
RAIL_PALETTES,
@@ -57,6 +58,7 @@ export function exposeRail(): void {
host = document.createElement('div');
host.id = HOST_ID;
host.setAttribute('aria-hidden', 'false');
+ host.setAttribute(OVERLAY_ATTRIBUTE, '');
host.style.cssText = 'all: initial; position: static;';
root = host.attachShadow({ mode: 'closed' });
document.documentElement.append(host);
diff --git a/src/lib/toast/host.ts b/src/lib/toast/host.ts
index 06912f1..4e91400 100644
--- a/src/lib/toast/host.ts
+++ b/src/lib/toast/host.ts
@@ -1,4 +1,5 @@
import { browser } from 'wxt/browser';
+import { OVERLAY_ATTRIBUTE } from '@/lib/overlay';
import { RAIL_PALETTES, RAIL_TONES } from '@/lib/rail/events';
import { MAX_TOASTS, TOAST_CHANNEL, isToastCommand, type ToastView } from './events';
@@ -66,6 +67,7 @@ export function exposeToast(): void {
clear();
host = document.createElement('div');
host.id = HOST_ID;
+ host.setAttribute(OVERLAY_ATTRIBUTE, '');
host.style.cssText = 'all: initial; position: static;';
root = host.attachShadow({ mode: 'closed' });
root.innerHTML = `<style>${STYLES}</style><div class="stack" role="region" aria-label="Browsentic"></div>`;