Skip to content

Instantly share code, notes, and snippets.

@MaxMatti
Last active July 3, 2024 16:49
Show Gist options
  • Save MaxMatti/f3679db24f6c15d69828bb1294198428 to your computer and use it in GitHub Desktop.
Save MaxMatti/f3679db24f6c15d69828bb1294198428 to your computer and use it in GitHub Desktop.
Using a secondary browser as Messenger for MS Teams only (open all links in other browser)

How to use a secondary browser as MS Teams messenger only

Chrome for Teams, Firefox for everything else

  1. install both browsers
  2. install the chrome-extension Open in Firefox
  3. add teams.microsoft.com as PWA in Chome
  4. go to the settings for "Open in Firefox" and select to open everything except *.microsoft.com in firefox

Firefox for Teams, Chrome for everything else

  1. install both browsers
  2. install the firefox-extension Open in Chrome
  3. install the firefox-extension PWAs for Firefox
  4. add teams.microsoft.com as PWA in Firefox
  5. go to the settings for "Open in Chrome" and select to open everything except *.microsoft.com in chrome
@influential-eliot
Copy link

Violent Monkey Observer JQuery Alternative

This uses the VM JQuery method to perform the work, it works on SLACK and Outlook PWAs in Edge on Linux (Debian) but I'm having trouble getting it to work in Teams.

Code

// ==UserScript==
// @name         external-teams-links
// @namespace    https://mstaff.de/
// @version      0.1
// @description  replace links in MS Teams to have chrome act like a messenger only
// @author       Max Staff <max.staff@gmx.de>
// @match        https://teams.microsoft.com/*
// @match        https://app.slack.com/*
// @match        https://outlook.office.com/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @require      https://cdn.jsdelivr.net/npm/@violentmonkey/dom@1
// @require      https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js
// @grant        none
// ==/UserScript==
 
VM.observe(document.body, () => {
  const $node = $('a[target="_blank"][href^="http"]');
 
  if ($node.length) {
    $($node).each(function () {
 
      // Check All Is OK
      let urllyOrig = new URL($(this).attr('href'));
      let urllyHost = urllyOrig.hostname;
      let urllyHostLow = urllyHost.toLowerCase();
 
      if ( !urllyHostLow.endsWith(".slack.com") || !urllyHostLow.endsWith("teams.microsoft.com") || !urllyHostLow.endsWith("outlook.office.com") ){
        // Construct New URL
        let urlly = $(this).attr('href').slice(4);
        let urllyNu = new URL("browser"+urlly);
        // Place new URL on A element
        $(this).attr('href', urllyNu);
      };
    });
 
    // If uncommented this will not run for all new links after it has handled one
    //return true;
  }
});

You may be able to make this more efficient than I have, I only know enough for 'applied' coding. 😅

More Information

I was a bit concerned that this would replace all instances of "http" in a URL, but then I remembered that replace() by default only replaces the first.

So I nearly didn't put it together.

However, I noticed that you had the issue with sent items and with images, and I thought that the fact that the observer in this instance isn't breaking might well fix that.

Teams Issues

For whatever reason, I cannot get this to run properly on Teams URLs.

I have tried the different 'inject' settings and also the following options in the metadata ...

// @match        http*://teams.microsoft.com/*
// @match        http*://teams.microsoft.com/v2/?clientType=pwa
// @run-at        document-start

... but I cannot get it to functionally fudge with the Teams HTML.

Do you think that perhaps Teams has an observer of its own that first needs to be disabled?

@MaxMatti
Copy link
Author

I updated the instructions so that all the custom stuff is no longer necessary. If you still want to do it the hard way you can check the gists history.

@influential-eliot
Copy link

OK, well, I'm not the trusting type, so my genuine apologies on not wishing to install both another extension and a local client.

Thanks, though, for all your hard work!

@JoeyG1973
Copy link

So here is something interesting. I follow this guide using the open in chrome plugin for edge. I add teams and outlook as an app from edge. When I open the Outlook app, it opens as a wpa in edge. When I open the teams app it opens chrome. Any ideas?

cat msedge-cifhbcnohmdccbgoicgdjpfamggdegmo-Default.desktop
#!/usr/bin/env xdg-open
[Desktop Entry]
Version=1.0
Terminal=false
Type=Application
Name=Microsoft Teams
Exec=/opt/microsoft/msedge/microsoft-edge --profile-directory=Default --app-id=cifhbcnohmdccbgoicgdjpfamggdegmo "--app-url=https://teams.microsoft.com/v2/?clientType=pwa"
Icon=msedge-cifhbcnohmdccbgoicgdjpfamggdegmo-Default
StartupWMClass=crx__cifhbcnohmdccbgoicgdjpfamggdegmo

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