• Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    TypeScript
  • License
    ISC License
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hackium

Hackium is a CLI tool, a browser, and a platform for analyzing and manipulating web sites.

Hackium vs Puppeteer?

Puppeteer is an automation framework aimed at developers who need to automate and test the web headlessly. Hackium exposes Puppeteer's automation framework to an interactive version of Chromium and extends it with features aimed at web power users. Features that Puppeteer will not adopt for compatibility or maintenance reasons may find a home in Hackium.

Hackium started as Puppeteer scripts and will continue to directly rely on Puppeteer unless both project's focus diverge passed the point of code sharability.

Core differences

  • Hackium exposes access to Chrome's Extension API via puppeteer-extensionbridge.
  • Hackium simulates human behavior for mouse movement and keyboard events, vs moving in straight lines or typing rapidly all at once.
  • Hackium prioritizes intercepting and transforming responses.
  • Hackium includes a plugin framework to hook into the hackium lifecycle.
  • Hackium injects an in-page client to extend functionality to pages and the console.
  • Hackium is not meant to run headlessly. It can, but Chromium loses functionality when headless.
  • Hackium includes a REPL to test and automate a live browser session.
  • Puppeteer scripts can be used with Hackium with few to no changes, Hackium scripts can not be used by Puppeteer.
  • and a lot more.

Status

Experimental.

Hackium combines many disparate – sometimes experimental – APIs into one and as such, breaking changes can come from anywhere. Rather than limit public APIs to make it easier to stay backwards compatible, Hackium exposes as much as it can. You're in control. Backwards compatbility is a priority, but please consider the reality of depending on Hackium before building anything mission-critical.

Installation

Install hackium globally with:

$ npm install -g hackium

NOTE: NodeJS version 12.x or higher is required in order for you to be able to use Hackium.

Using NodeJS version 10.x you'll be able to use the hackium init ... functionality of the CLI, but you won't able to run Hackium and its REPL.

You can install Hackium locally but every install downloads an additional Chromium installation so local installs should be avoided unless necessary.

Using Hackium from node

Hackium can be used like Puppeteer from standard node.js scripts, e.g.

const { Hackium } = require('hackium');

(async function main() {
  const hackium = new Hackium();
  const browser = await hackium.launch();
  //...
})();

API

Hackium extends and overrides [Puppeteer] behavior regularly and a passing understanding of how to use Puppeteer is important for developer with Hackium. If you're only wiring together plugins or running a pre-configured project, you can skip the Puppeteer docs.

Core dependencies

These projects or protocols provide valuable documentation that will help you get more out of Hackium

Hackium Plugins

These are projects built with Hackium and JavaScript interception in mind, though are separate on their own.

Hackium

Import the Hackium class and instantiate a hackium instance with the core options.

const { Hackium } = require('hackium');

const hackium = new Hackium({
  plugins: [
    /* ... */
  ],
});

.launch()

Like [Puppeteer], hackium.launch() launches a Chrome instance and returns a HackiumBrowser instance. Refer to Puppeteer's Browser section for documentation.

.cliBehavior()

hackium.cliBehavior() runs through the Hackium configuration as if it was called via the command line. This is useful when migrating from a simple hackium.config.js to a node.js project.

Returns a browser instance. Refer to Puppeteer's Browser section for further documentation.

Example:

const { Hackium } = require('hackium');

const hackium = new Hackium({
  plugins: [
    /* ... */
  ],
});

async function main() {
  const browser = await hackium.cliBehavior();
}

.pause(options)

Initializes a REPL and returns a promise that resolves only when hackium.unpause() (or unpause() in the REPL) is called. Use pause() with async/await to troubleshoot a script or to inject manual work into an automated process.

Options:

  • repl : pass false to disable the REPL or an object to use as the REPL context.

Example:

const { Hackium } = require('hackium');

const hackium = new Hackium();

async function main() {
  const browser = await hackium.launch();
  const [page] = await browser.pages();
  await hackium.pause({ repl: { page } });
}

.startRepl(context)

Initializes a REPL, adding the passed context to the REPL context. Will close an existing REPL if it is open.

Example:

const { Hackium } = require('hackium');

const hackium = new Hackium();

