# browser-run2

> Transform stream that executes JavaScript it receives in a real browser and outputs console output

Latest version **1.0.3** (published 2014-10-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install browser-run2
pnpm add browser-run2
yarn add browser-run2
bun add browser-run2
```

Provides the command `browser-run2`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2014-10-06 |
| First published | 2014-10-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tim Oxley |
| Maintainers | timoxley |
| Keywords | browser, stream, phantomjs, test, headless, duplex |

## Links

- npm: https://www.npmjs.com/package/browser-run2
- Repository: https://github.com/timoxley/browser-run
- Issues: https://github.com/timoxley/browser-run/issues
- npm.io page: https://npm.io/package/browser-run2

## Dependencies (8)

- [enstore](https://npm.io/package/enstore.md) ~0.0.1
- [through](https://npm.io/package/through.md) ~2.3.6
- [duplexer](https://npm.io/package/duplexer.md) ~0.1.1
- [optimist](https://npm.io/package/optimist.md) ~0.6.1
- [browserify](https://npm.io/package/browserify.md) ~6.0.2
- [utf8-stream](https://npm.io/package/utf8-stream.md) 0.0.0
- [xhr-write-stream](https://npm.io/package/xhr-write-stream.md) ~0.1.2
- [browser-launcher2](https://npm.io/package/browser-launcher2.md) ~0.4.3

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.3 (latest) — 2014-10-06
- 1.0.2 — 2014-10-06
- 1.0.1 — 2014-10-06

## README

# browser-run2

The easiest way of running code in a browser environment.

Same as [juliangruber/browser-run](https://github.com/juliangruber/browser-run), but uses
[benderjs/browser-launcher2](https://github.com/benderjs/browser-launcher2) instead of [substack/browser-launcher](https://github.com/substack/browser-launcher), due to [substack/browser-launcher/issues/34](https://github.com/substack/browser-launcher/issues/34).

## Installation

```bash
$ npm install browser-run2    # for library
$ npm install -g browser-run2 # for cli
```

## Usage

```bash
$ echo "console.log('Hey there from ' + document.location)" | browser-run
Hey there from http://localhost:53227/
```

Or use `browser-run` programmatically:

```js
var run = require('browser-run2');

var browser = run();
browser.pipe(process.stdout);
browser.write('console.log(document.location)');
browser.end();
```

## Example with browserify

```bash
$ browserify main.js | browser-run
```

or

```js
var browserify = require('browserify');
var browser = require('browser-run2');

browserify('main.js').bundle().pipe(browser()).pipe(process.stdout);
```

## CLI

```bash
$ browser-run --help
Run JavaScript in a browser.
Write code to stdin and receive console output on stdout.
Usage: browser-run [OPTIONS]

Options:
  --browser, -b  Browser to use. Available if installed: chrome, firefox, ie, phantom, safari  [default: "phantom"]
  --port, -p     Starts listening on that port and waits for you to open a browser
  --help, -h     Print help

```

## API

### run([opts])

Returns a duplex stream and starts a webserver.

`opts` can be:

* `port`: If speficied, no browser will be started, so you can point one yourself to `http://localhost/<port>`
* `browser`: Browser to use. Defaults to `phantom`. Available if installed:
  * `chrome`
  * `firefox`
  * `ie`
  * `phantom`
  * `safari`

### run#stop()

Stop the underlying webserver.

## License

MIT

---
_Source: https://npm.io/package/browser-run2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
