NativeMessaging 1.0.2
See the version list below for details.
dotnet add package NativeMessaging --version 1.0.2
NuGet\Install-Package NativeMessaging -Version 1.0.2
<PackageReference Include="NativeMessaging" Version="1.0.2" />
paket add NativeMessaging --version 1.0.2
#r "nuget: NativeMessaging, 1.0.2"
// Install NativeMessaging as a Cake Addin
#addin nuget:?package=NativeMessaging&version=1.0.2
// Install NativeMessaging as a Cake Tool
#tool nuget:?package=NativeMessaging&version=1.0.2
NativeMessaging
C# Chome Native Messaging Library
Can be used to receive data from or talk to a Chrome extension.
This can currently be used with the example app provided here: https://chromium.googlesource.com/chromium/src/+/master/chrome/common/extensions/docs/examples/api/nativeMessaging
Usage
Extend the host class and decide what you want to do when you receive a message.
public class MyHost : Host
{
private const bool SendConfirmationReceipt = true;
public override string Hostname
{
get { return "com.anewtonlevey.myhost"; }
}
public MyHost() : base(SendConfirmationReceipt)
{
}
protected override void ProcessReceivedMessage(JObject data)
{
SendMessage(data);
}
}
class Program
{
static public string AssemblyLoadDirectory
{
get
{
string codeBase = Assembly.GetEntryAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
}
static public string AssemblyExecuteablePath
{
get
{
string codeBase = Assembly.GetEntryAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
return Uri.UnescapeDataString(uri.Path);
}
}
static Host Host;
static string[] AllowedOrigins = new string[] { "chrome-extension://knldjmfmopnpolahpmmgbagdohdnhkik/" };
static string Description = "Description Goes Here";
static void Main(string[] args)
{
Host = new MyHost();
if (args.Contains("--register"))
{
Host.GenerateManifest(Description, AllowedOrigins);
Host.Register();
} else if(args.Contains("--unregister"))
{
Host.UnRegister();
} else
{
Host.Listen();
}
}
}
Troubleshooting
If your're having trouble connecting from Chrome try launching chrome with --enable-logging
flag as detailed in Debugging native messaging.
It also recommeneded to try compiling in Release mode if you're encountering issues.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net452 is compatible. net46 was computed. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
- Newtonsoft.Json (>= 12.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.