What is new in Browser Link with Visual Studio 2013 RC?

Reshmi Mangalore

Over the last few months, the Browser Link team has worked on delivering these new features in the Visual Studio 2013 RC release:

  1. Browser Link Dashboard
  2. APIs for extension authoring

For those who are not familiar with Browser Link, please look at our introductory blog here.

The Browser Link Dashboard is a tool window in VS that shows all active browser link connections.

You can invoke the dashboard by clicking on the little arrow next to the Refresh Linked Browser icon.


Clicking on the Browser Link Dashboard menu item will bring up the tool window.

As you can see in the image below, the dashboard shows all active connections related to your solution. These include connections that were opened via F5 (run with debugger), Ctrl+F5 (run), View in Browser or even just by opening any browser and pasting the url.

For example, in the image below, you can see that connections to About.aspx in IE, Chrome and IPad emulator are all listed in the Browser Link Dashboard. The connections also give you details of the url.

A Problems node exists to tell you if there is a problem. In our case, we are good as the debug flag is set to true and we are on a 4.5 project.


APIs for extension authoring

With the RC release, we now support the authoring of Browser Link Extensions via a public API. The rest of this post describes what a Browser Link Extension is and how you can write one.

A Browser Link Extension is a VS extension that will let you talk to all Browsers connected with any web project  that is open in Visual Studio. Your extension will have a CSharp part and a JavaScript part. The CSharp part is run in the context of Visual Studio. The Javascript part gets injected in the browser when a user makes a requests to that page. There are APIs on both sides that allow them to talk to each other.

Let us start off with writing a simple Browser link Extension.

To get started you will need the following:

1. Visual Studio Ultimate 2013 RC from here.

2. VSSDK from here.

3. The  Visual Studio Template for Browser Link Extension from the VS Gallery. This is available here.

Here is a step by step explanation of how to author a simple extension:

Step 1: Create a Browser Link Project by going to:

File –>New Project ->Visual C# –>Extensibility. Search for Browser Link Extension, select it and click the OK button.


Step 2: The project is created for you at this point.

Step 3: Open SimpleBrowserLinkProject.js under the scripts folder. Copy and paste the following. I have added a simple HelloWorld function that can be called from Visual Studio.

Code Snippet
  1. /// <reference path="../intellisense/browserlink.intellisense.js" />
  3. (function (browserLink, $) {
  4.     /// <param name="browserLink" value="bl" />
  5.     /// <param name="$" value="jQuery" />
  7.     function output(message) { // Helper for the 'greeting' function
  8.         alert(message);
  10.         if (console) {
  11.             console.log(message);
  12.         }
  13.     }
  15.     return {
  17.         HelloWorld: function(message)
  18.         {
  19.             var topDiv = document.createElement("div");
  20.             topDiv.id = "SimpleDiv";
  21.             var textElement = document.createTextNode(message);
  22.             topDiv.appendChild(textElement);
  23.             $("body").prepend(topDiv);
  24.         }
  25.         ,
  26.         name: "SimpleBrowserLinkProject",
  28.         greeting: function (message) { // Can be called from the server-side extension
  29.             output(message);
  30.         },
  32.         onInit: function () { // Optional. Is called when a connection is established
  34.         }
  35.     };
  36. });

Step 4: Open SimpleBrowserLinkProject.cs and copy and paste the following under OnConnected.

Code Snippet
  1. public override void OnConnected(BrowserLinkConnection connection)
  2.         {
  3.             Clients.Call(connection,"HelloWorld", "This is a simple Browser link extension!!");
  4.         }

Step 5: Ctrl + F5 and this will open the experimental instance of Visual Studio. Now, Create a Web Application Project and View About.aspx in IE and Chrome. In each of these new connections, we are calling the javascript function “HelloWorld” which adds a div at the top of your page. 


This is a simple extension which shows how VS can talk to all browsers.

Step 6:  To talk from the browser to VS, make the following changes. Copy and paste this code into your OnInit function in SimpleBrowserLinkProject.js.

Code Snippet
  1. onInit: function () { // Optional. Is called when a connection is established
  2.             browserLink.call("SendText", "Hello from JS to VS")
  3.         }

Step 7: In your SimpleBrowserLinkProject.cs file you should have a SendText method which has a BrowserLinkCallBack Attribute. This attribute suggests that this can be called from JavaScript.

Code Snippet
  1. [BrowserLinkCallback] // This method can be called from JavaScript
  2.         public void SendText(string message)
  3.         {
  4.             MessageBox.Show(message);
  5.         }

Step 8: Ctrl + F5 and this will open the experimental instance of Visual Studio. Create a  Web Application Project in your experimental instance and invoke Browse with multiple browsers. Now each of these will pop up a VS Message box as shown below.


So that was a quick introduction to the new Browser Link feature in RC.

You can look at Mad’s Web essentials for Visual Studio 2013 (source) for some cool Browser Link Extensions. Stay tuned for more posts around knowing your Browser Link APIs.


Reshmi Mangalore


Discussion is closed.

Feedback usabilla icon