async function main() {
  const browser = await hackium.launch();
  const [page] = await browser.pages();
  await hackium.startRepl({ page });
}

.closeRepl()

Closes a manually opened REPL.

HackiumBrowser

HackiumBrowser extends Puppeteer's Browser and manages instrumentation of the browser.

.extension

Hackium Browser comes pre-configured with puppeteer-extensionbridge available via browser.extension. See puppeteer-extensionbridge for documentation.

.clearSiteData(origin)

Clears everything associated with the passed origin.

const { Hackium } = require('hackium');

const hackium = new Hackium();

async function main() {
  const browser = await hackium.launch();
  await browser.clearSiteData('google.com');
}

HackiumPage

HackiumPage extends Puppeteer's Page and manages instrumentation of each created page.

.connection

Each page has a Chrome DevTools Protocol session instantiated and accessible via .connection. See Chrome Devtools Protocol for documentation.

.forceCacheEnabled(boolean)

This bypasses Puppeteer's intelligent cache settings and sends a direct request to Network.setCacheDisabled with your argument.

.mouse

Hackium's mouse class overrides Puppeteer's mouse behavior to simulate human movement. This is transparent in usage but means that movement actions are not instantaneous. Refer to Puppeteer's Mouse section for further documentation.

.mouse.idle()

Generates idle mouse movement behavior like scrolling, moving, and clicking.

.keyboard

Like mouse, the Hackium keyboard class simulates human behavior by typing at a casual speed with varying intervals. Refer to Puppeteer's Keyboard section for documentation.

Command line usage

Open hackium with the hackium command and Hackium will start the bundled Chromium.

$ hackium

Interceptor modules

An interceptor module needs to expose two properties, intercept and interceptor. intercept is a list of request patterns to intercept and interceptor is a JavaScript function that is called on every request interception.

More information on request patterns can be found at [puppeteer-interceptor] and Chrome Devtools Protocol#Fetch.RequestPattern

hackium init

use hackium init to initialize a configuration file or common boilerplate scripts.

hackium init config will generate a configuration file and, optionally through the wizard, boilerplate scripts.

hackium init interceptor will provide a list of interceptor templates to generate

hackium init injection will generate a template script to inject in the page.

hackium init script will generate a sample Hackium script that can be executed via hackium -e script.js

Default commmand options

Options:
  --version          Show version number                               [boolean]
  --help             Show help                                         [boolean]
  --headless         start hackium in headless mode   [boolean] [default: false]
  --pwd              root directory to look for support modules
                           [default: "/Users/jsoverson/development/src/hackium"]
  --adblock          turn on ad blocker                         [default: false]
  --url, -u          starting URL
  --env              environment variable name/value pairs (e.g. --env
                     MYVAR=value)                          [array] [default: []]
  --inject, -E       script file to inject first on every page
                                                           [array] [default: []]
  --execute, -e      hackium script to execute             [array] [default: []]
  --interceptor, -i  interceptor module that will handle intercepted responses
                                                           [array] [default: []]
  --userDataDir, -U  Chromium user data directory
                        [string] [default: "/Users/jsoverson/.hackium/chromium"]
  --devtools, -d     open devtools automatically on every tab
                                                       [boolean] [default: true]
  --watch, -w        watch for configuration changes  [boolean] [default: false]
  --plugin, -p       include plugin                        [array] [default: []]
  --timeout, -t      set timeout for Puppeteer                  [default: 30000]
  --chromeOutput     print Chrome stderr & stdout logging
                                                      [boolean] [default: false]
  --config, -c                                            [string] [default: ""]

Debugging

Set the DEBUG environment variable with a wildcard to print debug logs to the console, e.g.

$ DEBUG=hackium* hackium

Configuration

Hackium looks for hackium.json or hackium.config.js files in the current directory for configuration. Hackium merges or overrides configuration from the command line arguments. See the Arguments definition for valid configuration options.

REPL

Hackium's REPL exposes the browser, page, and protocol instances for rapid prototyping.

Additional REPL context:

  • page: active page
  • browser: browser instance
  • cdp: chrome devtools protocol connection
  • extension: chrome extension API bridge

Interceptors

