TFS Team Room - Chrome popup notifications

Are you getting tired of flipping back and forth between Team Room chats and your day-to-day coding tasks?  Well, you'll enjoy this post!

The following TamperMonkey script will tap into the guts of the TFS Team Room, intercept each post, and display it in a nice Chrome desktop notification.


  1. Install the TamperMonkey plugin into Chrome
  2. Add a new user script, and paste the code below into the script window
  3. Profit!
Note - you may have to change your notification settings to get this script to function properly:

Known bugs/issues (will be fixed in a future release):
  • This script only works for Visual Studio Online.  If you want it to work with your internal TFS servers, change the @match url in the comment block at the top.
  • When anyone is tagged, the message will stay open until you close it
  • TFS notifications won't display correctly (like check-ins, people entering/leaving rooms, etc.)  For example, when a check-in against a task occurs, all you'll see is "Task 1234 has changed", with no other details.
  • Clicking on a notification doesn't focus on the tab that issued it.  This feature will be added in a future release.

// ==UserScript==
// @name       TFS Team Room notifications in Chrome
// @namespace  http://nuts4.net
// @version    0.51
// @description Getting tired of switching back and forth between a browser and Visual Studio...just to see if you have any chat notifications?  Use this script, and get your notifications directly on your desktop!
// @match      https://*.visualstudio.com/_rooms*
// @copyright  2013+, Joe Coutcher
// ==/UserScript==
 
// Bookmarklet to activate Chrome notifications on TFS Team Room Chat
$(function() {
    if (window.webkitNotifications.checkPermission() != 0) {
        window.webkitNotifications.requestPermission();
    }
    
    console.log("TFS Notifications - Setting up 10 second delay...");
    // Activate the plugin after 10 seconds
    window.setTimeout(function() {
        $.connection.chatHub.on('messageReceived', function(roomId, message) {
            var messageNotification = function(image, title, content) {
                var _notification = window.webkitNotifications.createNotification(_tfsIcon, title, content);
                _notification.show();
                
                // If you are mentioned in the chat, keep it displayed until you actively close it.
                if (message.Mentions.length == 0) {
                    window.setTimeout(function() {
                        _notification.cancel();
                    }, 5000);
                }
            };
            
            if (message.PostedByUserTfId != $.connection.chatHub.state.id) {
                if (message.Content.indexOf("{") == 0) {
                    var _tfsServerIcon = "/_static/tfs/20131021T164530/_content/tfs-large-icons.png";
                    var serverMessage = $.parseJSON(message.Content);
                    messageNotification(_tfsServerIcon, serverMessage.type, serverMessage.title);
                } else {
                    var _tfsIcon = "/_api/_common/IdentityImage?id=" + message.PostedByUserTfId;
                    
                    if (window.webkitNotifications.checkPermission() == 0) {
                        messageNotification(_tfsIcon, message.PostedByUserName, message.Content);
                    }
                }
            }
        });
        console.log("TFS Notification code has loaded.");
    }, 10000);
});