go-crx3
go-crx3 copied to clipboard
Chrome browser extension tools. Provides a set of tools packing, unpacking, zip, unzip, download, etc.
go-crx3
Provides a sets of tools packing, unpacking, zip, unzip, download, gen id, etc...
Table of contents
- Installation
- Dev commands
-
Examples
- Encode to base64 string
- Pack a zip file or unzipped directory into a crx extension
- Unpack chrome extension into current directory
- Download a chrome extension from the web store
- Add unpacked extension to archive
- Unzip an extension to the directory
- Keygen
- Generate extension id
- IsDir, IsZip, IsCRX3 helpers
- Load or save private key
- License
Installation
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
$ make proto
$ make test/cover
Examples
Pack
Pack a zip file or unzipped directory into a crx extension
import crx3 "github.com/mediabuyerbot/go-crx3"
if err := crx3.Extension("/path/to/file.zip").Pack(nil); err != nil {
panic(err)
}
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)
}
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)
}
$ 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
import crx3 "github.com/mediabuyerbot/go-crx3"
if err := crx3.Extension("/path/to/ext.crx").Unpack(); err != nil {
panic(err)
}
$ crx3 unpack /path/to/ext.crx
Base64
Encode an extension file to a base64 string
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))
$ crx3 base64 /path/to/ext.crx [-o /path/to/file]
Download
Download a chrome extension from the web store
import crx3 "github.com/mediabuyerbot/go-crx3"
extensionID := "blipmdconlkpinefehnmjammfjpmpbjk"
filepath := "/path/to/ext.crx"
if err := crx3.DownloadFromWebStore(extensionID,filepath); err != nil {
panic(err)
}
$ 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
import crx3 "github.com/mediabuyerbot/go-crx3"
if err := crx3.Extension("/path/to/unpacked").Zip(); err != nil {
panic(err)
}
$ crx3 zip /path/to/unpacked [-o /custom/path]
Unzip
Unzip an extension to the current directory
import crx3 "github.com/mediabuyerbot/go-crx3"
if err := crx3.Extension("/path/to/ext.zip").Unzip(); err != nil {
panic(err)
}
$ crx3 unzip /path/to/ext.zip [-o /custom/path]
Gen ID
Generate extension id (like dgmchnekcpklnjppdmmjlgpmpohmpmgp)
import crx3 "github.com/mediabuyerbot/go-crx3"
id, err := crx3.Extension("/path/to/ext.crx").ID()
if err != nil {
panic(err)
}
$ crx3 id /path/to/ext.crx
IsDir, IsZip, IsCRX3
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
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
$ crx3 keygen /path/to/key.pem
License
go-crx3 is released under the Apache 2.0 license. See LICENSE.txt