
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
browser-run
Advanced tools
Transform stream that executes JavaScript it receives in a real browser and outputs console output
The easiest way of running code in a browser environment.
Bundles electronjs by default!
$ echo "console.log('Hey from ' + location); window.close()" | browser-run
Hey from http://localhost:53227/
$
Or use browser-run programmatically:
var run = require('browser-run');
var browser = run();
browser.pipe(process.stdout);
browser.end('console.log(location); window.close()');
$ browserify main.js | browser-run
or
var browserify = require('browserify');
var browser = require('browser-run');
browserify('main.js').bundle().pipe(browser()).pipe(process.stdout);
$ browser-run --help
Run JavaScript in a browser.
Write code to stdin and receive console output on stdout.
Usage: browser-run [OPTIONS]
Options:
--version Show version number [boolean]
-b, --browser Browser to use. Always available: electron. Available if
installed: chrome, firefox, ie, safari [default: "electron"]
--sandbox Enable electron sandbox [boolean] [default: true]
--basedir Set this if you need to require node modules in node mode
-h, --help Print help [boolean]
-p, --port Starts listening on that port and waits for you to open a
browser
-s, --static Serve static assets from this directory
-m, --mock Path to code to handle requests for mocking a dynamic back-end
-i, --input Input type. Defaults to 'javascript', can be set to 'html'.
-n, --node Enable nodejs apis in electron
By using --input html or { input: 'html' } you can provide a custom html file for browser-run to use. Keep in mind though that it always needs to have <script src="/reporter.js"></script> above other script tags so browser-run is able to properly forward your console.logs etc to the terminal.
By using --mock mock.js or { mock: 'mock.js'} you can provide a custom server-side implementation and handle all requests that are sent to paths beginning with /mock
mock.js needs to export a function that accepts req and res arguments for handling requests.
Example:
module.exports = function(req,res){
if (req.url === '/mock/echo') {
req.pipe(res)
}
}
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 electron. Available if installed:
chromefirefoxiesafaristatic: Serve static files from this directorymock: Path to code to handle requests for mocking a dynamic back-endinput: Input type. Defaults to javascript, can be set to html.node: Enable nodejs integration in electronsandbox: Enable electron sandbox. Default: true.basedir: Set this if you need to require node modules in node modeIf only an empty string is written to it, an error will be thrown as there is nothing to execute.
If you call window.close() inside the script, the browser will exit.
Stop the underlying webserver.
In environments without a screen, you can use Xvfb to simulate one.
This is a full example to run npm test. Refer to the last 2 lines in the YAML config:
on:
- pull_request
- push
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- run: npm install
- run: sudo apt-get install xvfb
- run: xvfb-run --auto-servernum npm test
Add this to your travis.yml:
addons:
apt:
packages:
- xvfb
install:
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- npm install
$ sudo apt-get install xvfb # or equivalent
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
$ browser-run ...
There is also an example Docker image. Source
With npm do
$ npm install browser-run # for library
$ npm install -g browser-run # for cli
This module is proudly supported by my Sponsors!
Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my Patreon. Not sure how much of my modules you're using? Try feross/thanks!
(MIT)
FAQs
Transform stream that executes JavaScript it receives in a real browser and outputs console output
The npm package browser-run receives a total of 1,667 weekly downloads. As such, browser-run popularity was classified as popular.
We found that browser-run demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.