• Stars
    star
    132
  • Rank 274,205 (Top 6 %)
  • Language
    JavaScript
  • Created over 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

More Repositories

1

Nustache

Logic-less templates for .NET
C#
585
star
2

harmonizr

bring tomorrow's Harmony to today's JavaScript
JavaScript
86
star
3

MQTT.ts

MQTT in TypeScript for Deno, Node.js, and browsers
TypeScript
51
star
4

html5-examples

Some HTML5 examples
JavaScript
27
star
5

todo.txt-ahk

An AutoHotKey GUI for working with todo.txt files.
15
star
6

NChanges

A tool for detecting API changes between assemblies
C#
13
star
7

rogue-sharp

A port of the original Rogue to C#
C
7
star
8

RoguePy

a framework for creating roguelikes in Python
Python
4
star
9

pointless

Point-free programming in JavaScript
JavaScript
4
star
10

autorunner

A tool that automatically runs executables whenever a target file or directory changes
C#
4
star
11

TradeCraft

A plugin for Minecraft
Java
3
star
12

UniCycle

Unicode character cycler plugin for Vim
Vim Script
3
star
13

discoverable

discover packages and modules to compose your Node.js applications
JavaScript
3
star
14

VerifyThat

A method to do asserts that derive failure messages from your code
C#
3
star
15

docker-mongo

2
star
16

mqtt-spy

MQTT proxy server for debugging
JavaScript
2
star
17

dotvim

My Vim files.
Vim Script
2
star
18

AutoHotTip

AutoHotKey script to display random tips based on the active application
2
star
19

xqtt

JavaScript
2
star
20

posixtz

posix time zone formatter and parser
JavaScript
2
star
21

db.js

High-level API for working with client-side databases
JavaScript
1
star
22

docker-hubot

JavaScript
1
star
23

nodejs-for-dotnet-devs

JavaScript
1
star
24

control.js

easy control panels for experimenting with values
JavaScript
1
star
25

docker-hubot-hipchat

1
star
26

CustomTestRunners

Custom test runners for unit testing with Python
Python
1
star
27

sandbox

My sandbox for code that hasn't made it into its own project
C#
1
star