Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mmadfox/go-crx3

Chrome browser extension tools. Provides a set of tools packing, unpacking, zip, unzip, download, etc.
https://github.com/mmadfox/go-crx3

chrome-extension chrome-extension-download chrome-extension-id crx-pack crx-unpack crx-zip crx3

Last synced: 9 days ago
JSON representation

Chrome browser extension tools. Provides a set of tools packing, unpacking, zip, unzip, download, etc.

Awesome Lists containing this project

README

        

# go-crx3
[![Coverage Status](https://coveralls.io/repos/github/mmadfox/go-crx3/badge.svg?branch=master)](https://coveralls.io/github/mmadfox/go-crx3?branch=master)
[![Documentation](https://godoc.org/github.com/mediabuyerbot/go-crx3?status.svg)](https://pkg.go.dev/github.com/mediabuyerbot/go-crx3)
[![Go Report Card](https://goreportcard.com/badge/github.com/mediabuyerbot/go-crx3)](https://goreportcard.com/report/github.com/mediabuyerbot/go-crx3)
![Actions](https://github.com/mmadfox/go-crx3/actions/workflows/cover.yml/badge.svg)

Provides a sets of tools packing, unpacking, zip, unzip, download, gen id, etc...

## Table of contents
+ [Code examples](/examples/)
+ [Installation](#installation)
+ [Dev commands](#commands)
+ [Examples](#examples)
- [Encode to base64 string](#base64)
- [PublicKey from extension](#retriveres-public-key-from-extension)
- [Pack a zip file or unzipped directory into a crx extension](#pack)
- [Unpack chrome extension into current directory](#unpack)
- [Download a chrome extension from the web store](#download)
- [Add unpacked extension to archive](#zip)
- [Unzip an extension to the directory](#unzip)
- [Keygen](#keygen)
- [Generate extension id](#gen-id)
- [IsDir, IsZip, IsCRX3 helpers](#isdir-iszip-iscrx3)
- [Load or save private key](#newprivatekey-loadprivatekey-saveprivatekey)
+ [License](#license)

### Installation
```ssh
go get -u github.com/mediabuyerbot/go-crx3/crx3
go install github.com/mediabuyerbot/go-crx3/crx3@latest
```

OR download the binary from here
```
https://github.com/mmadfox/go-crx3/releases
```

### Dev commands
```shell script
$ make proto
$ make test/cover
```

### Examples
#### Pack
##### Pack a zip file or unzipped directory into a crx extension
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

if err := crx3.Extension("/path/to/file.zip").Pack(nil); err != nil {
panic(err)
}
```

```go
import crx3 "github.com/mediabuyerbot/go-crx3"

pk, err := crx3.LoadPrivateKey("/path/to/key.pem")
if err != nil {
panic(err)
}
if err := crx3.Extension("/path/to/file.zip").Pack(pk); err != nil {
panic(err)
}
```

```go
import crx3 "github.com/mediabuyerbot/go-crx3"

pk, err := crx3.LoadPrivateKey("/path/to/key.pem")
if err != nil {
panic(err)
}
if err := crx3.Extension("/path/to/file.zip").PackTo("/path/to/ext.crx", pk); err != nil {
panic(err)
}
```
```shell script
$ crx3 pack /path/to/file.zip
$ crx3 pack /path/to/file.zip -p /path/to/key.pem
$ crx3 pack /path/to/file.zip -p /path/to/key.pem -o /path/to/ext.crx
```

#### Unpack
##### Unpack chrome extension into current directory
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

if err := crx3.Extension("/path/to/ext.crx").Unpack(); err != nil {
panic(err)
}
```
```shell script
$ crx3 unpack /path/to/ext.crx
```

#### Base64
##### Encode an extension file to a base64 string
```go
import crx3 "github.com/mediabuyerbot/go-crx3"
import "fmt"

b, err := crx3.Extension("/path/to/ext.crx").Base64()
if err != nil {
panic(err)
}
fmt.Println(string(b))
```
```shell script
$ crx3 base64 /path/to/ext.crx [-o /path/to/file]
```

#### Retriveres public key from extension
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

pubkey, signature, err := crx3.Extension("/path/to/ext.crx").PublicKey()
```
```shell script
$ crx3 pubkey /path/to/ext.crx [-o /path/to/file]
```

#### Download
##### Download a chrome extension from the web store
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

extensionID := "blipmdconlkpinefehnmjammfjpmpbjk"
filepath := "/path/to/ext.crx"
if err := crx3.DownloadFromWebStore(extensionID,filepath); err != nil {
panic(err)
}
```
```shell script
$ crx3 download blipmdconlkpinefehnmjammfjpmpbjk [-o /custom/path]
$ crx3 download https://chrome.google.com/webstore/detail/lighthouse/blipmdconlkpinefehnmjammfjpmpbjk
```

#### Zip
##### Zip add an unpacked extension to the archive
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

if err := crx3.Extension("/path/to/unpacked").Zip(); err != nil {
panic(err)
}
```
```shell script
$ crx3 zip /path/to/unpacked [-o /custom/path]
```

#### Unzip
##### Unzip an extension to the current directory
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

if err := crx3.Extension("/path/to/ext.zip").Unzip(); err != nil {
panic(err)
}
```
```shell script
$ crx3 unzip /path/to/ext.zip [-o /custom/path]
```

#### Gen ID
##### Generate extension id (like dgmchnekcpklnjppdmmjlgpmpohmpmgp)
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

id, err := crx3.Extension("/path/to/ext.crx").ID()
if err != nil {
panic(err)
}
```
```shell script
$ crx3 id /path/to/ext.crx
```

#### IsDir, IsZip, IsCRX3
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

crx3.Extension("/path/to/ext.zip").IsZip()
crx3.Extension("/path/to/ext").IsDir()
crx3.Extension("/path/to/ext.crx").IsCRX3()
```

#### NewPrivateKey, LoadPrivateKey, SavePrivateKey
```go
import crx3 "github.com/mediabuyerbot/go-crx3"

pk, err := crx3.NewPrivateKey()
if err != nil {
panic(err)
}
if err := crx3.SavePrivateKey("/path/to/key.pem", pk); err != nil {
panic(err)
}
pk, err = crx3.LoadPrivateKey("/path/to/key.pem")
```

#### Keygen
```shell script
$ crx3 keygen /path/to/key.pem
```

## License
go-crx3 is released under the Apache 2.0 license. See [LICENSE.txt](https://github.com/mediabuyerbot/go-crx3/blob/master/LICENSE)