Manage opening urls in different browsers.
Browser Dispatch lets you open urls in the browser/profile/settings of your choice based on patterns. For example, you can use it to keep Firefox as your default browser, but open all Google products (meet, calendar, mail, drive, ...) in Chrome. Or open all work related domains with Opera, or always using incognito/anonymous browsing for certain domains...
While the primary motivation to create it was managing browsers, it can actually be used to "dispatch" any kind of files with any application. For example, it could be setup to open all images under ~/Pictures/MyWork with GIMP, while anywhere else they would open with the default previewer. Or open all audio files with a certain name pattern to open with Audacity, and so on.
It is meant to be set as your default browser, and then dispatch to the relevant installed browser on your system, based on configurable rules.
Browser Dispatch relies on https://www.freedesktop.org/ specifications, so should work in any variants that support xdg-utils (Linux, FreeBSD, DragonFly, etc).
There is no support for Windows or Mac OS.
It is written in Go, and has no dependencies on external modules besides the standard libraries.
Download the binaries for your architecture from https://gitlab.com/pm98zz-c/browser-dispatch/-/releases/permalink/latest, and extract them anywhere disposable. You should have two binaries files:
- browser-dispatch
- browser-dispatch-config
From the command line, run browser-dispatch-config install self
.
This will prompt you to install both of them in a location under your user's $PATH.
If you get a message that no installation path can be found, you can either:
- create a local binary path for your user, (eg
~/.bin
) and make sure you add it to your $PATH, then runbrowser-dispatch-config install self
again. - run the command with privileges to install to a system-wide location (eg.
/usr/local/bin
), withsudo browser-dispatch-config install self
.
You can now get rid of the downloaded files.
If you prefer to build the binaries from source, all you'll need is the https://go.dev/ environment. You can clone the repository and
go build -o build/browser-dispatch cmd/*
go build -o build/browser-dispatch-config cli/*
Start by creating a default configuration file, by running browser-dispatch-config generate configuration
.
This will scan your system to see which browsers are available and add them to the configuration.
You can check the available found executables with browser-dispatch-config list executables
, which should output something similar to:
Executables:
- com.google.Chrome : /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=/app/bin/chrome --file-forwarding com.google.Chrome
- io.github.ungoogled_software.ungoogled_chromium : /usr/bin/flatpak run --branch=stable --arch=x86_64 --command=/app/bin/chromium --file-forwarding io.github.ungoogled_software.ungoogled_chromium
- org.mozilla.firefox : firefox
You can pick the one you want to use by default, when no rule is matched, with browser-dispatch-config set default-executable
.
You're now ready to add your rules, and then define "Browser Dispatch" as your default browser.
There are four types of matching you can use for rules:
- starts with
- contains
- ends with
- regex
To add a rule, use browser-dispatch-config add rule
, and follow the prompts to set:
- the rule type (eg "starts with")
- the rule pattern (eg "https://example.com")
- the rule position (rules are evaluated in order)
- which executable to use if the rule matches
Before setting Browser Dispatch as your default browser, manually test that your rules work as expected, by manually calling the main command with the urls you want to match with:
browser-dispatch https://example.com/?page1
browser-dispatch https://meet.google.com/xyz
...
When you install a new browser, or remove one, the list of available executables (as seen with browser-dispatch-config list executables
) needs to be updated.
Running browser-dispatch-config scan executables
will scan the system to add newly found entry.
There is currently no way of automatically remove an uninstalled entry, as it would prevent the creation of "customized" entries. You need to manually remove them from the list with browser-dispatch-config remove executable
and recreate the associated rules.
Assuming Google Chrome is installed, and has been automatically added as "com.google.Chrome" by browser-dispatch-config scan executables
.
Add a rule and follow the prompts:
browser-dispatch-config add rule
- select the "starts with" type
- type "https://meet.google.com/" as the pattern
- select "com.google.Chrome" as the executable ID
- select any position
Running browser-dispatch https://meet.google.com/xyz
should now open in Google Chrome instead of the default browser.
Lets say you have your dev websites setup on the .local tld, and you always want to open a private window for testing purposes.
Start by creating a new executable, to be able to pass the "--private-window" argument, and follow the prompts:
browser-dispatch-config add executable
- define a unique ID. We'll use "firefox-private" here.
- add your command with the needed flags: "/usr/bin/firefox --private-window"
Check with browser-dispatch-config list executables
that it got added properly.
Now add a rule and follow the prompts again:
browser-dispatch-config add rule
- select the "ends with" type
- type ".local" as the pattern
- select our new "firefox-private" as the executable
- select any position
Running browser-dispatch https://www.mydev.local
should now open in a private window.
- Links within a browser still open within the same browser: Browser Dispatch operates when the system matches the resource type with the associated executable. That means it cannot do anything within applications. Overcoming this should be possible with a companion browser extension to manipulate links.
- Redirection detection: some apps manipulate links for tracking purposes (typically, the Slack app), which means the rules won't match as they pass an obscufated url instead of the original one. This can usually be bypassed by "Ctrl+clicking" the link. This could potentially be dealt with by making an initial http request to check the destination, but would intensive and probably fragile.