Interceptor modules define two things, a pattern that matches against URLs and an interceptor which is passed both the request and the response and can optionally return a modified response to send to the browser.

Use hackium init interceptor to see examples of different interceptors

Injecting JavaScript

Injecting JavaScript before any other code loads is the only way to guarantee a pristine, unadulterated environment. Injected JavaScript can take any form and will run at the start of every page load.

Use hackium init injection to see an example of injected JavaScript that augments the in-page hackium client.

Hackium Scripts

Hackium scripts are normal JavaScript scripts surrounded by an async wrapper function and a context primed with variables to reduce boilerplate. Hackium launches a browser and sets the hackium, browser, and page values automatically so you can rapidly get running.

Use hackium init script to generate a sample script.

Plugin API

Plugins are plain JavaScript objects with properties named after Hackium lifecycle events. See hackium-plugin-preserve-native for an example of a plugin that injects JavaScript into the page to preserve native functions.

Lifecycle methods

  • preInit : called before a Hackium instance is initialized. Receives the hackium instance and the passed options.
  • postInit : called after a Hackium instance is initialized. Receives the hackium instance and the final options.
  • preLaunch : called before the browser is launched. Receives the hackium instance and the launch options.
  • postLaunch : called after the browser is launched. Receives the hackium instance, browser instance, and final launch options.
  • postBrowserInit : called after running browser initializing and instrumentation logic. Receives the hackium instance, browser instance, and final launch options.
  • prePageCreate : called before a Page instance is created. Receives a browser instance.
  • postPageCreate : called after a Page instance is created. Receives a browser instance and a page instance.

Boilerplate plugin

let plugin: Plugin = {
  preInit: function (hackium, options) {},
  postInit: function (hackium, options) {},
  preLaunch: function (hackium, launchOptions) {},
  postLaunch: function (hackium, browser, finalLaunchOptions) {},
  postBrowserInit: function (hackium, browser, finalLaunchOptions) {},
  prePageCreate: function (browser) {},
  postPageCreate: function (browser, page) {},
};

hackium = new Hackium({
  plugins: [plugin],
});

More Repositories

1

node-to-rust

Rust
1,372
star
2

preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
JavaScript
363
star
3

grunt-preprocess

Preprocess files based off environment configuration
JavaScript
294
star
4

JavaScript-Particle-System

2d JavaScript Particle System with gravity field simulation
JavaScript
242
star
5

grunt-env

Grunt task to automate environment configuration for future tasks
JavaScript
224
star
6

grunt-plato

Generate static analysis reports with plato through grunt
JavaScript
206
star
7

shift-refactor

A suite of utilities to query and modify JavaScript source
TypeScript
131
star
8

grunt-open

Open urls and files from a grunt task
JavaScript
112
star
9

jquery.pulse.js

jQuery Pulse Animation Plugin
CSS
82
star
10

puppeteer-interceptor

Easy request interception/response modification for puppeteer
TypeScript
51
star
11

rcl

A websocket bridge for debug logging from browser to server
JavaScript
44
star
12

grunt-contrib-jasmine-example

Example application to help get you started using jasmine through grunt
JavaScript
42
star
13

grunt-strip

Strip JavaScript nodes (like console.*) out of your source code
JavaScript
42
star
14

deobfuscating-js-streams

JavaScript
27
star
15

gitfaq

organized git faq
SCSS
26
star
16

workshop-reverse-engineering

JavaScript
23
star
17

shift-interpreter

TypeScript
22
star
18

jsconsole

JavaScript console/repl styled after chrome devtools.
JavaScript
22
star
19

RetwisJS

Port of Redis's Twitter clone, retwis for node.js
19
star
20

puppeteer-extra-interceptor

Puppeteer-extra plugin for puppeteer-interceptor
TypeScript
18
star
21

es6repl

reusable babel repl
JavaScript
15
star
22

Backbone.Augment

Simple plugin/addon functionality for Backbone Views, Models, and Collections.
JavaScript
15
star
23

puppeteer-extensionbridge

Expose the Chrome extension API to puppeteer
TypeScript
13
star
24

javascript-deobfuscation-AMA

General questions about deobfuscating JavaScript
13
star
25

grunt-jasmine-runner-example

