All Projects → juliangruber → Browser Run

juliangruber / Browser Run

The easiest way of running code in a browser environment

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Browser Run

siteshooter
📷 Automate full website screenshots and PDF generation with multiple viewport support.
Stars: ✭ 63 (-83.33%)
Mutual labels:  phantomjs
java-phantomjs-wrapper
A Java wrapper around the PhantomJS binaries including a packaged HTML to PDF render script
Stars: ✭ 54 (-85.71%)
Mutual labels:  phantomjs
Browsershot
Convert HTML to an image, PDF or string
Stars: ✭ 3,526 (+832.8%)
Mutual labels:  phantomjs
kick-off-web-scraping-python-selenium-beautifulsoup
A tutorial-based introduction to web scraping with Python.
Stars: ✭ 18 (-95.24%)
Mutual labels:  phantomjs
img-cli
An interactive Command-Line Interface Build in NodeJS for downloading a single or multiple images to disk from URL
Stars: ✭ 15 (-96.03%)
Mutual labels:  phantomjs
node-qunit-phantomjs
Run QUnit unit tests in a headless PhantomJS instance without using Grunt
Stars: ✭ 36 (-90.48%)
Mutual labels:  phantomjs
pyderman
Install Selenium-compatible Chrome/Firefox/Opera/PhantomJS/Edge webdrivers automatically.
Stars: ✭ 24 (-93.65%)
Mutual labels:  phantomjs
Comic Dl
Comic-dl is a command line tool to download manga and comics from various comic and manga sites. Supported sites : readcomiconline.to, mangafox.me, comic naver and many more.
Stars: ✭ 365 (-3.44%)
Mutual labels:  phantomjs
chromate
Automate Headless Chrome.
Stars: ✭ 36 (-90.48%)
Mutual labels:  phantomjs
Slimerjs
A scriptable browser like PhantomJS, based on Firefox
Stars: ✭ 2,984 (+689.42%)
Mutual labels:  phantomjs
pyCreeper
一个用来快速提取网页内容的信息采集(爬虫)框架, 实现了对网页的动态加载与控制。
Stars: ✭ 25 (-93.39%)
Mutual labels:  phantomjs
TqExtension
Test your Drupal 7 (D8 in progress) sites easier with TqExtension for Behat.
Stars: ✭ 13 (-96.56%)
Mutual labels:  phantomjs
Responsive mockups
Takes screenshots of a webpage in different resolutions and automatically applies it to mockup templates.
Stars: ✭ 274 (-27.51%)
Mutual labels:  phantomjs
crawlkit
A crawler based on Phantom. Allows discovery of dynamic content and supports custom scrapers.
Stars: ✭ 23 (-93.92%)
Mutual labels:  phantomjs
Node Html Pdf
📄 Html to pdf converter in nodejs. It spawns a phantomjs process and passes the pdf as buffer or as filename.
Stars: ✭ 3,364 (+789.95%)
Mutual labels:  phantomjs
phantom-lord
Handy API for Headless Chromium
Stars: ✭ 24 (-93.65%)
Mutual labels:  phantomjs
wdm4j
Automatic Selenium WebDriver binaries management for java
Stars: ✭ 16 (-95.77%)
Mutual labels:  phantomjs
Grunt Mocha
[MOVED] Grunt task for running mocha specs in a headless browser (PhantomJS)
Stars: ✭ 371 (-1.85%)
Mutual labels:  phantomjs
Phantomjs Node
PhantomJS integration module for NodeJS
Stars: ✭ 3,544 (+837.57%)
Mutual labels:  phantomjs
Phantomjs
Go client for PhantomJS.
Stars: ✭ 278 (-26.46%)
Mutual labels:  phantomjs

browser-run

The easiest way of running code in a browser environment.

Bundles electronjs by default!

build status downloads

Usage

$ 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()');

Example with browserify

$ browserify main.js | browser-run

or

var browserify = require('browserify');
var browser = require('browser-run');

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

CLI

$ 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. Always available: electron. Available if installed: chrome, firefox, ie, safari  [default: "electron"]
  --port         Starts listening on that port and waits for you to open a browser
  --static       Serve static assets from this directory
  --mock         Path to code to handle requests for mocking a dynamic back-end
  --input        Input type. Defaults to 'javascript', can be set to 'html'.
  --node         Enable nodejs apis in electron
  --basedir      Set this if you need to require node modules in node mode
  --help         Print help

Custom html file

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.

Dynamic back-end mock

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)
  }
}

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 electron. Available if installed:
    • chrome
    • firefox
    • ie
    • safari
  • static: Serve static files from this directory
  • mock: Path to code to handle requests for mocking a dynamic back-end
  • input: Input type. Defaults to javascript, can be set to html.
  • node: Enable nodejs integration in electron
  • basedir: Set this if you need to require node modules in node mode

If 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.

run#stop()

Stop the underlying webserver.

Headless testing

In environments without a screen, you can use Xvfb to simulate one.

GitHub Actions

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/[email protected]
    - run: npm install
    - run: sudo apt-get install xvfb
    - run: xvfb-run --auto-servernum npm test

Travis

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

Full example.

Any gnu/linux box

$ sudo apt-get install xvfb # or equivalent
$ export DISPLAY=':99.0'
$ Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
$ browser-run ...

Docker

There is also an example Docker image. Source

Installation

With npm do

$ npm install browser-run    # for library
$ npm install -g browser-run # for cli

Sponsors

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!

License

(MIT)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].