Skip to content

Commit aacf076

Browse files
authored
Merge pull request #208 from esokullu/codex/background-tab-runs
Make local browser runs background-safe
2 parents 7eee841 + c26d6d6 commit aacf076

65 files changed

Lines changed: 908 additions & 189 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,11 @@ they diverge.
212212
Chrome DevTools Protocol via `chrome.debugger`, so the Firefox build has no
213213
shadow-DOM piercing, no real trusted mouse events (some React/Vue handlers won't
214214
fire), no closed-shadow-root traversal, no `resolveSelector` retry budget, no
215-
SPA-navigation-aware retry, and no CDP screenshots (it falls back to
216-
`tabs.captureVisibleTab`, active tabs only). Site adapters, vision detection,
217-
loop detection, the auto-screenshot loop, and the Compact prompt/tool set *are*
218-
mirrored to Firefox. Some single-page apps may also fail to trigger
215+
SPA-navigation-aware retry, and no CDP screenshots. It uses `tabs.captureTab`
216+
for viewport screenshots, including inactive run tabs, but still cannot provide
217+
Chrome's pixel-perfect or full-page CDP capture. Site adapters, vision
218+
detection, loop detection, the auto-screenshot loop, and the Compact prompt/tool
219+
set *are* mirrored to Firefox. Some single-page apps may also fail to trigger
219220
content-script re-injection after client-side navigation.
220221

221222
## Contributing

docs/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ Firefox uses `browser.storage.session`.
719719
|---|---|---|
720720
| Background | Service worker (ephemeral) | Background page (persistent) |
721721
| Events | CDP-trusted (`isTrusted=true`) | Synthetic (`isTrusted=false`) |
722-
| Screenshots | CDP `Page.captureScreenshot` | `browser.tabs.captureVisibleTab()` |
722+
| Screenshots | CDP `Page.captureScreenshot` with run-scoped focus emulation for background tabs | `browser.tabs.captureTab()` for direct inactive-tab capture |
723723
| Conversation/UI persistence | `chrome.storage.session` | `browser.storage.session` |
724724
| Offscreen document | Yes (fetch proxy + recorder) | Not available |
725725
| Trace recorder | IndexedDB (opt-in) | IndexedDB (opt-in) — same `trace/recorder.js` |

docs/fr/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ rouvert reconstruise correctement le Markdown en cours. Chrome utilise
402402
|---|---|---|
403403
| Arrière-plan | Service worker (éphémère) | Page d'arrière-plan (persistante) |
404404
| Événements | CDP de confiance (`isTrusted=true`) | Synthétiques (`isTrusted=false`) |
405-
| Captures d'écran | CDP `Page.captureScreenshot` | `browser.tabs.captureVisibleTab()` |
405+
| Captures d'écran | CDP `Page.captureScreenshot` avec émulation de focus limitée à l'exécution en arrière-plan | `browser.tabs.captureTab()` pour capturer directement un onglet inactif |
406406
| Persistance conversation/interface | `chrome.storage.session` | `browser.storage.session` |
407407
| Document hors-écran | Oui (proxy fetch + enregistreur) | Non disponible |
408408
| Enregistreur de trace | IndexedDB (optionnel) | IndexedDB (optionnel) — même `trace/recorder.js` |

