Skip to content

Instantly share code, notes, and snippets.

@NiklasBeierl
Last active March 10, 2023 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NiklasBeierl/7fcc012b00e148c7dd33f9a03ac3c44e to your computer and use it in GitHub Desktop.
Save NiklasBeierl/7fcc012b00e148c7dd33f9a03ac3c44e to your computer and use it in GitHub Desktop.
Keep making a mess of your tabs and accidentally closing your messengers? I might have a solution for you!

Motivation

There are a bunch of web apps that I generally like to keep open when working on my computer. Mostly messengers: Slack, multiple instances of mattermost, etc. But I usually make a mess of my browser windows and tabs, so I end up opening these apps multiple times or accidentally closing them. This is my attempt to nudge me back to sanity.

Goals:

  • Open all my important apps in a single chromium window with a single click
  • Prevent me from accidentally closing any of these apps
  • Prevent me from cluttering up this window

Prerequistes:

You might be able to translate some of this to windows and other browsers, but this guide was created with:

  • Chromium
  • Linux

Steps:

1. Create a designated chromium profile

Top rigt corner (Next to the vertical dots) -> Add profile (Referred to as apps-profile)

2. Set all of your apps as start pages

In a chromium window using the apps-profile.
Goto: chrome://settings/onStartup -> Open a specific page or set of pages
Hint: The tabs will open in the order in which you add them here, but you can not reorder them here! :(

3. Prevent yourself from accidentally closing these pages:

Install the Tampermonkey Extension.
Add this user script:

// ==UserScript==
// @name         PreventClose
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Prompt before closing tab
// @author       Niklas Beierl
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    const originsToPrompt = [];

    function onBeforeUnload(e) {
        e.returnValue = "Modern Browsers will ignore this string.";
    }
    window.addEventListener('beforeunload', onBeforeUnload);
})();

This activates the "Changes you made may not be saved."-prompt on any pages you will choose in the next step: In the settings tab for that user script, add all of your apps, to "User matches". So if you want to prevent yourself from closing tabs on https://some-app.tld add https://some-app.tld/*, e.g.: https://app.slack.com/*

4. Ensure that chromium always opens with my default profile

Now we have introduced a bit of an annoying issue: By default, chromium will open any new window with the least recently used profile. But I only want to open a window for that profile when explicitly selecting it in the profile menu! By default, new windows should open with my "Default" profile. On linux you can simply add --profile-directory="Default" to /home/<user>/.config/chromium-flags.conf to achieve that. See this stackoverflow post for a more detailed explanation. You can of course also have a non-"Default" profile open by default. ;)

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