Skip to content
This repository

A pure-JavaScript browser environment with early rubygem support.

branch: envjsrb

This branch is 0 commits ahead and 0 commits behind envjsrb

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 DTD
Octocat-spinner-32 bin
Octocat-spinner-32 dist
Octocat-spinner-32 gm
Octocat-spinner-32 htmlparser
Octocat-spinner-32 jsl
Octocat-spinner-32 lib
Octocat-spinner-32 licenses
Octocat-spinner-32 rhino
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .jslintrbrc
Octocat-spinner-32 .project
Octocat-spinner-32 CHANGELOG.rdoc
Octocat-spinner-32 Makefile
Octocat-spinner-32 Manifest.txt
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 Wakefile
Octocat-spinner-32 build.xml
Octocat-spinner-32 envjs.gemspec


The Johnson fork of env.js is pretty much mothballed (which is already pretty much true of Johnson, given the rise of v8 and the difficulty moving Johnson to 1.9.*). The current best practices seem to be based on a headless webkit.



A browser environment for javascript interpreters.

This is a fork of the env.js project ( See that link for env.js details. This fork is based on the Johnson Ruby gem (


For now, you can install the envjs gem by installing Johnson:

gem install johnson --prerelease

and then installing the envjs gem with

gem install envjs

Using envjs interactively

The envjs gem provides the envjsrb command, which functions as an extended version of the Johnson javascript shell. For example:

 mbp:env-js smparkes$ envjsrb
 js> this
 => [object Window 0]
 js> window.location
 => about:blank
 js> document.innerHTML
 => "<html><head><title></title></head><body></body></html>"

Embedding envjs

It's also possible to embed the envjs interpreter similar to the way it's done in Johnson, e.g.,

require 'rubygems' # if necessary
require 'johnson/tracemonkey'
require 'envjs/runtime'

envjs =
envjs.extend Envjs::Runtime
window = envjs.evaluate("window")
puts window.location.to_s # == "about:blank"
puts window.document.innerHTML # == "<html><head><title></title></head><body></body></html>"

You need the Runtime#wait at the end to give env.js's event loop a chance to execute queued events and timers. You may need to do this at other times as well, depending on the asynchronous nature of your application.


See and

Something went wrong with that request. Please try again.