crx-util

1.0.0 • Public • Published

crx-util

Download (and extract) Chrome/Edge extension (.crx).

Install

npm install crx-util

Usage

const crx = require("crx-util");

// Download a CRX file from microsoft webstore
crx.downloadByURL(`https://microsoftedge.microsoft.com/addons/detail/${extensionName}/${extensionId}`, "./xxx.crx")
  .then((res) => {
    if (res.result) {
      console.info("succeed!");
    } else {
      console.warn("Failed:", res.error);
    }
    // Other info
    const { extensionId, source, downloadURL, output } = res;
  });

// Download by extension id and source
crx.downloadById(`${extensionId}`, "edge", "./xxx.crx");

// Download and extract
crx.downloadById(`${extensionId}`, "edge", "./xxx");

// Download from google webstore
crx.downloadByURL(`https://chrome.google.com/webstore/detail/${extensionName}/${extensionId}`, "./xxx.crx");

// Or by extension id and source
crx.downloadById(`${extensionId}`, "chrome", "./xxx.crx");

// Extract a local CRX file
crx.parser.extract("./xxx.crx", "./xxx");

CLI

Usage

# Download by webstore url
crx-util -u=url [-o=output]

# Download by extension id and source
crx-util -i=extensionId -s=source [-o=output]

# Extract a local CRX file
Usage: crx-util -e=crxPath [-o=output]

Example:

# Download a CRX file from microsoft webstore
crx-util -u="https://microsoftedge.microsoft.com/addons/detail/$name/$id" -o="./xxx.crx"

# Download and extract
crx-util -i="$id" -s="edge" -o="./xxx"

# Extract a local CRX file
crx-util -e="./xxx.crx" -o="./xxx"

Arguments

  • -u, --url - Chrome/Edge extension url
  • -i, --id - Extension id
  • -s, --source - Extension source, "chrome" or "edge"
  • -e, --extract - Extract a local CRX file
  • -o, --output - Output, if it ends with .crx, it will be saved as a CRX file, otherwise it will be extracted to ${output}/${extensionId}. Default by process.cwd().
  • -h, --help - Display help for command

API

crx.downloadByURL(url, output?): Promise

Download a CRX file from webstore.

  • url string - Chrome/Edge extension url
  • output string (optional) - If output ends with ".crx", it will be saved as a CRX file, otherwise it will be extracted to ${output}/${extensionId}. Default by process.cwd().

Resolves with an object contains the following info:

  • result Boolean
  • error any
  • extensionId String
  • source "chrome" | "edge"
  • downloadURL String
  • output String

crx.downloadById(extensionId, source, output?): Promise

Download a CRX file by extension id and source.

  • extensionId string - Extension id
  • source "chrome" | "edge" - Extension source
  • output string (optional) - If output ends with ".crx", it will be saved as a CRX file, otherwise it will be extracted to ${output}/${extensionId}. Default by process.cwd().

Resolves with an object.

crx.downloader

crx.downloader.URL_PATTERN

Download url pattern.

  • chrome string
  • edge string

crx.downloader.parseURL(url): Object

Parse Chrome/Edge extension url.

  • url string - Chrome/Edge extension url.

Returns an object contains extensionId and source ("chrome" or "edge") info.

crx.downloader.getDownloadURL(extensionId, source): String

Get download url by extensionId and source.

  • extensionId string - Extension id
  • source "chrome" | "edge" - Extension source

Returns the download url.

crx.downloader.downloadByURL(url): Promise

Download a CRX file by url.

  • url string - Chrome/Edge extension url.

Resolves with CRX buffer.

crx.downloader.downloadById(extensionId, source): Promise

Download a CRX file by extension id and source.

  • extensionId string - Extension id
  • source "chrome" | "edge" - Extension source

Resolves with CRX buffer.

crx.parser

crx.parser.isCrx(crxPathOrBuffer): Boolean

Checks whether the given path or Buffer contains a valid CRX file.

  • crxPathOrBuffer string | Buffer - CRX file path or buffer.

crx.parser.getCrxVersion(crxPathOrBuffer): Number

Get CRX version.

  • crxPathOrBuffer string | Buffer - CRX file path or buffer.

crx.parser.getZipContents(crxPathOrBuffer): Buffer

Convert a CRX Buffer to a Zip Buffer.

  • crxPathOrBuffer string | Buffer - CRX file path or buffer.

crx.parser.extract(crxPathOrBuffer, output?)

Extract a local CRX file.

  • crxPathOrBuffer string | Buffer - CRX file path or buffer.
  • output string (optional) - It will be extracted to ${output}/${crxFileName}. Default by process.cwd().

Package Sidebar

Install

npm i crx-util

Weekly Downloads

80

Version

1.0.0

License

MIT

Unpacked Size

14.8 kB

Total Files

7

Last publish

Collaborators

  • ssnangua