A
A
Alex2015-02-03 03:15:37
Google Chrome
Alex, 2015-02-03 03:15:37

How to use Chrome Native Messaging on Ubuntu?

How to use Chrome Native Messaging on Ubuntu?
Chromium has an extension installed:
manifest.json

{
    "manifest_version": 2,
    "version": "1.0",
    "name": "Native Messaging Example",
    "description": "Send a message to a native application",
    "permissions": [
        "nativeMessaging"
    ],
    "background": {
        "scripts": ["native.js"]
    }
}

native.js
port = chrome.runtime.connectNative('com.google.chrome.example.echo	');
port.onMessage.addListener(function(message) {
    alert(message);
});
port.onDisconnect.addListener(function() {
    alert(chrome.runtime.lastError.message);
});
port.postMessage({ text: "Hello, my_application" });

But I get the same error every time I run it:
Invalid native messaging host name specified
File com.google.chrome.example.echo.json was placed at the following addresses:
/home/alex/.config/chromium/NativeMessagingHosts/
/home/alex/.config/chromium/Default/NativeMessagingHosts/
/etc/chromium/native-messaging-hosts/
/etc/chromium-browser/native-messaging-hosts/

And its content:
{
  "name": "com.google.chrome.example.echo",
  "description": "Chrome Native Messaging API Example Host",
  "path": "/home/alex/native/native.sh",
  "type": "stdio",
  "allowed_origins": [
    "chrome-extensions://bpblaklgcafionejfnmigkncnmkaebef/"
  ]
}

native.sh
#!/bin/bash
  echo "Hello"
exit 0

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yandexzombie, 2015-09-22
@yandexzombie

native.sh should act as a daemon. There is a good example in the answer
to stack overflow

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question