Skip to content

fix(browser): support wrapped Exec commands in browser and webapp launchers - #11728

Closed
harshithnadig wants to merge 2 commits into
omacom:quattrofrom
harshithnadig:fix/issue-11718-wrapped-browser-exec
Closed

harshithnadig wants to merge 2 commits into
omacom:quattrofrom
harshithnadig:fix/issue-11718-wrapped-browser-exec

Conversation

@harshithnadig

Copy link
Copy Markdown

What problem does this solve?

Fixes #11718.

When a default web browser's .desktop entry has a wrapped Exec= command (such as Flatpaks like Exec=/usr/bin/flatpak run org.mozilla.firefox %u or wrapper scripts like Exec=/usr/bin/env python3 /path/to/browser.py %u), omarchy-launch-browser and omarchy-launch-webapp stripped away everything after the first whitespace token via:

sed -n 's/^Exec=\([^ ]*\).*/\1/p'

This reduced the command to bare /usr/bin/flatpak or /usr/bin/env with no subcommands or arguments. Because systemd-run routed stdout/stderr to null, keybindings like SUPER+SHIFT+RETURN, SUPER+SHIFT+B, and URL openings silently failed with zero feedback.

How is it solved?

  1. Tokenize and preserve full Exec line: Parses the entire Exec= line respecting quotes, maintaining wrapper commands, subcommands, and flags.
  2. Freedesktop field code handling: Correctly replaces %u or %U with the target URL when present, or omits them when launching empty.
  3. Private browsing flag placement: Dynamically injects --private-window, --inprivate, or --incognito in front of the URL parameter for both native and containerized browsers.
  4. Window focus regex: Resolves window focus regex against wrapper subcomponents and flatpak IDs.
  5. Applies to webapp launcher: Updated bin/omarchy-launch-webapp with matching command line preservation.
  6. Automated test coverage: Added test assertions to test/shell.d/launch-browser-test.sh verifying flatpak wrapped commands and private browsing flags.

…nchers

- Parse and preserve complete Exec command line from desktop files instead of slicing off first whitespace token
- Properly substitute %u / %U field codes with URL argument or omit when empty
- Correctly position private browsing flag for both native and containerized browsers
- Enhance app focus pattern resolution to match flatpak IDs and wrapped binaries
- Add automated regression tests in launch-browser-test.sh

Fixes omacom#11718
@llstrk

llstrk commented Sep 30, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Outcome: The Exec parser splits quoted arguments, and installed Flatpak browsers are still not found.

Quoted Exec arguments are split

parse_exec_line splits at spaces inside quotes, so "/opt/Example Browser/chromium" becomes two arguments in both launchers. Impact: entries quoting a path or argument with a space launch the wrong command.

Suggested change: elif [[ ($char == ' ' || $char == $'\t') && $in_single -eq 0 && $in_double -eq 0 ]]; then.

Reproducer (fails at d87d9f8)

Save as test/shell.d/launch-browser-quoted-exec-test.sh and run it with bash.

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT

mock_bin="$test_tmp/bin"
test_home="$test_tmp/home"
mkdir -p "$mock_bin" "$test_home/.local/share/applications"

