Giter Club home page Giter Club logo

chrome-native-messaging's Introduction

Chrome Native Messaging for Node.js

Transform streams for writing Chrome App native messaging hosts in Node.js.

Install

npm i -S chrome-native-messaging

API

The module exports Input, Output, and Transform transform streams.

Input streams transform bytes to objects.

Output streams transform objects to bytes.

Use Transform to easily create custom object-to-object transform streams.

var nativeMessage = require('chrome-native-messaging');

process.stdin
    .pipe(new nativeMessage.Input())
    .pipe(new nativeMessage.Transform(function(msg, push, done) {
        var reply = getReplyFor(msg); // Implemented elsewhere by you.
        push(reply);                  // Push as many replies as you like.
        done();                       // Call when done pushing replies.
    }))
    .pipe(new nativeMessage.Output())
    .pipe(process.stdout)
;

Example

The app directory contains a sample Chrome App.

The host directory contains a native messaging host that you can send messages to.

Go to the Chrome Extensions page (chrome://extensions/), hit "Load unpacked extension...", and select this project's app directory.

SUPER IMPORTANT: Find the ID your app received when you loaded it and copy it to the host manifest in the host directory.

SUPER IMPORTANT ON MACS: The path to the host must be absolute. Make sure the "path" property in the manifest is correct (it's probably not unless you're me).

Install the host manifest:

sudo host/register.sh

On Windows (Run as Administrator):

host\register.bat

Open a new tab and hit Apps in the upper left. Launch the example app and send yourself messages.

Testing

Run npm test for the unit tests.

json2msg.js is a script that can convert lines of JSON into native messages. Use it to send messages to your host to see how it responds.

Pipe the output of your host to msg2json.js to see what its output looks like.

./json2msg.js < test.json | ./host/my_host.js | ./msg2json.js

On Windows:

node json2msg.js < test.json | node host\my_host.js | node msg2json.js

Logging

Enabling logging in Chrome can help find problems finding the manifest.

Quit Chrome first.

open -a Google\ Chrome --args --enable-logging --v=1

On Windows:

start chrome --enable-logging --v=1

View the log like this:

less ~/Library/Application\ Support/Google/Chrome/chrome_debug.log

On Windows:

type "C:\Users\%USERNAME%\AppData\Local\Google\Chrome\User Data\chrome_debug.log"

More info: http://www.chromium.org/for-testers/enable-logging

chrome-native-messaging's People

Contributors

acdibble avatar jdiamond avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.