Otaqui.com Blog

Scan the Google Chrome Cache for a string using NodeJS

I wanted to hunt in my browser cache for a particular string (well, regular expression in fact), and pull out matching contents. There didn’t seem to be an immediately obvious way of doing this with chrome://cache, so I wrote a little nodejs script.

Since I knew the only files I was interested in would be gzipped, I ran that and ignored any contents that returned an error.

You’ll need the path to the cache folder – it’ll vary if you aren’t using OS X as I was.

var fs = require('fs');
var zlib = require('zlib');
// here's the REGEX you want to search for:
var regex = /otaqui/i;
// here's the PATH to your Google Chrome cache directory.
var dir = '/Users/USERNAME/Library/Caches/Google/Chrome/Default/Cache/';
fs.readdirSync(dir).forEach(function(f) {
    'use strict';
    var path = dir + f;
    var rawContents = fs.readFileSync(path);
    zlib.gunzip(rawContents, function(err, result) {
        if ( !err ) {
            var contents = result.toString();
            var match = contents.match(regex);
            if ( match ) {
                console.log('found in', f);