Skip to content

Instantly share code, notes, and snippets.

@PiDelport
Last active December 28, 2022 18:06
Show Gist options
  • Save PiDelport/513676916e8fc186a09edfc8965a410b to your computer and use it in GitHub Desktop.
Save PiDelport/513676916e8fc186a09edfc8965a410b to your computer and use it in GitHub Desktop.
Slack Web Workspace Sidebar
// ==UserScript==
// @name Slack Web Workspace Sidebar
// @description Enable the workspace sidebar on the web version of Slack.
// @namespace https://github.com/PiDelport/
// @author Pi Delport <[email protected]>
// @version 1.0
// @license MIT
// @homepageURL https://gist.github.com/PiDelport/513676916e8fc186a09edfc8965a410b
// @match https://app.slack.com/*
// ==/UserScript==
(function() {
'use strict';
// See:
// https://webapps.stackexchange.com/questions/144258/slacks-web-version-shows-workspace-switching-sidebar-but-only-on-chromebooks
//
// This seems to be the minimal change to make Slack detect Chrome OS, as of 2020-09-25:
Object.defineProperty(navigator, 'userAgent', {
value: navigator.userAgent + ' CrOS'
});
})();
@Dunedan
Copy link

Dunedan commented Mar 26, 2021

This doesn't work in Firefox, as Firefox doesn't allow executing Javascript on pages with proper Content Security Policies, like Slack has. Unless one wants to set security.csp.enable = false, which is obviously bad for security, there doesn't seem to be a working workaround.

Tampermonkey claims to have one (Tampermonkey/tampermonkey#952 (comment)), however I could get that to work (not even with disabled service workers and caching).

Violentmonkey has another workaround (https://violentmonkey.github.io/posts/inject-into-context/), however they explicitly state that this then results in the userscripts to run in another context than the Javascript on the page. I also tried that and can confirm that while the script gets executed, the changed user agent isn't visible to the page.

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