1.0.0 • Published 2 years ago
crx-util v1.0.0
crx-util
Download (and extract) Chrome/Edge extension (.crx).
Install
npm install crx-utilUsage
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 byprocess.cwd().-h,--help- Display help for command
API
crx.downloadByURL(url, output?): Promise
Download a CRX file from webstore.
urlstring - Chrome/Edge extension urloutputstring (optional) - Ifoutputends with ".crx", it will be saved as a CRX file, otherwise it will be extracted to${output}/${extensionId}. Default byprocess.cwd().
Resolves with an object contains the following info:
resultBooleanerroranyextensionIdStringsource"chrome" | "edge"downloadURLStringoutputString
crx.downloadById(extensionId, source, output?): Promise
Download a CRX file by extension id and source.
extensionIdstring - Extension idsource"chrome" | "edge" - Extension sourceoutputstring (optional) - Ifoutputends with ".crx", it will be saved as a CRX file, otherwise it will be extracted to${output}/${extensionId}. Default byprocess.cwd().
Resolves with an object.
crx.downloader
crx.downloader.URL_PATTERN
Download url pattern.
chromestringedgestring
crx.downloader.parseURL(url): Object
Parse Chrome/Edge extension url.
urlstring - 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.
extensionIdstring - Extension idsource"chrome" | "edge" - Extension source
Returns the download url.
crx.downloader.downloadByURL(url): Promise
Download a CRX file by url.
urlstring - Chrome/Edge extension url.
Resolves with CRX buffer.
crx.downloader.downloadById(extensionId, source): Promise
Download a CRX file by extension id and source.
extensionIdstring - Extension idsource"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.
crxPathOrBufferstring | Buffer - CRX file path or buffer.
crx.parser.getCrxVersion(crxPathOrBuffer): Number
Get CRX version.
crxPathOrBufferstring | Buffer - CRX file path or buffer.
crx.parser.getZipContents(crxPathOrBuffer): Buffer
Convert a CRX Buffer to a Zip Buffer.
crxPathOrBufferstring | Buffer - CRX file path or buffer.
crx.parser.extract(crxPathOrBuffer, output?)
Extract a local CRX file.
crxPathOrBufferstring | Buffer - CRX file path or buffer.outputstring (optional) - It will be extracted to${output}/${crxFileName}. Default byprocess.cwd().