标签: chrome-native-messaging

带有Chrome Native Messaging的C#本机主机

我今天花了几个小时研究如何使用C#本机主机来使用Chrome本机消息传递.从概念上来说,这很简单,但是我从这些其他问题的帮助(部分)中解决了一些障碍:

原生消息Chrome
从Chrome扩展到使用C#编写的本机主机的本机消息传递
很慢,无法将"大量"数据从Chrome扩展传递到主机(用C#编写)

我的解决方案发布在下面.

c# google-chrome chrome-native-messaging

23
推荐指数
1
解决办法
1万
查看次数

与Firefox中的Chrome原生客户端消息传递类似的技术?

我们希望在基于浏览器的Web应用程序和客户端守护进程之间替换自定义NPAPI接口.

Firefox中的Chrome的Native Client Messaging是否有类似的技术?

firefox google-chrome jsctypes chrome-native-messaging

15
推荐指数
1
解决办法
3575
查看次数

未捕获(承诺中)错误:侦听器通过返回 true 指示异步响应,但消息通道在响应之前关闭

我在 background.js 中发现“未捕获(承诺中)错误:侦听器通过返回 true 指示异步响应,但消息通道在收到响应之前已关闭”错误。我的 chrome 扩展可以工作,但开发工具在 background.js 上显示很多此类错误

我最近将 chrome 扩展从 Manifest V2 迁移到 Manifest V3,从那时起我发现了错误。

这是错误似乎产生的地方:

const browser = chrome || browser;

// Listen for messages from content script
browser.runtime.onMessage.addListener(
    function (request, sender, sendResponse) {
         var frameId = sender.frameId || 0;

            if (request.type == "connect") {               
                connect(sender.tab, frameId);
                sendResponse({ success: true });
            } else if (request.type == "disconnect") {                
                disconnect(sender.tab, frameId);
                sendResponse({ success: true });
            } else if (request.type == "send") {
                sendNativeMessage(request.data, sender.tab);
                document.addEventListener('nativeMessage',
                    function …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome-extension promise chrome-native-messaging chrome-extension-manifest-v3

11
推荐指数
1
解决办法
3万
查看次数

chrome.runtime.connectNative生成Uncaught TypeError:undefined不是函数

我写了一个chrome扩展,调用这个connect()函数连接到本地C++程序:

function connect() {
  console.log("test1");
  //port = chrome.extension.connectNative('com.a.chrome_interface');
  port = chrome.runtime.connectNative('com.a.chrome_interface');

  port.onMessage.addListener(onNativeMessage);
  port.onDisconnect.addListener(onDisconnected);
  console.log("test5");
}
Run Code Online (Sandbox Code Playgroud)

我可以在Console中看到test1,但之后我收到了错误

Uncaught TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)

在线

port = chrome.runtime.connectNative('com.a.chrome_interface');
Run Code Online (Sandbox Code Playgroud)

我的扩展清单文件在这里:

{
  "name": "CPP_Connect",
  "version": "1.0",
  "description": "Send data to CPP program",

  "content_scripts": [
   {
     "matches": ["<all_urls>"],
     "js": ["contentscript.js"]
   }
  ],

  "permissions": ["contextMenus", "tabs", "nativeMessaging", "<all_urls>"],

  "manifest_version": 2

}
Run Code Online (Sandbox Code Playgroud)

我的com.a.chrome_interface.json看起来像这样:

{
"name": "com.a.chrome_interface",
"description": "Chrome Native Messaging API Example Host",
"path": "com.a.chrome_interface",
"type": "stdio",
"allowed_origins": [
"chrome-extension://abc.../"
]
}
Run Code Online (Sandbox Code Playgroud)

com.a.chrome_interface是一个linux可执行C++文件,它生成一个文件,如果它被调用,则永远不会创建该文件.我确实放了两个文件

 /etc/opt/chrome/native-messaging-hosts/
Run Code Online (Sandbox Code Playgroud)

所以我想,我确实正确地注册了我的C++,但我也猜测,如果我注册错了,我应该得到一个不同的错误.如果我使用chrome.extension.connect()脚本运行低谷,错误消息消失,但没有数据到达我的C++程序.

我确实阅读并尝试按照 …

google-chrome google-chrome-extension chrome-native-messaging

10
推荐指数
1
解决办法
5738
查看次数

Chrome Native Messaging API chrome.runtime.connectNative不是一个函数

我希望操纵当前位于Chrome标签页上的内容页面,如果以下内容无法做到这一点,那么我需要找到方法来实现这一目标!

嘿所有我试图让这个新的chrome扩展与我的C#程序一起来回传递消息.我已经在stackoverflow上看到了很多代码演示,这主要是我一直在想的,但似乎所有的例子都不适合我.

我遇到的问题是我得到的错误:

Connecting to native messaging host com.google.chrome.example.echo
Uncaught TypeError: chrome.runtime.connectNative is not a function
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

每当我尝试"连接"到端口.

不知道我做错了什么,因为我在这里跟随其他tetorials,他们似乎都说它有效....

JS main.js:

var port = null;
var getKeys = function (obj) {
    var keys = [];
    for (var key in obj) {
        keys.push(key);
    }
    return keys;
}
function appendMessage(text) {
    document.getElementById('response').innerHTML += "<p>" + text + "</p>";
}
function updateUiState() {
    if (port) {
        document.getElementById('connect-button').style.display = 'none';
        document.getElementById('input-text').style.display = 'block';
        document.getElementById('send-message-button').style.display = 'block';
    } else {
        document.getElementById('connect-button').style.display = 'block';
        document.getElementById('input-text').style.display = 'none'; …
Run Code Online (Sandbox Code Playgroud)

javascript c# google-chrome google-chrome-app chrome-native-messaging

9
推荐指数
2
解决办法
7938
查看次数

Chrome关闭时Chrome Native Messaging未关闭

我已经制作了chrome主机,用于在我的扩展程序和我的进程之间传递本机消息,我的进程在chrome启动时启动但在关闭chrome时没有关闭,我应该在主机清单中添加参数还是应该添加我的进程处理以关闭铬合金关闭的过程?

谢谢.

google-chrome chrome-native-messaging

8
推荐指数
1
解决办法
1185
查看次数

原生消息Chrome

我试图在我的chrome扩展和我的c#应用程序之间获取Native Messaging.javascript工作正常,但我收到此错误:

与本机消息传递主机通信时出错.

正如我从任务管理器中看到的那样,应用程序与扩展一起启动.这是我的c#代码.

private static string OpenStandardStreamIn()
{
    //// We need to read first 4 bytes for length information
    Stream stdin = Console.OpenStandardInput();
    int length = 0;
    byte[] bytes = new byte[4];
    stdin.Read(bytes, 0, 4);
    length = System.BitConverter.ToInt32(bytes, 0);

    string input = "";
    for (int i = 0; i < length;i++ )    
    {
        input += (char)stdin.ReadByte();
    }

    return input;  
}

private static void OpenStandardStreamOut(string stringData)
{
    //// We need to send the 4 btyes of length information
    string msgdata …
Run Code Online (Sandbox Code Playgroud)

javascript c# google-chrome google-chrome-extension chrome-native-messaging

8
推荐指数
1
解决办法
8159
查看次数

C++中的Chrome原生主机无法与Chrome通信

我正在尝试使用runtime.connectNative和实现Chrome扩展程序postMessage.我正在关注Chrome文档,下载了本机消息传递示例,并将本机应用程序更改为使用C++.

但是,原生应用无法从Chrome扩展程序接收消息.

同时,当使用该printf功能的本机应用程序向chrome扩展程序写入消息时,扩展程序无法接收并且控制台中只显示消息.

任何想法如何解决问题?

c++ google-chrome-extension chrome-native-messaging

8
推荐指数
2
解决办法
5757
查看次数

如何在Firefox附加组件中发送子进程,如Chrome本机消息传递

我正在尝试使用Firefox的附加SDK 模拟Chrome的本机消息功能.具体来说,我正在使用child_process模块emit方法与python子进程通信.

我能够成功地向子进程发送消息,但是我无法将消息发送回附加组件.Chrome的本机消息传递功能使用stdin/stdout.两个方向上每个消息的前4个字节表示后续消息的字节大小,因此接收方知道要读取多少.这是我到目前为止所拥有的:

子进程的附加组件

var utf8 = new TextEncoder("utf-8").encode(message);
var latin = new TextDecoder("latin1").decode(utf8);

emit(childProcess.stdin, "data", new TextDecoder("latin1").decode(new Uint32Array([utf8.length])));
emit(childProcess.stdin, "data", latin);
emit(childProcess.stdin, "end");
Run Code Online (Sandbox Code Playgroud)

来自附加组件的子进程(Python)

text_length_bytes = sys.stdin.read(4)
text_length = struct.unpack('i', text_length_bytes)[0]
text = sys.stdin.read(text_length).decode('utf-8')
Run Code Online (Sandbox Code Playgroud)

加载项的子进程

sys.stdout.write(struct.pack('I', len(message)))
sys.stdout.write(message)
sys.stdout.flush()
Run Code Online (Sandbox Code Playgroud)

子进程的附加组件

这是我在努力的地方.当长度小于255时,我可以使用它.例如,如果长度为55,则可以:

childProcess.stdout.on('data', (data) => { // data is '7' (55 UTF-8 encoded)
    var utf8Encoded = new TextEncoder("utf-8).encode(data);
    console.log(utf8Encoded[0]); // 55
}
Run Code Online (Sandbox Code Playgroud)

但是,就像我说的那样,它并不适用于所有数字.我确定我必须对TypedArrays做些什么,但我很难把所有东西放在一起.

javascript python firefox-addon firefox-addon-sdk chrome-native-messaging

7
推荐指数
1
解决办法
252
查看次数

使用 Xamarin Mac、C# 的跨浏览器、跨平台本机消息传递

我尝试重新创建示例以使用 chrome 扩展程序连接到我的 Xamarin Mac 应用程序,我将用作所有其他浏览器的主干,但它没有使用以下错误:

与本机消息传递主机通信时出错。

文档在纸面上看起来很简单,但在现实生活中却没有那么简单。

这是我的阅读和聆听功能(那里有很好的例子,https : //github.com/anewtonlevey/NativeMessaging):

    public void Listen()
    {

        JObject data;
        while ((data = Read()) != null)
        {
            ProcessReceivedMessage(data);
        }

    }




    private JObject Read()
    {
        try
        {
            Stream stdin = Console.OpenStandardInput();


            byte[] lengthBytes = new byte[4];
            stdin.Read(lengthBytes, 0, 4);


            var buffer = new char[BitConverter.ToInt32(lengthBytes, 0)];

            using (var reader = new StreamReader(stdin)) while (reader.Peek() >= 0) reader.Read(buffer, 0, buffer.Length);
            return JsonConvert.DeserializeObject<JObject>(new string(buffer));


        }
        catch (Exception e)
        {
            Console.WriteLine("Read error: {0}", e);
            return null; …
Run Code Online (Sandbox Code Playgroud)

macos chrome-native-messaging xamarin.forms

7
推荐指数
1
解决办法
298
查看次数