我正在尝试创建一个插件/侦听器,以使外部应用程序将消息泵入我的 SPA 页面/应用程序。
我已经创建了清单、JS 文件并添加了一个 reg 条目,但无济于事,我的听众没有被触发。
我有:
// JavaScript 源代码
Native.js - 插件
chrome.runtime.onMessageExternal.addListener(
function (request, sender, sendResponse) {
console.log(request);
console.log(sender);
console.log(sendResponse);
});
Manifest.json - 插件 { "manifest_version": 2,
"name": "Native Messaging Example",
"version": "1.0",
"permissions": [
"nativeMessaging"
],
"background": {
"scripts": [ "Native.js" ]
},
"externally_connectable": {
"matches": [ "*://localhost/*", "*://casetest/*", "*://case/*" ]
}
}
C#
程序.js
using System;
using System.IO;
namespace ChromeNativeMessaging
{
class Program
{
static void Main(string[] args)
{
OpenStandardStreamOut("data");
Console.ReadLine();
}
private static void OpenStandardStreamOut(string stringData)
{
String str = "{\"text\": \"" + stringData + "\"}";
//String str = stringData;
Stream stdout = Console.OpenStandardOutput();
stdout.WriteByte((byte)str.Length);
stdout.WriteByte((byte)'\0');
stdout.WriteByte((byte)'\0');
stdout.WriteByte((byte)'\0');
Console.Write(str);
}
}
}
清单.json
{
"name": "com.example.nativeMessage",
"description": "Hello World App",
"path": "C:\\Users\\sas\\Documents\\visual studio 2013\\Projects\\ChromeNativeMessaging\\ChromeNativeMessaging\\bin\\Debug\\ChromeNativeMessaging.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://gbdadncpjaecammkmeolpbembeedjohb/"
]
}