Example setup for grunt-jasmine-runner
JavaScript
12
star
26

badjs.org

CSS
12
star
27

shift-query-cli

Command line tool to query AST nodes in JavaScript source files.
JavaScript
11
star
28

combolist-generator

JavaScript
10
star
29

texture.js

Basic implementation of normal mapped textures in javascript
JavaScript
10
star
30

stream-unzip

A streaming unzip library for rust projects
Rust
9
star
31

html5hub-particlesystem

Particle System demo for html5hub
JavaScript
8
star
32

js-identifiers

JavaScript
8
star
33

karma-commonjs-example

Example repo showing commonjs tests running on command line as well as in karma
JavaScript
7
star
34

shift-visualizer

Visualizer for the Shift AST format
JavaScript
5
star
35

string-format

Sprintf inspired string format method.
JavaScript
5
star
36

typescript-boilerplate

Boilerplate TypeScript project with mocha, eslint, prettier, and Visual Studio Code preconfigured
TypeScript
4
star
37

refactor-plugin-common

TypeScript
4
star
38

shift-identifiers

Find similar identifiers across a source file
JavaScript
4
star
39

marionette.augment.inlineregions

JavaScript
4
star
40

grunt-require-dir

Task to bundle up a directory of AMD modules into one accessor module
JavaScript
3
star
41

fromgit

TypeScript
3
star
42

shift-complexity

Complexity analysis for JavaScript source code.
JavaScript
3
star
43

liquid-json

A library to parse structured JSON with embedded liquid templates
Rust
3
star
44

apex-wip

TypeScript
3
star
45

hackium-plugin-visiblecursor

JavaScript
3
star
46

box2d-intro-amd

Seth Ladd's excellent box2d intro migrated to a modular structure with requirejs.
JavaScript
3
star
47

gh-cloneall

Utility to clone all github repos for a user or organization
JavaScript
3
star
48

concentric-circle-illusion

Visualization on html canvas of the classic optical illusion http://i.imgur.com/p2yeT.jpg
JavaScript
3
star
49

AMD_RequireJS-slides

Talk given to SanDiegoJS on Jan 10, 2012
JavaScript
2
star
50

believable

TypeScript
2
star
51

randomfarts.com

HTML
2
star
52

AMD-urlParams

A query string parser in AMD format for require.js, curl.js, etc
JavaScript
2
star
53

auto-cli-replay

Automatically create CLI GIFs with simulated typing, dynamic interactivity, and more.
Shell
2
star
54

git-spread

Run git commands across multiple directories
Shell
2
star
55

es6-repl

web component wrapping the es6repl
JavaScript
2
star
56

interpreter-context-jsdom

TypeScript
2
star
57

widl2json

WIDL to JSON converter
JavaScript
2
star
58

hackium-plugin-preserve-native

TypeScript
2
star
59

chrome-devtools-slides

Slides for sandiego.js July talk
JavaScript
2
star
60

jsperf-common

List of good jsperf benchmarks for common situations
1
star
61

browserusage.org

Site to simply display worldwide browser usage stats.
CSS
1
star
62

wacl

Rust
1
star
63

perl-Parallel-Forking-Manager

Thread manager for Moose objects with role 'Forking'
Perl
1
star
64

gcp-simple-secrets

TypeScript
1
star
65

cordova-flashcard-app

Objective-C
1
star
66

perl-MooseX-Role-Forking

Forking/Threading role for Perl Moose
Perl
1
star
67

refactor-plugin-unsafe

TypeScript
1
star
68

lockyourdamncomputer.com

CSS
1
star
69

phaser-mario

JavaScript
1
star
70

python-game

Python
1
star
71

example-cli

Rust
1
star
72

gh-action-test

TypeScript
1
star
73

dotfiles

Shell
1
star
74

jsoverson.github.com

stub
1
star
75

fromgit-test

1
star
76

mp-tuning

Rust
1
star
77

allfaqs

HTML
1
star
78

wapc-rust-template

Makefile
1
star
79

apex-template

TypeScript
1
star
80

seeded-random-utils

TypeScript
1
star
81

wit-example

Rust
1
star
82

d3-starter

basic repo that includes what's necessary to experiment with d3
CSS
1
star