Today I fixed a small JS loader bug. Since the loader’s behaviour between testing/staging and production environment is a little different, I want to double check and testing the fix by hijacking the online loader script and replacing it with the fixed content in Chrome.

There are lots of proxy apps can do the hijack and editing the response data on the fly. Well, I found this proxy.app claiming it could intercept HTTP requests. It was in a promotion celebrating up coming new version and only asking for a price as low as $0.99. Such bargain, much steal.

Don’t buy it.

This app crashes a lot. A LO…OOOT. Also the interaction is confusing.

So I glued some simple code with the help from Proxy SwichyOmega to cover my needs.

Prepare

  • A simple http server.
  • Chrome and Proxy SwitchyOmega plugin installed.

Create a simple server

The server simply returns the content you wanna replace for any incoming request. Just write it in your favoriate language.

Node version:

require('http').createServer(function (req, res) {
    console.log('get request ' + req.url + ' ...')

    res.end(require('fs').readFileSync('loader.js', {
        encoding: 'utf-8'
    }))
}).listen(8080)

console.log('listening 8080...')

Proxy Switchy(Omega) config

  1. Create a proxy profile using the port configured above.
  2. In auto switch profile, add a record. Set the “condition” to resource URI you want to intercept, and the proxy profile to the one you just added.
  3. Voilà

Other Simple Approaches

I thought chorme.webRequest might do the work (change the response body). But after checking the document, the answer is no.

mitmproxy/libmproxy