Skip to content
TheChatArchiveThe Chat Archive
o1-preview-2024-09-12· OpenAIAi2 WildChat-4.8M (AI2)

Hi there. I have blocked browser callings in my system with these methods: 1. export…

  1. User

    Hi there.

    I have blocked browser callings in my system with these methods:

    1. export BROWSER=/bin/true in my .bashrc

    and

    1. 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 nothing
    

    Still 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 picard command) 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?

  2. Assistant

    To completely prevent applications from opening links in an external browser, you need to override the default URL handlers for http and https schemes 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.

    1. Create the Desktop Entry File

      Create a file named NoBrowser.desktop in ~/.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
      
    2. 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/true specifies a command that does nothing and exits successfully.
      • NoDisplay=true hides the application from application menus.
      • MimeType associates the application with the http and https URL schemes.
    3. 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.desktop application as the default handler for http and https URLs.

    1. Use xdg-mime to Set the Default Handler

      Run the following commands:

      xdg-mime default NoBrowser.desktop x-scheme-handler/http
      xdg-mime default NoBrowser.desktop x-scheme-handler/https
      

      This sets NoBrowser.desktop as the default application for handling http and https schemes.

    2. Alternatively, Use gio (GNOME Specific)

      If you prefer or if xdg-mime doesn't work as expected, you can use GNOME's gio command:

      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/https
      

      Both commands should output NoBrowser.desktop.

    • Check with gio:

      gio mime x-scheme-handler/http
      gio mime x-scheme-handler/https
      

      The 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 firefox or xdg-open explicitly). 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: