Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
CommonJS modules for developing Chrome Extensions
JavaScript
tag: v0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
examples/basic
lib
.gitignore
.npmignore
LICENSE.md
README.md
index.js
package.json

README.md

chrx

chrx is a collection of CommonJS modules for developing Chrome Extensions. This project is an attempt to collect some useful abstractions for developing Chrome Extensions and distribute them via npm.

Installation

Install via npm:

$ npm install chrx

Usage

Reference using require:

var chrx = require('chrx')

chrx is designed to be used with browserify (or watchify). This approach is demonstrated in the included examples. It's also explained in this Chrome Apps Office Hours video.

Background API

Modules and methods for use in background or event scripts.

tabs.getActive([options][, callback])

Gets the active tab in the active window.

tabs.getActive(function(err, tab){})

options

  • protocol

tabs.executeScripts(options[, callback])

Executes content scripts in a tab.

tabs.executeScripts({
    tab: tab,
    scripts: ['underscore.js', 'jquery.js']
}, function(err, tab){})

options

  • tab (required)
  • scripts (required)
  • runAt

tabs.executeScriptsInActive(options[, callback])

Executes content scripts in the active tab.

tabs.executeScriptsInActive({
    scripts: ['underscore.js', 'jquery.js']
}, function(err, tab){})

options

  • scripts (required)
  • runAt

window.getActive([callback])

Gets the active window.

window.getActive(function(err, win){})

Content API

Modules and methods for use in content scripts.

frame.create(options)

Creates an iframe in in the web page. This is useful for creating sandboxed overlay applications that run on top of the current page.

var f = frame.create({
    src: 'pages/menu.html',
    css: {
        left: '10px',
        top: '10px',
        width: '100px',
        height: '100px'
    }
})

options

  • src (required)
  • css

f.on(event[, callback])

Bind a callback function to the frame. The callback will be invoked whenever the event is fired.

f.on('hide', f.hide)

f.trigger(event[, *args])

Triggers callbacks for the given event. Subsequent arguments to trigger will be passed along to the event callbacks.

f.trigger('alert', 'Hello!')

frame.parent()

Creates an object that is "bound" to the parent context. Used in the context of a child frame, this object allows for simple two-way communication with the parent.

var p = frame.parent()

p.on(event[, callback])

Bind a callback function to the frame. The callback will be invoked whenever the event is fired.

p.on('alert', displayAlertInsideTheFrame)

p.trigger(event[, *args])

Triggers callbacks for the given event. Subsequent arguments to trigger will be passed along to the event callbacks.

p.trigger('hide')

Tests

Install dependencies and run:

$ npm install
$ npm test

License

MIT License, see LICENSE for details.

Something went wrong with that request. Please try again.