Scripting

Paid Feature

Scripting rules execute JavaScript scripts written by the user.

Once saved, the scripting rule runs the code and check if global functions onRequest and onResponse exist, both of which are optional. Ongoing flows that match the rule's filter will be wrapped into a JS Object and passed into onRequest and onResponse if any.

If a flow has been passed into either of the two functions, so long as the function didn't return "discard", the flow is considered affected by the rule, even if the function didn’t actually do any changes.

Example

function onRequest(flow) {
    let request = flow.request;
    let url = request.url;
    if (url.host === 'proxie.app' && request.method === 'POST') {
        url.pathname = '/test.html';
        let form = request.body.form;
        if (form != null) {
            form.set('username', 'awesome');
            flow.log('Changed username to "awesome"');
        }
    }
}

let count = 1;
function onResponse(flow) {
    let url = flow.request.url;
    let response = flow.response;
    if (url.href === 'https://proxie.app/test.html') {
        response.headers.delete('etag');
        response.headers.delete('cache-control');

        let $ = response.body.html;
        $('head > title').text('MitM-ed: ' + count.toString());
        count++;
    }
}

API Reference

onRequest, onResponse

Parameters

Return Values

  • undefined: Let the rule apply the changes to the flow.
  • 'abort': Abort the connection.
  • 'discard': Discard whatever changes were made to the flow in the function.

Flow

Methods

log(String, ...)

Attach to the flow a log, which can later be viewed at the “Log” section in the inspector.

Properties

request and response are not assignable.

The response property does not exist when onRequest is called. The request property always exists, but mutating it in onResponse does not have any effect.

HTTPRequest

url, headers and body are not assignable, but you can mutate them by assigning their properties or calling their methods.

Names in headers are case-insensitive.

HTTPResponse

headers and body are not assignable, but you can mutate them by assigning their properties or calling their methods.

Names in headers are case-insensitive.

HTTPBody

These 4 properties might be undefined if not applicable.

html is a cheerio object constructed by Proxie in a manner of cheerio.load(body.text). You can mutate it using jQuery-like APIs.

form and html are not assignable.

NameValueCollection

set(name: String, value: String)

Sets a new value for an existing name, or adds the entry if it does not already exist.

append(name: String, value: String)

Appends a new value onto an existing name, or adds the entry if it does not already exist.

delete(name: String)

Deletes a name and its value(s).

get(name: String): String

Returns the first value associated with a given name.

has(name: String): Boolean

Returns a boolean stating whether a certain name exists.

entries(): [[String, String]]

Returns name/value pairs.

values(): [String]

Returns all the values.

keys(): [String]

Return all the names.