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(apps): the Mac's status poll no longer waits on the notification prompt, and tells the Bridge it may notify only when alerts or Notification Center are on; a click lets every running browser come forward when the brand names none, as with Vivaldi, Arc or Chrome for Testing, and brings the browser up when its tab can no longer be reached; on Windows the copy a toast's click starts lets the browser take the front before it hands the link over

Shahriar9b6afb630ff7
diff --git a/docs/internals/mac-app.md b/docs/internals/mac-app.md
index ec33694..a0b038b 100644
--- a/docs/internals/mac-app.md
+++ b/docs/internals/mac-app.md
@@ -45,9 +45,12 @@ When a monitor, a scheduled task or a timer finishes while its browser is out of
hands the notice to the app, which posts it as a macOS notification (`BROWSER_NOTICE`, identifier
`notice:<id>`, so a repeat replaces it). On every socket to a Bridge at protocol 24 or later the app
sends `notices {watch, allowed}`, and again whenever notification permission changes (checked on the
-poll and on activation), so the browser keeps its own card when the app cannot post. On
-`notices-changed` it calls `takeNotices`. A click yields activation to the browser it came from
-(`BrowserApps`, brand to bundle ids) and sends `openNotice`, leaving this window alone.
+poll and on activation, never awaited by the poll, since the first check waits on macOS's prompt).
+`allowed` also needs alerts or Notification Center on, so the browser keeps its own card when nothing
+would appear. On `notices-changed` it calls `takeNotices`. A click yields activation to the browser it
+came from (`BrowserApps`, brand to bundle ids, or every running browser when the brand names none, as
+for Vivaldi and Arc) and sends `openNotice`, leaving this window alone; when the Bridge can no longer
+reach that browser, the click brings the browser itself up.
## The payload
diff --git a/docs/internals/windows-app.md b/docs/internals/windows-app.md
index 499323e..79016e5 100644
--- a/docs/internals/windows-app.md
+++ b/docs/internals/windows-app.md
@@ -126,6 +126,8 @@ it again when `allowed` changes (on the 2 s poll and on focus): whether the AUMI
reports `Enabled`, so a development build says false and the browser keeps its own card. On `notices-changed`
the app calls `takeNotices` and posts each as a toast (`notices.rs`, tagged by id), even while focused.
Its `browsentic://notice/open` link sends `openNotice` only with the nonce minted for it, used once, and never shows the window.
+The copy of the app the click starts calls `AllowSetForegroundWindow(ASFW_ANY)` before it hands the link
+over, since Windows lets only that copy bring a window forward, and the browser is the one that has to.
## Build and test
diff --git a/src/mac/Sources/Browsentic/App/AppModel.swift b/src/mac/Sources/Browsentic/App/AppModel.swift
index a5fa057..99231e4 100644
--- a/src/mac/Sources/Browsentic/App/AppModel.swift
+++ b/src/mac/Sources/Browsentic/App/AppModel.swift
@@ -110,6 +110,7 @@ final class AppModel: ObservableObject {
private var seenPairings: Set<String>?
/// What this socket was last told about notification permission; nil until it is told.
private var noticesReported: Bool?
+ private var reportingNotices = false
var cli: CLI? { node.map(CLI.init) }
var appVersion: String { Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? Payload.bundledVersion ?? "dev" }
@@ -312,7 +313,7 @@ final class AppModel: ObservableObject {
stamp = ExtensionFiles.stamp()
if changed { Task { await loadBrowsers() } }
if status.pairing != nil { await loadPairRequests() }
- await reportNotices()
+ Task { await self.reportNotices() }
} catch {
await control.close()
markOff()
@@ -465,8 +466,11 @@ final class AppModel: ObservableObject {
// MARK: Browser notices
/// Tells the Bridge whether this app can show a browser's notices, again only when that changes.
+ /// Never awaited by the poll: the first time, it waits for the person to answer macOS's prompt.
func reportNotices() async {
- guard NoticeWatch.supported(by: status) else { return }
+ guard !reportingNotices, NoticeWatch.supported(by: status) else { return }
+ reportingNotices = true
+ defer { reportingNotices = false }
let allowed = await PairingAlerts.shared.mayNotify()
guard NoticeWatch.needsReport(allowed: allowed, reported: noticesReported),
(try? await control.notices(allowed: allowed)) != nil
@@ -484,7 +488,7 @@ final class AppModel: ObservableObject {
/// this app active, and since macOS 14 another app comes forward only when the active one yields to it.
func openNotice(_ id: String, from browser: String?) async {
let running = Set(NSWorkspace.shared.runningApplications.compactMap(\.bundleIdentifier))
- if let app = BrowserApps.running(for: browser, among: running) {
+ for app in BrowserApps.yielded(for: browser, among: running) {
NSApp.yieldActivation(toApplicationWithBundleIdentifier: app)
}
if status == nil {
@@ -495,6 +499,9 @@ final class AppModel: ObservableObject {
try await control.openNotice(id)
} catch {
Self.log.notice("openNotice \(id, privacy: .public) from \(browser ?? "an unnamed browser", privacy: .public) was not delivered: \(error.localizedDescription, privacy: .public)")
+ if let app = BrowserApps.named(browser, among: running).first {
+ NSRunningApplication.runningApplications(withBundleIdentifier: app).first?.activate()
+ }
}
}
diff --git a/src/mac/Sources/Browsentic/App/PairingAlerts.swift b/src/mac/Sources/Browsentic/App/PairingAlerts.swift
index 96740f1..b262c80 100644
--- a/src/mac/Sources/Browsentic/App/PairingAlerts.swift
+++ b/src/mac/Sources/Browsentic/App/PairingAlerts.swift
@@ -92,8 +92,11 @@ final class PairingAlerts: NSObject, UNUserNotificationCenterDelegate {
/// Whether the app can post right now, asking once if nobody has decided yet. Never true outside an app bundle.
@MainActor func mayNotify() async -> Bool {
guard let center else { return false }
- let status = await center.notificationSettings().authorizationStatus
- guard status == .notDetermined, !askedForPermission else { return NoticeWatch.allows(status) }
+ let settings = await center.notificationSettings()
+ let visible = settings.alertStyle != .none || settings.notificationCenterSetting == .enabled
+ guard settings.authorizationStatus == .notDetermined, !askedForPermission else {
+ return NoticeWatch.allows(settings.authorizationStatus, visible: visible)
+ }
askedForPermission = true
return (try? await center.requestAuthorization(options: [.alert, .sound])) ?? false
}
diff --git a/src/mac/Sources/Browsentic/Core/Models.swift b/src/mac/Sources/Browsentic/Core/Models.swift
index 498e289..e334d96 100644
--- a/src/mac/Sources/Browsentic/Core/Models.swift
+++ b/src/mac/Sources/Browsentic/Core/Models.swift
@@ -161,7 +161,8 @@ enum NoticeWatch {
static func supported(by status: BridgeStatus?) -> Bool { (status?.protocolVersion ?? 0) >= protocolVersion }
- static func allows(_ status: UNAuthorizationStatus) -> Bool { status == .authorized || status == .provisional }
+ /// Allowed, and somewhere to appear: with alerts off and Notification Center off a notice shows nowhere.
+ static func allows(_ status: UNAuthorizationStatus, visible: Bool) -> Bool { (status == .authorized || status == .provisional) && visible }
/// Nil `reported` is a socket that has not been told yet.
static func needsReport(allowed: Bool, reported: Bool?) -> Bool { reported != allowed }
@@ -183,6 +184,11 @@ enum BrowserApps {
"Vivaldi": ["com.vivaldi.Vivaldi"],
"Arc": ["company.thebrowser.Browser"],
"Firefox": ["org.mozilla.firefox", "org.mozilla.firefoxdeveloperedition", "org.mozilla.nightly"],
+ "Google Chrome for Testing": ["com.google.chrome.for.testing"],
+ "Zen": ["app.zen-browser.zen"],
+ "LibreWolf": ["io.gitlab.librewolf-community"],
+ "Waterfox": ["net.waterfox.waterfox"],
+ "Floorp": ["one.ablaze.floorp"],
]
static func candidates(for brand: String?) -> [String] {
@@ -190,9 +196,16 @@ enum BrowserApps {
return bundleIds.first { $0.key.caseInsensitiveCompare(brand) == .orderedSame }?.value ?? []
}
- /// The running app the notice came from; an unknown brand, or none of its apps running, names nothing.
- static func running(for brand: String?, among running: Set<String>) -> String? {
- candidates(for: brand).first(where: running.contains)
+ /// The running apps of the brand the notice came from; an unknown brand, or none of its apps running, names none.
+ static func named(_ brand: String?, among running: Set<String>) -> [String] {
+ candidates(for: brand).filter(running.contains)
+ }
+
+ /// Those, or every running browser when they are none, since Vivaldi and Arc report no brand of their own:
+ /// only the browser the notice came from asks to come forward.
+ static func yielded(for brand: String?, among running: Set<String>) -> [String] {
+ let named = named(brand, among: running)
+ return named.isEmpty ? bundleIds.values.flatMap { $0 }.filter(running.contains).sorted() : named
}
}
diff --git a/src/mac/Tests/BrowsenticTests/ModelTests.swift b/src/mac/Tests/BrowsenticTests/ModelTests.swift
index b3ba5c0..b93d3d5 100644
--- a/src/mac/Tests/BrowsenticTests/ModelTests.swift
+++ b/src/mac/Tests/BrowsenticTests/ModelTests.swift
@@ -436,11 +436,12 @@ import Testing
#expect(NoticeWatch.needsReport(allowed: false, reported: true))
}
- @Test func onlyAGrantedPermissionLetsTheAppShowNotices() {
- #expect(NoticeWatch.allows(.authorized))
- #expect(NoticeWatch.allows(.provisional))
- #expect(!NoticeWatch.allows(.denied))
- #expect(!NoticeWatch.allows(.notDetermined))
+ @Test func onlyAGrantedPermissionWithSomewhereToAppearLetsTheAppShowNotices() {
+ #expect(NoticeWatch.allows(.authorized, visible: true))
+ #expect(NoticeWatch.allows(.provisional, visible: true))
+ #expect(!NoticeWatch.allows(.authorized, visible: false))
+ #expect(!NoticeWatch.allows(.denied, visible: true))
+ #expect(!NoticeWatch.allows(.notDetermined, visible: true))
}
@Test func aRepeatOfTheSameEventReplacesItsNotification() {
@@ -465,16 +466,22 @@ import Testing
#expect(Set(ids).count == ids.count)
}
- @Test func theRunningChannelIsTheOneThatComesForward() {
- #expect(BrowserApps.running(for: "Google Chrome", among: ["com.google.Chrome.canary", "com.apple.Safari"]) == "com.google.Chrome.canary")
- #expect(BrowserApps.running(for: "Google Chrome", among: ["com.google.Chrome", "com.google.Chrome.beta"]) == "com.google.Chrome")
- #expect(BrowserApps.running(for: "microsoft edge", among: ["com.microsoft.edgemac.Dev"]) == "com.microsoft.edgemac.Dev")
+ @Test func everyRunningChannelOfTheBrandMayComeForward() {
+ #expect(BrowserApps.yielded(for: "Google Chrome", among: ["com.google.Chrome.canary", "com.apple.Safari"]) == ["com.google.Chrome.canary"])
+ #expect(BrowserApps.yielded(for: "Google Chrome", among: ["com.google.Chrome", "com.google.Chrome.beta"]) == ["com.google.Chrome", "com.google.Chrome.beta"])
+ #expect(BrowserApps.yielded(for: "microsoft edge", among: ["com.microsoft.edgemac.Dev"]) == ["com.microsoft.edgemac.Dev"])
}
- @Test func anUnknownBrandOrABrowserNotRunningYieldsToNothing() {
- #expect(BrowserApps.running(for: "Netscape", among: ["com.google.Chrome"]) == nil)
- #expect(BrowserApps.running(for: nil, among: ["com.google.Chrome"]) == nil)
- #expect(BrowserApps.running(for: "chrome-extension://abc", among: ["com.google.Chrome"]) == nil)
- #expect(BrowserApps.running(for: "Brave", among: ["com.google.Chrome"]) == nil)
+ @Test func aBrandThatNamesNoRunningAppLetsEveryRunningBrowserComeForward() {
+ let running: Set<String> = ["com.vivaldi.Vivaldi", "company.thebrowser.Browser", "com.apple.Safari"]
+ #expect(BrowserApps.yielded(for: "Chromium", among: running) == ["com.vivaldi.Vivaldi", "company.thebrowser.Browser"])
+ #expect(BrowserApps.yielded(for: nil, among: ["com.google.chrome.for.testing"]) == ["com.google.chrome.for.testing"])
+ #expect(BrowserApps.yielded(for: "Netscape", among: ["com.apple.Safari"]) == [])
+ }
+
+ @Test func onlyTheBrandItselfIsBroughtUpWhenTheClickCannotReachItsTab() {
+ #expect(BrowserApps.named("Brave", among: ["com.brave.Browser", "com.google.Chrome"]) == ["com.brave.Browser"])
+ #expect(BrowserApps.named("chrome-extension://abc", among: ["com.google.Chrome"]) == [])
+ #expect(BrowserApps.named(nil, among: ["com.google.Chrome"]) == [])
}
}
diff --git a/src/windows/src-tauri/src/main.rs b/src/windows/src-tauri/src/main.rs
index ce1d244..3ad5497 100644
--- a/src/windows/src-tauri/src/main.rs
+++ b/src/windows/src-tauri/src/main.rs
@@ -304,6 +304,9 @@ fn main() {
if std::env::args().any(|arg| arg == "--uninstall") {
return prepare_uninstall();
}
+ if std::env::args().any(|arg| notices::parse(&arg).is_some()) {
+ toast::yield_foreground();
+ }
tauri::Builder::default()
.plugin(tauri_plugin_single_instance::init(|app, args, _| second_launch(app, args)))
.plugin(tauri_plugin_deep_link::init())
diff --git a/src/windows/src-tauri/src/toast.rs b/src/windows/src-tauri/src/toast.rs
index 690c8ce..70b1143 100644
--- a/src/windows/src-tauri/src/toast.rs
+++ b/src/windows/src-tauri/src/toast.rs
@@ -82,6 +82,16 @@ pub fn enabled(app_id: &str) -> bool {
windows_toasts::enabled(app_id).unwrap_or(false)
}
+/// Only the copy a click started may bring a window forward, and the browser has the tab to bring back.
+#[cfg(windows)]
+pub fn yield_foreground() {
+ use windows_sys::Win32::UI::WindowsAndMessaging::{AllowSetForegroundWindow, ASFW_ANY};
+ unsafe { AllowSetForegroundWindow(ASFW_ANY) };
+}
+
+#[cfg(not(windows))]
+pub fn yield_foreground() {}
+
#[cfg(not(windows))]
pub fn post(_: &str, _: &str, _: Option<(&str, &str)>) {}