Hi there. I have blocked browser callings in my system with these methods: 1. export…
- User
Hi there.
I have blocked browser callings in my system with these methods:
export BROWSER=/bin/truein my .bashrc
and
- linking default browser in system settings to this launcher:
[Desktop Entry] Name=Do Nothing Exec=/bin/bash -c "notify-send 'Doing nothing'; /bin/true" Type=Application NoDisplay=true StartupNotify=Doing nothingStill some apps invoke an external browser (Firefox) when I accidentally click links in them. One of those apps is Picard. I've tried to run it from CLI (via
picardcommand) to see how it invokes the browser but it seems it does it only when launched from GUI.I'm running Arch Linux based distro with GNOME on Wayland. How to completely block link openings in an external browser from apps?
- Assistant
To completely prevent applications from opening links in an external browser, you need to override the default URL handlers for
httpandhttpsschemes to point to a do-nothing application. This ensures that any application trying to open a web link using the standard system mechanisms will effectively do nothing instead. Here's how you can set this up on your Arch Linux system with GNOME on Wayland:Step 1: Create a Do-Nothing Application
Create a desktop entry for a do-nothing application that will act as the handler for web URLs.
-
Create the Desktop Entry File
Create a file named
NoBrowser.desktopin~/.local/share/applications/(you may need to create this directory if it doesn't exist):mkdir -p ~/.local/share/applications/ nano ~/.local/share/applications/NoBrowser.desktop -
Add the Following Content to
NoBrowser.desktop[Desktop Entry] Type=Application Name=Do Nothing Exec=/bin/true NoDisplay=true MimeType=x-scheme-handler/http;x-scheme-handler/https;Exec=/bin/truespecifies a command that does nothing and exits successfully.NoDisplay=truehides the application from application menus.MimeTypeassociates the application with thehttpandhttpsURL schemes.
-
Update the Desktop Database
Update the MIME database to recognize the new desktop entry:
update-desktop-database ~/.local/share/applications/
Step 2: Set the Do-Nothing Application as the Default URL Handler
Now, configure your system to use the
NoBrowser.desktopapplication as the default handler forhttpandhttpsURLs.-
Use
xdg-mimeto Set the Default HandlerRun the following commands:
xdg-mime default NoBrowser.desktop x-scheme-handler/http xdg-mime default NoBrowser.desktop x-scheme-handler/httpsThis sets
NoBrowser.desktopas the default application for handlinghttpandhttpsschemes. -
Alternatively, Use
gio(GNOME Specific)If you prefer or if
xdg-mimedoesn't work as expected, you can use GNOME'sgiocommand:gio mime x-scheme-handler/http NoBrowser.desktop gio mime x-scheme-handler/https NoBrowser.desktop
Step 3: Verify the Default URL Handlers
Ensure that the default handlers have been set correctly.
-
Check with
xdg-mime:xdg-mime query default x-scheme-handler/http xdg-mime query default x-scheme-handler/httpsBoth commands should output
NoBrowser.desktop. -
Check with
gio:gio mime x-scheme-handler/http gio mime x-scheme-handler/httpsThe output should include
Default application for “x-scheme-handler/http”: NoBrowser.desktop.
Step 4: Test the Configuration
Try clicking a link in an application like Picard to see if it still opens the browser. With this configuration, the application should no longer launch the browser when you click a link.
Additional Considerations
-
Applications That Bypass the System Default:
Some applications may not respect the system's default URL handlers and might invoke browsers directly (e.g., by calling
firefoxorxdg-openexplicitly). In such cases, additional steps are necessary. -
Renaming Browser Binaries (Not Recommended):
You could rename or remove browser binaries like Firefox, but this approach is intrusive and may cause system issues or prevent you from using the browser when needed.
-
Restricting Execution with AppArmor or SELinux:
Advanced users can create security policies to prevent specific applications from launching browsers. This requires a deep understanding of security frameworks and is beyond the scope of this solution.
Summary
By creating a do-nothing application and setting it as the default handler for web URLs, you effectively prevent applications from opening links in your browser. This method relies on the standard system mechanisms for handling URL schemes and should work for most applications on your GNOME desktop environment.
Note: Always ensure you have backups or can revert changes when modifying system settings or configurations.
References:
xdg-mimemanual:man xdg-mimegiomanual:man gio- Freedesktop.org specifications: https://www.freedesktop.org/wiki/
-