GithubHelp home page GithubHelp logo

browserjet's Introduction

Browserjet - headless webkit with a node.js interface

Browserjet gives you access to headless webkit which is often useful for site scraping, testing, page screenshots, saving pdfs, and more.

Installing

To install the node.js module simply use

npm install browserjet

Currently supported is Linux 32/64

Usage

Browserjet provides and easy to use API. To load, manipulate, and save a page as a png you can use:

var browserjet = require('browserjet'),
    browser = browserjet.createBrowser();
    
browser
  .chain
  .get("http://nodejs.org/")
  .run(function() {
    document.body.style.backgroundColor = '#000066';
  })
  .save('nodejs.png')
  .end(function(err) {
    if(err) { throw err; }
  });

API

browser.get(url, callback)

Fetch the given page and pass ok to callback after completely loaded

browser.get("http://google.com/", function(err, ok) {
  if(err) { throw err; }
  console.log("Page loaded");
});

Also see examples/loadspeed.js for another example

browser.setHtml(html, callback)

Set the browsers content to the given HTML and run callback when completely loaded

browser.setHtml("<html><body>Hello World</body></html>");

browser.html(callback)

Return the browsers HTML

browser.run(js, callback)

Run the supplied javascript synchronously in the context of the currently loaded page and pass the last result to the callback

browser.run("document.getElementsByTagName('p').length", function(err, count) {
  console.log("There are "+count+" paragraphs in the currently loaded page");
});

browser.runAsync(js, callback)

An advanced command to run the given javascript asynchronously in the context of the currently loaded page, browserjet.callback is exposed on the page and returns its parameter to the callback.

browser.runAsync(function() {
  // This code runs in the context of the loaded page
  setTimeout(function() {
    browserjet.callback(document.title);
  }, 1000);
}, function(err, title) {
  console.log(title);
});

After 1s, the title of the currently loaded page is printed

Also see examples/qunit.js for another example of runAsync

browser.save(filename, callback)

Saves the current page, supported file extensions are image formats (png, gif, svg, tiff) and pdf

browser.save("page.pdf");
browser.save("/tmp/page.png");

Tests

The browserjet tests use expresso, which you can install with

npm install -g expresso

Then in the module directory you can just run

expresso

browserjet's People

Contributors

briankircho avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.