In Tauri v2, the JS listen() receives emit_to events addressed to other windows
A two-window test on tauri 2.11.2 where emit_to("a") also ran a plain JS listen() handler in window b, and the listener call that scopes it.
app.emit_to("a", …) in Tauri v2 filters on the target each listener registered with. The JS listen() from @tauri-apps/api/event registers as Any unless you pass a target: the reference says the option "defaults to { kind: 'Any' }" and that Any "matches every target (the default)". A handler in window b that used plain listen() runs for an event sent to a.
A test app with two hidden windows, a and b, built on tauri 2.11.2 with withGlobalTauri, ran this in each:
const { listen } = window.__TAURI__.event;
const { invoke } = window.__TAURI__.core;
const me = window.__TAURI__.webviewWindow.getCurrentWebviewWindow();
await listen('open-file', () => invoke('report', { who: `${me.label}: listen` }));
await me.listen('open-file', () => invoke('report', { who: `${me.label}: me.listen` }));
await invoke('ready');
Once both were ready, Rust called app.emit_to("a", "open-file", "/tmp/x.md") once and printed what was reported. On macOS 26.6.2 that was a: listen, a: me.listen and b: listen, four runs out of four. Nothing from b: me.listen.
The match is one line, the body of match_any_or_filter in src/event/listener.rs: *target == EventTarget::Any || filter.as_ref().map(|f| f(target)).unwrap_or(true). target is the listener's and filter comes from the emit (plain emit passes none), so a listener registered as Any matches before the emit's filter is called. emit_js_filter puts every JS handler in every webview through it.
Building the test app needed an existing app's Cargo.lock. A new crate pinning only tauri = "=2.11.2" resolved tauri-runtime 2.12.1 and tauri-utils 2.10.1 on 2026-10-04 and did not compile.
The note under emit_to
The section of the guide that introduces emit_to ends with a note: "Webview-specific events are not triggered to regular global event listeners. To listen to any event you must use the listen_any function instead of listen". That note is about Rust. listen_any is a method on the Rust Listener trait, and Rust's listen on a window is scoped: a cargo test on Tauri's mock runtime with a.listen, b.listen and b.listen_any ran a.listen and b.listen_any for the same emit. The JS API has no listen_any; plain listen() already is the catch-all. Further down the same page the JS listen sits under "Listening to global events", beside getCurrentWebviewWindow().listen under "Listening to webview-specific events".
Finder double-click, 2026-08-24
Noteline is a Markdown editor built on Tauri in which a window has at most one folder open. On 2026-08-24, double-clicking a .md in Finder did nothing while a window was open.
The open-file event was broadcast with emit. Since 2026-07-10 a window whose folder held the file claimed it, and if no claim arrived within 200 ms the window labelled main opened a new one. We had tied that fallback to a label. Open a file into a new window (main-1), close the original, and there is no main. A file outside every open folder was dropped as long as no window was labelled main. A test build under a different bundle identifier, driven with open -a, logged branch=NONE (dropped).
We moved the choice into Rust. Each window registers its folder, and Rust sends the path with emit_to(&label, "noteline:open-file", path) to the live window whose folder contains it, or opens a new window. Our commit message says the frontend had no way to know which windows were alive, but getAllWebviewWindows() returns them and the July code never called it.
The same logging then showed the handler running in every open window for one emit_to. The window that did not own the file found the path outside its folder and asked for a new window. The duplicate was never in a release; the fix is in the same commit, which went out in desktop 0.2.28 on 2026-08-31. The listener was still the global listen from the broadcast design. The committed version:
const me = getCurrentWebviewWindow();
unOpen = await me.listen<string>('noteline:open-file', (e) => {
if (e.payload) void routeOpenRef.current(e.payload);
});
getCurrentWebviewWindow().listen calls the same listen with { kind: 'WebviewWindow', label: this.label }.
If a window tells Rust which folder it holds before its listener is attached, a path sent in that gap goes to a window with no handler. A running app has no buffer to recover it from, so each window registers its folder only after listen resolves. A review caught that gap before the commit.
A comment that does not fit
The app's lib.rs still has a comment from 2026-06-12, when menu events went from emit_to back to plain emit. It says emit_to with a window label is not delivered to a module-level listen, and that this was verified. Neither the comment nor the commit message records how. That is the opposite symptom on the same versions (tauri 2.11.2, @tauri-apps/api 2.11.0), and in the test app the plain listen() in window a did receive the event. The menu path has not been re-tested.