JSPM

  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q61039F
  • License MIT

Otiluke intercepts JavaScript code within HTML pages and Node modules

Package Exports

  • otiluke
  • otiluke/node

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (otiluke) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Otiluke otiluke-logo

Otiluke is a npm module that intercepts JavaScript within HTML pages and Node modules. To install:

npm install otiluke

Intercept JavaScript within Node modules:

var Otiluke = require("otiluke");
function intercept (url) {
  console.log("Intercepting " + url);
  return function (js) {
    return "console.log('Executing ' + " + JSON.stringify(url) + ");\n" + js;
  }
}

Otiluke({
  setup: ".absolute/path/to/setup.js",
  intercept: intercept,
  main: "/absolute/path/to/main.js",
  out: "/absolute/path/to/bundle.js"
});

Under the hood, Browserfiy explores the require graph starting from the entry point options.main. Whenever a new file is required, the function options.intercept is called with the url path to that file. If this function returns a false value, no transformation is applied to the content of the file. If the intercept functions returns a true value, it should be function that transform JavaScript code. The transformed code is bundled and preceded by options.setup which may itself points to the entry point of a node module. The result is output to options.out or stdout if this option is no provided.

Intercept JavaScript within HTML pages:

var Otiluke = require("otiluke");
Otiluke({
  setup: "/absolute/path/to/setup.js",
  intercept: intercept
  port: 8080
});

To intercept JavaScript code within HTML pages, Otiluke deploy an MITM Proxy on local port options.port. This proxy intercepts every requests and transform their responses. The options setup and intercept are similar to the ones of the Node mode. Two modifications should be done on your browser -- here Firefox but should works on other browsers as well -- before deploying the MITM proxy:

  1. You have to indicate Firefox that you trust Otiluke's root certificate. Go to about:preferences#advanced then click on Certificates then View Certificates. You can now import Otiluke's root certificate which can be found at /path/otiluke/mitm/ca/cacert.pem. Note that you can reset all Otiluke's certificates with

    node /path/to/otiluke/mitm/ca/reset.js --hard
    demo-screenshot
  2. You have to redirect all Firefox requests to the local port where the MITM proxy is deployed. Go again to about:preferences#advanced then click on Network then Settings.... You can now tick the checkbox Manual proxy configuration and Use this proxy server for all protocols. The HTTP proxy fields should be the localhost 127.0.0.1 and the port given in the options.

    demo-screenshot