Skip to content

Slack open in browser userscript

I despise Slack very much and try to use it as little as possible. Sometimes, however, I have no choice but to message a colleague or a friend, so I refuse to download the Slack app because I don't want it open all the time. One thing that really annoyed me was that whenever you clicked on a Slack channel from the main Slack homepage, it would do two things:

  1. It would try to open Slack in the app, which I didn't have installed, so it would require me to click "Open in Browser" or "Continue in Browser."
  2. It would open Slack workspaces in a new tab, which was very frustrating because I don't need the Slack homepage open in my browser.

I wrote a small userscript that bypasses and disables the new tab opening and automatically clicks the "Continue in Browser" button when it appears.

javascript
// ==UserScript==
// @name         Slack Browser UX Enhancements
// @description  Keeps Slack in the browser and prevents workspace links opening new tabs
// @version      1.0.1
// @author       @tdrayson
// @namespace    https://github.com/tdrayson/userscripts
// @match        https://*.slack.com/*
// @match        https://*.slack.com/ssb/redirect*
// @match        https://*.slack.com/archives/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=slack.com
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function () {
  'use strict';

  const textVariations = [
    'use slack in your browser',
    'open in browser',
    'continue in browser',
    'stay in browser',
    'open this link in your browser',
  ];

  let browserLinkClicked = false;

  function disableNewTabOpening() {
    const links = document.querySelectorAll(
      'a.ss-c-workspace-detail__action, a.workspace-list-item'
    );

    if (links.length === 0) return;

    links.forEach((link) => {
      if (link.target === '_blank') {
        link.target = '_self';
      }
    });
  }

  function clickBrowserLink() {
    if (browserLinkClicked) return;

    const links = document.querySelectorAll('a');

    for (const link of links) {
      const text = (link.textContent || '').toLowerCase().trim();
      if (!text) continue;

      if (textVariations.some((variant) => text.includes(variant))) {
        link.click();
        browserLinkClicked = true;
        break;
      }
    }
  }

  window.addEventListener('load', disableNewTabOpening);

  const observer = new MutationObserver(() => {
    disableNewTabOpening();
    clickBrowserLink();
  });

  if (document.body) {
    observer.observe(document.body, {
      childList: true,
      subtree: true,
    });
  }

  clickBrowserLink();
})();

Tagged Slack, Userscripts

View as .json, .yaml, .md, .mf2, .txt

1 interaction

0

Add a comment, or .

Send me the link and your response will show up on this page.

Link back to this page if you write about it.

This is what shows up when you post the link somewhere.

taylordrayson.com

Slack open in browser userscript

I despise Slack very much and try to use it as little as possible. Sometimes, however, I have no choice but to message a colleague or a friend, so I refuse to download the Slack app because I don't…

Want to see how it is made? Here is the card on its own, drawn from this page's own title and description.