# Log one argument per line, so argument boundaries are visible.
cat >"$mock_bin/systemd-run" <<'SH'
#!/bin/bash
printf '%s\n' "$@" >"$OMARCHY_TEST_LAUNCH"
SH
cp "$mock_bin/systemd-run" "$mock_bin/setsid"
cat >"$mock_bin/xdg-settings" <<'SH'
#!/bin/bash
echo chromium.desktop
SH
cat >"$mock_bin/omarchy-hyprland-focus-app" <<'SH'
#!/bin/bash
exit 0
SH
chmod +x "$mock_bin"/*

# Desktop Entry spec, "The Exec key": an argument containing a space is quoted
# in whole and passed to the program as one argument.
cat >"$test_home/.local/share/applications/chromium.desktop" <<'EOF'
[Desktop Entry]
Exec="/opt/Example Browser/chromium" "--user-data-dir=/tmp/Example Profile" %U
EOF

problems=""
for launcher in omarchy-launch-browser omarchy-launch-webapp; do
  log="$test_tmp/$launcher"
  HOME="$test_home" PATH="$mock_bin:$PATH" OMARCHY_TEST_LAUNCH="$log" \
    bash "$ROOT/bin/$launcher" "https://example.test/quoted"
  if ! grep -Fxq -- '/opt/Example Browser/chromium' "$log" ||
    ! grep -Fxq -- '--user-data-dir=/tmp/Example Profile' "$log"; then
    problems+="$launcher ran:"$'\n'"$(sed -n '/^--$/,$p' "$log" | tail -n +2)"$'\n'
  fi
done

[[ -z $problems ]] || fail "launchers keep quoted Exec arguments whole" "$problems"
pass "launchers keep quoted Exec arguments whole"

Output at d87d9f8 (exit status 1):

omarchy-launch-browser ran:
/opt/Example
Browser/chromium
--user-data-dir=/tmp/Example
Profile
https://example.test/quoted
omarchy-launch-webapp ran:
/opt/Example
Browser/chromium
--user-data-dir=/tmp/Example
Profile
--app=https://example.test/quoted

not ok - launchers keep quoted Exec arguments whole

With the suggested change it prints ok - launchers keep quoted Exec arguments whole, and the PR's own test still passes.

Installed Flatpak browsers are not found

Flatpak exports entries to XDG_DATA_DIRS paths the lookup never searches, so the fallback runs uwsm-app -- org.mozilla.firefox.desktop --private-window URL. Impact: uwsm makes the flag a file:// URL, so --private URL opens the URL in a normal window.

Suggested change: also search XDG_DATA_HOME and XDG_DATA_DIRS, and refuse private launches when only the desktop ID is known.

Reproducer (fails at d87d9f8)

Save as test/shell.d/launch-browser-flatpak-export-test.sh and run it with bash.

#!/bin/bash

set -euo pipefail

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

test_tmp=$(mktemp -d)
trap 'rm -rf "$test_tmp"' EXIT

mock_bin="$test_tmp/bin"
test_home="$test_tmp/home"
# Flatpak exports desktop files here (added to XDG_DATA_DIRS), not to
# ~/.local/share/applications.
exports="$test_home/.local/share/flatpak/exports/share/applications"
mkdir -p "$mock_bin" "$exports"

cat >"$mock_bin/systemd-run" <<'SH'
#!/bin/bash
printf '%s\n' "$@" >"$OMARCHY_TEST_LAUNCH"
SH
cat >"$mock_bin/xdg-settings" <<'SH'
#!/bin/bash
echo org.mozilla.firefox.desktop
SH
cat >"$mock_bin/omarchy-hyprland-focus-app" <<'SH'
#!/bin/bash
exit 0
SH
chmod +x "$mock_bin"/*

# The Exec line Flatpak writes for an exported Firefox.
cat >"$exports/org.mozilla.firefox.desktop" <<'EOF2'
[Desktop Entry]
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u %u @@
EOF2

launch_log="$test_tmp/launch"
# Flatpak's env.d adds its export dirs to XDG_DATA_DIRS the same way.
HOME="$test_home" PATH="$mock_bin:$PATH" OMARCHY_TEST_LAUNCH="$launch_log" \
  XDG_DATA_DIRS="$test_home/.local/share/flatpak/exports/share:/usr/local/share:/usr/share" \
  bash "$ROOT/bin/omarchy-launch-browser" --private "https://example.test/private"

command=$(sed -n '/^--$/{n;p;q}' "$launch_log")
[[ $command == /usr/bin/flatpak ]] ||
  fail "browser launcher runs the Exec of an exported Flatpak browser" "$(sed -n '/^--$/,$p' "$launch_log")"
pass "browser launcher runs the Exec of an exported Flatpak browser"

Output at d87d9f8 (exit status 1):

--
org.mozilla.firefox.desktop
--private-window
https://example.test/private
not ok - browser launcher runs the Exec of an exported Flatpak browser

What uwsm-app expands that fallback to, run with python3 on an Omarchy install (uwsm and python-pyxdg installed):

import sys, tempfile
sys.path.insert(1, "/usr/share/uwsm/modules")  # where the uwsm package installs its modules
from xdg.DesktopEntry import DesktopEntry
from uwsm.main import gen_entry_args

# What `uwsm-app -- org.mozilla.firefox.desktop --private-window <url>` expands to.
with tempfile.NamedTemporaryFile("w", suffix=".desktop") as entry:
    entry.write("[Desktop Entry]\nType=Application\nName=Firefox\n"
                "Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=firefox "
                "--file-forwarding org.mozilla.firefox @@u %u @@\n")
    entry.flush()
    command, instances = gen_entry_args(DesktopEntry(entry.name), ["--private-window", "https://example.test/private"])
    for args in instances:
        print(command, *args)

Output (uwsm 0.26.7-1, python-pyxdg 0.28-7):

/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u file://--private-window @@
/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=firefox --file-forwarding org.mozilla.firefox @@u https://example.test/private @@

Looking the entry up through XDG_DATA_HOME, ~/.nix-profile/share and XDG_DATA_DIRS makes this test pass; when XDG_DATA_HOME is set in the environment, the PR's test then also needs export XDG_DATA_HOME="$test_home/.local/share", as quattro's version has.

More findings

Conflicts with quattro. #13520 and #13530 changed both launchers, and #13530 the test, adding omarchy-cmd-default-browser and omarchy-cmd-browser-handoff. Impact: the branch does not apply to current quattro, and a resolution that keeps the PR's lookup block would undo #13520. Suggested change: rebase, keeping omarchy-cmd-default-browser and passing the parsed "${cmd[@]}" to omarchy-cmd-browser-handoff before the existing launch fallback.

Checked resolution: if ! omarchy-cmd-browser-handoff "${cmd[@]}"; then systemd-run ... uwsm-app -- "${cmd[@]}"; fi (webapp: same with --app="$1" "${@:2}" and exec setsid). A hand rebase done this way passes the merged test (with the checkout's bin on PATH).

Private flag is picked from the whole Exec line. The Mozilla/edge regexes scan every argument and the --help probe runs the wrapper, so env MOZ_ENABLE_WAYLAND=1 zen %u gets --incognito (wrapped entries failed completely before) and brave --profile-directory=Ledger gets --inprivate (the base sent --incognito). Impact: the browser gets another browser's private flag, so the private request is lost. Suggested change: detect from the resolved browser token (skip env and VAR=val, use the Flatpak app ID).

Details

Verified:

  • env VAR=val brave %U and Flatpak-style Exec lines in ~/.local/share/applications now launch the full command in both launchers.
  • Native Chromium, Chrome, Brave, Edge, Firefox and Zen entries get the same argv and focus regex as before, except URL --private is reordered to --private-flag URL and extra URLs are dropped.
  • No eval; the metacharacter Exec stays literal.
  • The PR test passes at the head and fails on the base scripts at the Flatpak assertion.

Optional notes:

Other open PRs for this issue

Review information

Test scope: Source and sandbox tests with stubs at d87d9f8; no real browser or Flatpak.

AI process: Opus 5.5 Medium coordination and synthesis, Opus 5.5 Xhigh technical review and final fact check, GPT 6 Sol Xhigh search for related issues, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed against quattro at d87d9f8, by reading the diff alongside the three other open pull requests that fix #11718 and its webapp twin #10988: #12533 (both launchers, with tests) and #13240 with #13241 (one launcher each). The tests were not run on a worker, because this one is not the fix being taken forward.

The bug is real and still on quattro: both launchers keep only the first token of Exec=, so env … and flatpak run … entries launch the bare wrapper. Here is what this branch does with it:

  • Quoted arguments are still split. The whitespace branch in parse_exec_line never checks in_single/in_double, so Exec="/opt/My Browser/chromium" %U or a quoted --user-data-dir with a space becomes two arguments, in both launchers. Single quotes are also treated as quoting, which the Desktop Entry spec does not do.
  • Caller arguments are dropped. Only the first argument that is not --private survives, so URL1 URL2 loses the second URL and --new-window URL loses the URL. That affects ordinary native browsers, not just wrapped ones.
  • The private flag is picked from the whole Exec line. The Mozilla and edge patterns match any argument, so brave --profile-directory=Ledger gets --inprivate, and chromium --user-data-dir=/tmp/firefox gets --private-window. Wrapped Zen falls through to probing env --help or flatpak --help and gets --incognito.
  • It no longer applies to quattro. Read the default browser from mimeapps.list when launching #13520 and Hand browser and web app launches to the running browser directly #13530 replaced the default-browser lookup with omarchy-cmd-default-browser and added omarchy-cmd-browser-handoff in both launchers.

I compared the four fixes, and so did Codex at medium effort, which reviewed them separately and was not given my conclusion. It is a second reading, but its independence is not guaranteed. We agree that #12533 is the one to take forward. It is the smallest change, it keeps every caller argument and the existing private-flag probe and focus behaviour for native browsers, and it tests both launchers. It still has to be ported onto quattro and taught to keep quoted arguments whole before it is ready. #13240 and #13241 keep quoted spaces, but they still probe and focus the wrapper (env, flatpak) instead of the browser, they reorder caller arguments, and they add no tests.

This waits on the maintainer to choose between the competing fixes. Nothing is asked of you right now. If #12533 lands, it covers what this pull request set out to fix.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this, @harshithnadig. #12533 fixes the same problem in a way the review judged better, so this is closed in favour of it. If it does not cover your case, please say so there.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

omarchy-launch-browser silently fails when the default browser's Exec= is wrapped (env, flatpak, ...)

3 participants