npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chrome-cache-reader

v1.0.1

Published

Read cached files stored by chrome or chromium

Downloads

7

Readme

chrome-cache-reader

Read cached files stored by chrome or chromium

This module will allow you to retrieve cached files by their url. For example, when you navigate to google.com, the google logo is downloaded and cached so that it is rendered.

You can right click on the image and copy the image address and use that as the argument for ChromeCacheReader::get() to get a ChromeCacheFile instance that holds the cached file's filename, url, content & http response headers.

ChromeCacheFile::content is a buffer of the file that was cached, however you will have to read the ChromeCacheFile::headers object, in order to determine the file's content-type or mimetype, & content-encoding in case it was compressed.

For the example above, the url is https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png & a snippet of how to extract the image is:

const reader = new ChromeCacheReader()
reader.update()
.then(() => {
  const url = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
  reader.get(url)
  .then((r) => {
    console.log('\nfilename:', r.filename)
    console.log('\nurl:', r.url)
    console.log('\ncontent:', r.content)
    console.log('\nheaders:', r.headers)
    console.log('\n')
  })
  .catch(error => console.log(error))
})
.catch(error => console.log(error))

Which returns the following: (assuming you are using Linux & Chromium)

Example output

see example.js


Install

npm i chrome-cache-reader --save

Usage

NOTE You may have to specify the cachePath option, this is the location where cached files are stored. By default: ~/.cache/chromium/Default/Cache is used for linux and ~\AppData\Local\Google\Chrome\User Data\Default\Cache is used for windows.

const os = require('os')
const ChromeCacheReader = require('chrome-cache-reader')

const options = {
  cachePath: `${ os.homedir() }/.cache/google-chrome/Default/Cache`,
}

const reader = new ChromeCacheReader(options)

reader.update()
.then(() => {
  const url = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'

  reader.get(url)
  .then(chromeCacheFile => {
    console.log('\nfilename:', chromeCacheFile.filename)
    console.log('\nurl:', chromeCacheFile.url)
    console.log('\ncontent:', chromeCacheFile.content)
    console.log('\nheaders:', chromeCacheFile.headers)
    console.log('\n')
  })
  .catch(error => console.log(error))

})
.catch(error => console.log(error))

Options

DEFAULT OPTIONS

const DEFAULT_OPTIONS = {
  databasePath: './database',
  cachePath: null,
}

cachePath is ~/.cache/chromium/Default/Cache on linux, ~\AppData\Local\Google\Chrome\User Data\Default\Cache on windows, otherwise it is set to null. Location varies by browser version and platform so you may have to set this value manually. Works for both chrome & chromium.

databasePath: This module creates a lookup database using leveldb in order to quickly find a cached file by their url. databasePath determines where this database will be stored.

databasePath and cachePath are required, and must be valid values

API

class ChromeCacheReader

The chrome cache reader; what you will use to fetch cached files.

void ChromeCacheReader::constructor(Object options)

Promise ChromeCacheReader::get(String url)

Returns a ChromeCacheFile instance if the cached file is found, null if it does not exist or an Error if something goes wrong.

Promise ChromeCacheReader::update()

Updates lookup database so as to have all cached files ready for retrieval by their original url. You will only have to call this method when you are certain the cache has been updated (i.e Browsing the web).

class ChromeCacheFile

A parsed cache file

void ChromeCacheFile::constructor(Buffer rawFile)

String ChromeCacheFile::filename

Read-only. The name of the cached file found in cachePath.

String ChromeCacheFile::url

Read-only. The original url of the file that was cached.

Buffer ChromeCacheFile::content

Read-only. The contents of the file that was cached. Keep in mind that it may be compressed (i.e with gzip), so you may have to use the value in content-encoding in the object found in ChromeCacheFile::headers.

Object ChromeCacheFile::headers

Read-only. An Oject containing the headers from the HTTP response that returned the file that was cached. Headers will vary however, the most relevant are content-type & content-encoding in case the file was compressed when it was cached.

NOTE Some requests do not return content or HTTP response headers, in those cases the only values that will be set are filename & url, everything else will be set to null

License

MIT