I just went through trying to figure this out for similar purposes. Moral of the story is you either need to use "Native Messaging" (which Chrome basically calls a deployed .EXE) or create an Extension that uses JavaScript to talk with your application.
https://developer.chrome.com/extensions
https://developer.chrome.com/extensions/nativeMessaging
This is a departure from IE where you can simply assign the underlying DOM to an object. Chrome does not expose an API or the underlying DOM in the same way.
The way I solved this was using a WebSocket Server in C# (SuperWebSocket
in NuGet), and Javascript within a Chrome Extension to call said WebSocket Server. For Chrome Extensions, the JavaScript runs in the background so you can connect and establish a session to pass messsages back and forth.
Here is a sample for how to start WebSocket Client:
https://github.com/kerryjiang/SuperWebSocket/blob/master/Samples/BasicConsole/Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSocket.SocketBase;
namespace SuperWebSocket.Samples.BasicConsole
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to start the WebSocketServer!");
Console.ReadKey();
Console.WriteLine();
var appServer = new WebSocketServer();
//Setup the appServer
if (!appServer.Setup(2012)) //Setup with listening port
{
Console.WriteLine("Failed to setup!");
Console.ReadKey();
return;
}
appServer.NewMessageReceived += new SessionHandler<WebSocketSession, string>(appServer_NewMessageReceived);
Console.WriteLine();
//Try to start the appServer
if (!appServer.Start())
{
Console.WriteLine("Failed to start!");
Console.ReadKey();
return;
}
Console.WriteLine("The server started successfully, press key 'q' to stop it!");
while (Console.ReadKey().KeyChar != 'q')
{
Console.WriteLine();
continue;
}
//Stop the appServer
appServer.Stop();
Console.WriteLine();
Console.WriteLine("The server was stopped!");
Console.ReadKey();
}
static void appServer_NewMessageReceived(WebSocketSession session, string message)
{
//Send the received message back
session.Send("Server: " + message);
}
}
}
Here is sample JavaScript to attempt a new WebSocket connection:
function attemptConnection() {
if (!connectionMade) {
var exampleSocket = new WebSocket("ws://localhost:8080");
exampleSocket.onopen = function () {
connectionMade = true;
};
exampleSocket.onmessage = function (event) {
//msg received from C#
}
exampleSocket.onerror = function () {
//do nothing
}
exampleSocket.onclose = function () {
connectionMade = false;
}
}
}
You can use any WebSocket server library you want. The gist of it is the Chrome Extension Opens a line of communication with your application and then the two pass messages back and forth which the Chrome Extension or Application can act on. For example, C# can pass the Chrome Extension JSON containing field elements that you want to update on the web page.
Also, keep in mind that you have to deploy your Chrome Extension to the Chrome Web Store (and set to private if required) or else it will automatically disable itself.