docs/fr/slash-commands.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ d'une espace ouvre l'autocomplétion de ses options disponibles.
3131
| `/workflow --export <id>` | Télécharger un fichier JSON portable `webbrain-workflow/1` assaini |
3232
| `/workflow --import --file` | Importer un fichier de workflow portable comme nouveau workflow local |
3333
| `/allow-api` | **Dérogation de mutation API par conversation.** Voir [plus bas](#allow-api). |
34+
| `/foreground [invite]` | Exécuter une tâche locale au premier plan pour assurer la compatibilité visuelle |
3435
| `/dangerously-skip-permissions` | **Contournement global des demandes d'autorisation.** Désactive `Ask before consequential actions` sans ouvrir les Paramètres. WebBrain agira sans demandes par site jusqu'à ce que vous réactiviez le réglage. |
3536
| `/compact` | Force le compactage du contexte pour la conversation actuelle |
3637
| `/verbose` | Bascule l'affichage verbeux/compact des outils |
@@ -64,6 +65,22 @@ quitter la page initiale ne la ramène pas vers l'URL surveillée, et l'onglet
6465
auxiliaire est fermé à la fin du watch. Les échecs d'interrogation transitoires
6566
sont tolérés ; trois échecs consécutifs arrêtent le watch.
6667

68+
## `/foreground`
69+
70+
Les exécutions locales ordinaires restent liées à leur onglet d'origine et
71+
fonctionnent sans activer cet onglet ni donner le focus à sa fenêtre. Chrome
72+
effectue les captures via CDP avec une émulation du focus limitée à l'exécution ;
73+
Firefox capture directement l'onglet cible avec `tabs.captureTab`. Si Chrome
74+
renvoie plusieurs fois une image vide en arrière-plan, WebBrain l'écarte et
75+
continue à partir du DOM et des données d'accessibilité.
76+
77+
Utilisez `/foreground <invite>` comme solution de compatibilité pour une seule
78+
exécution lorsqu'un site ne restitue pas correctement son état visuel en
79+
arrière-plan. Cette commande rétablit l'activation de l'onglet et le focus de la
80+
fenêtre pour cette exécution uniquement. Elle n'est pas persistante, et les
81+
exécutions Cloud gérées conservent leur comportement actuel au premier plan car
82+
leur navigateur est dédié à la tâche.
83+
6784
## `/allow-api`
6885

6986
`/allow-api` lève la restriction UI-d'abord pour la conversation en cours, afin
@@ -92,10 +109,11 @@ zone visible juste avant et après l'exécution (Chrome et Firefox). Par exemple
92109
`checkout-before.png` et `checkout-after.png` ; sans `--save-as`, WebBrain
93110
utilise des noms horodatés.
94111

95-
Si l'exécution ouvre un autre onglet, WebBrain réactive l'onglet d'origine avant
96-
d'enregistrer la capture « après ». Si l'enregistrement ou la capture initiale ne
97-
peut pas être démarré et sauvegardé, l'exécution n'est pas envoyée. Les
98-
`/record` et `/screenshot` autonomes conservent leur comportement existant.
112+
Pour ce suffixe de diagnostic, Chrome peut réactiver l'onglet d'origine avant
113+
d'enregistrer la capture « après ». Firefox capture directement cet onglet sans
114+
l'activer. Si l'enregistrement ou la capture initiale ne peut pas être démarré
115+
et sauvegardé, l'exécution n'est pas envoyée. Les `/record` et `/screenshot`
116+
autonomes conservent leur comportement existant.
99117

100118
## Exports, instantanés et workflows
101119

docs/slash-commands.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ for its available flags.
3131
| `/workflow --export <id>` | Download a sanitized portable `webbrain-workflow/1` JSON file |
3232
| `/workflow --import --file` | Import a portable workflow file as a new local saved workflow |
3333
| `/allow-api` | **Per-conversation API mutation override.** See [below](#allow-api). |
34+
| `/foreground [prompt]` | Run one local task in the foreground for visual compatibility |
3435
| `/dangerously-skip-permissions` | **Global permission-prompt bypass.** Turns off `Ask before consequential actions` without opening Settings. WebBrain will act without per-site prompts until you re-enable the setting. |
3536
| `/compact` | Force context compaction for the current conversation |
3637
| `/verbose` | Toggle verbose/compact tool display |
@@ -63,6 +64,20 @@ navigate it back to the watched URL, and the helper tab is closed when the watch
6364
ends. Transient poll failures are tolerated; three consecutive failures stop the
6465
watch.
6566

67+
## `/foreground`
68+
69+
Regular local runs stay pinned to their original tab and operate without
70+
activating that tab or focusing its window. Chrome captures through CDP with
71+
focus emulation scoped to the run; Firefox captures the target tab directly
72+
with `tabs.captureTab`. If Chrome repeatedly returns a blank background frame,
73+
WebBrain discards it and continues from DOM and accessibility data.
74+
75+
Use `/foreground <prompt>` as a one-run compatibility escape hatch for a site
76+
whose visual state does not render correctly in the background. It restores tab
77+
activation and window focus for that run. The setting is not persistent, and
78+
managed cloud runs retain their existing foreground behavior because their
79+
browser is dedicated to the task.
80+
6681
## `/allow-api`
6782

6883
`/allow-api` lifts the UI-first restriction for the current conversation so the
@@ -89,10 +104,11 @@ immediately before and after the run (Chrome and Firefox). For example,
89104
`checkout-before.png` and `checkout-after.png`; without `--save-as`, WebBrain
90105
uses timestamped filenames.
91106

92-
If the run opens another tab, WebBrain reactivates the originating run tab
93-
before saving the after screenshot. If the recording or initial screenshot
94-
cannot be started and saved, the run is not sent. Standalone `/record` and
95-
`/screenshot` keep their existing behavior.
107+
For the Chrome diagnostic suffix, WebBrain may reactivate the originating run
108+
tab before saving the after screenshot. Firefox captures that tab directly
109+
without activating it. If the recording or initial screenshot cannot be
110+
started and saved, the run is not sent. Standalone `/record` and `/screenshot`
111+
keep their existing behavior.
96112

97113
## Exports, snapshots, and workflows
98114

docs/zh-CN/architecture.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ while (steps < maxSteps) {
278278
|---|---|---|
279279
| 后台 | Service Worker(临时) | 后台页面(持久化) |
280280
| 事件 | CDP 受信任(`isTrusted=true`| 合成事件(`isTrusted=false`|
281-
| 截图 | CDP `Page.captureScreenshot` | `browser.tabs.captureVisibleTab()` |
281+
| 截图 | CDP `Page.captureScreenshot`,后台运行时使用仅限该次运行的焦点模拟 | `browser.tabs.captureTab()`,可直接捕获非活动标签页 |
282282
| 对话/UI 持久化 | `chrome.storage.session` | `browser.storage.session` |
283283
| 离屏文档 | 有(fetch 代理 + 录制器) | 不可用 |
284284
| 轨迹记录器 | IndexedDB(可选) | IndexedDB(可选)— 相同的 `trace/recorder.js` |

docs/zh-CN/slash-commands.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ WebBrain 接受作为输入框某行开头的斜杠命令。在面板内输入 `
2929
| `/workflow --export <id>` | 下载经过清洗的可移植 `webbrain-workflow/1` JSON 文件 |
3030
| `/workflow --import --file` | 将可移植工作流文件导入为新的本地工作流 |
3131
| `/allow-api` | **按对话的 API 变更覆盖。** 参见[下文](#allow-api)|
32+
| `/foreground [提示词]` | 为视觉兼容性在前台运行一次本地任务 |
3233
| `/dangerously-skip-permissions` | **全局权限提示绕过。** 无需打开设置即可关闭「操作前询问」。在你重新启用该设置之前,WebBrain 将不再按站点弹出提示。 |
3334
| `/compact` | 强制压缩当前对话上下文 |
3435
| `/verbose` | 切换详细/压缩工具显示 |
@@ -55,6 +56,17 @@ WebBrain 接受作为输入框某行开头的斜杠命令。在面板内输入 `
5556
轮询在专用的非活动标签页中进行,因此离开发起页面不会把它导航回被监视的 URL;watch
5657
结束时会关闭该辅助标签页。短暂的轮询失败可以容忍;连续三次失败会停止 watch。
5758

59+
## `/foreground`
60+
61+
常规本地运行会固定在最初的标签页上执行,不会激活该标签页或聚焦其窗口。Chrome 通过
62+
CDP 截图,并仅在该次运行期间模拟焦点;Firefox 使用 `tabs.captureTab` 直接捕获目标
63+
标签页。如果 Chrome 多次返回空白的后台画面,WebBrain 会丢弃该画面,继续使用 DOM
64+
和无障碍数据。
65+
66+
若某个网站无法在后台正确渲染视觉状态,可使用 `/foreground <提示词>` 作为仅对本次
67+
运行生效的兼容模式。它会为该次运行恢复标签页激活和窗口聚焦,不会成为持久设置。
68+
托管 Cloud 运行仍保留现有前台行为,因为其浏览器专用于该任务。
69+
5870
## `/allow-api`
5971

6072
`/allow-api` 会为当前对话解除 UI 优先限制,使智能体在 UI 失败时可通过 `fetch_url`
@@ -77,9 +89,9 @@ WebBrain 接受作为输入框某行开头的斜杠命令。在面板内输入 `
7789
`测试结账流程 /screenshot --save-as checkout.png` 会保存 `checkout-before.png`
7890
`checkout-after.png`;若不带 `--save-as`,WebBrain 使用带时间戳的文件名。
7991

80-
如果运行打开了另一个标签页,WebBrain 会在保存「之后」截图前重新激活发起运行的标签页
81-
如果录制或初始截图无法启动并保存,该运行不会被发送。独立的 `/record`
82-
`/screenshot` 保持原有行为。
92+
对于这个诊断后缀,Chrome 可能会在保存「之后」截图前重新激活发起运行的标签页
93+
Firefox 会直接捕获该标签页而不激活它。如果录制或初始截图无法启动并保存,该运行不会
94+
被发送。独立的 `/record``/screenshot` 保持原有行为。
8395

8496
## 导出、快照与工作流
8597

0 commit comments

Comments
 (0)