Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#向Chrome发送本地消息_C#_Google Chrome_Google Chrome Extension_Chrome Native Messaging - Fatal编程技术网

C#向Chrome发送本地消息

C#向Chrome发送本地消息,c#,google-chrome,google-chrome-extension,chrome-native-messaging,C#,Google Chrome,Google Chrome Extension,Chrome Native Messaging,我正在尝试创建一个插件/监听器,让外部应用程序将消息输入我的SPA页面/应用程序 我已经创建了清单、JS文件,并添加了一个reg条目,但是没有用,我的侦听器没有被触发 我有: //JavaScript源代码 Native.js-插件 chrome.runtime.onMessageExternal.addListener( function (request, sender, sendResponse) { console.log(request); console.

我正在尝试创建一个插件/监听器,让外部应用程序将消息输入我的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-插件 { “清单版本”:2


C#

Program.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);
        }
    }
}
Manifest.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/"
    ]
}

Chrome从不监听来自外部的本机连接(
onMessageExternal
不适用),运行C代码也不会神奇地与Chrome联系

只有JavaScript端可以启动连接(通过运行本机主机的新副本),之后可以保持连接打开(如果使用
connect()

因此,如果希望收到在浏览器之外发生的事件的通知,则需要从扩展端启动本机主机,然后在本机主机中处理这些事件


总之,你应该(重新)阅读完整的文档:

通过在互联网上的阅读,我想这些帖子一定缺少了一些C#能够“神奇地”连接的东西。我会重新阅读并重新思考我的解决方案-谢谢!基本上,你不能直接敲开Chrome的门。但是你可以制作一个像代理/守护程序一样运行的小型本机主机模块,在了解背景,听你想听的任何东西。
    {
    "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/"
    ]
}