Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions browser/all/import.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package all

import (
_ "github.com/browserutils/kooky/browser/brave"
_ "github.com/browserutils/kooky/browser/browsh"
_ "github.com/browserutils/kooky/browser/chrome"
_ "github.com/browserutils/kooky/browser/chromium"
Expand Down
30 changes: 30 additions & 0 deletions browser/brave/brave.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package brave

import (
"context"

"github.com/browserutils/kooky"
"github.com/browserutils/kooky/internal/chrome"
"github.com/browserutils/kooky/internal/cookies"
)

func ReadCookies(ctx context.Context, filename string, filters ...kooky.Filter) ([]*kooky.Cookie, error) {
return cookies.SingleRead(cookieStore, filename, filters...).ReadAllCookies(ctx)
}

func TraverseCookies(filename string, filters ...kooky.Filter) kooky.CookieSeq {
return cookies.SingleRead(cookieStore, filename, filters...)
}

// CookieStore has to be closed with CookieStore.Close() after use.
func CookieStore(filename string, filters ...kooky.Filter) (kooky.CookieStore, error) {
return cookieStore(filename, filters...)
}

func cookieStore(filename string, filters ...kooky.Filter) (*cookies.CookieJar, error) {
s := &chrome.CookieStore{}
s.FileNameStr = filename
s.BrowserStr = `brave`

return cookies.NewCookieJar(s, filters...), nil
}
43 changes: 43 additions & 0 deletions browser/brave/find.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package brave

import (
"github.com/browserutils/kooky"
"github.com/browserutils/kooky/internal/chrome"
"github.com/browserutils/kooky/internal/chrome/find"
"github.com/browserutils/kooky/internal/cookies"
)

type braveFinder struct{}

var _ kooky.CookieStoreFinder = (*braveFinder)(nil)

func init() {
kooky.RegisterFinder(`brave`, &braveFinder{})
}

func (f *braveFinder) FindCookieStores() kooky.CookieStoreSeq {
return func(yield func(kooky.CookieStore, error) bool) {
for file, err := range find.FindBraveCookieStoreFiles() {
if err != nil {
if !yield(nil, err) {
return
}
continue
}
st := &cookies.CookieJar{
CookieStore: &chrome.CookieStore{
DefaultCookieStore: cookies.DefaultCookieStore{
BrowserStr: file.Browser,
ProfileStr: file.Profile,
OSStr: file.OS,
IsDefaultProfileBool: file.IsDefaultProfile,
FileNameStr: file.Path,
},
},
}
if !yield(st, nil) {
return
}
}
}
}
4 changes: 4 additions & 0 deletions internal/chrome/find/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func FindChromiumCookieStoreFiles() iter.Seq2[*chromeCookieStoreFile, error] {
return FindCookieStoreFiles(chromiumRoots, `chromium`)
}

func FindBraveCookieStoreFiles() iter.Seq2[*chromeCookieStoreFile, error] {
return FindCookieStoreFiles(braveRoots, `brave`)
}

func FindCookieStoreFiles(rootsFunc iter.Seq2[string, error], browserName string) iter.Seq2[*chromeCookieStoreFile, error] {
return func(yield func(*chromeCookieStoreFile, error) bool) {
if rootsFunc == nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/chrome/find/find_android.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ func chromeRoots(yield func(string, error) bool) {
}

func chromiumRoots(yield func(string, error) bool) { _ = yield(``, errNotImplemented) }

func braveRoots(yield func(string, error) bool) { _ = yield(``, errNotImplemented) }
12 changes: 12 additions & 0 deletions internal/chrome/find/find_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ func chromiumRoots(yield func(string, error) bool) {
return
}
}

func braveRoots(yield func(string, error) bool) {
// "$HOME/Library/Application Support"
cfgDir, err := os.UserConfigDir()
if err != nil {
_ = yield(``, err)
return
}
if !yield(filepath.Join(cfgDir, `BraveSoftware`, `Brave-Browser`), nil) {
return
}
}
2 changes: 2 additions & 0 deletions internal/chrome/find/find_others.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ var errNotImplemented = errors.New(`not implemented`)
func chromeRoots(yield func(string, error) bool) { _ = yield(``, errNotImplemented) }

func chromiumRoots(yield func(string, error) bool) { _ = yield(``, errNotImplemented) }

func braveRoots(yield func(string, error) bool) { _ = yield(``, errNotImplemented) }
4 changes: 4 additions & 0 deletions internal/chrome/find/find_otherunix.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ func windowsChromeRoots(_ string) func(yield func(string, error) bool) {
func windowsChromiumRoots(_ string) func(yield func(string, error) bool) {
return func(yield func(string, error) bool) {}
}

func windowsBraveRoots(_ string) func(yield func(string, error) bool) {
return func(yield func(string, error) bool) {}
}
36 changes: 36 additions & 0 deletions internal/chrome/find/find_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,39 @@ func chromiumRoots(yield func(string, error) bool) {
}
}
}

func braveRoots(yield func(string, error) bool) {
// "${XDG_CONFIG_HOME:-$HOME/.config}"
var dotConfigs []string
// fallback
if home, err := os.UserHomeDir(); err != nil {
if !yield(``, err) {
return
}
} else {
dotConfigs = append(dotConfigs, filepath.Join(home, `.config`))
}
if dir, ok := os.LookupEnv(`XDG_CONFIG_HOME`); ok {
dotConfigs = append(dotConfigs, dir)
}
for _, dotConfig := range dotConfigs {
for _, p := range []string{
filepath.Join(dotConfig, `BraveSoftware`, `Brave-Browser`),
filepath.Join(dotConfig, `brave-browser`),
} {
if !yield(p, nil) {
return
}
}
}
// on WSL Linux add Windows paths
appDataRoot, err := wsl.WSLAppDataRoot()
if err != nil && (errors.Is(err, wsl.ErrNotWSL) || !yield(``, err)) {
return
}
for r, err := range windowsBraveRoots(filepath.Join(appDataRoot, `Local`)) {
if !yield(r, err) {
return
}
}
}
1 change: 1 addition & 0 deletions internal/chrome/find/find_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ import (
var (
chromeRoots = windowsChromeRoots(os.Getenv(`LocalAppData`))
chromiumRoots = windowsChromiumRoots(os.Getenv(`LocalAppData`))
braveRoots = windowsBraveRoots(os.Getenv(`LocalAppData`))
)
12 changes: 12 additions & 0 deletions internal/chrome/find/find_wsl.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ func windowsChromiumRoots(dir string) func(yield func(string, error) bool) {
}
}
}

func windowsBraveRoots(dir string) func(yield func(string, error) bool) {
return func(yield func(string, error) bool) {
if len(dir) == 0 {
_ = yield(``, errors.New(`%LocalAppData% is empty`))
return
}
if !yield(filepath.Join(dir, `BraveSoftware`, `Brave-Browser`, `User Data`), nil) {
return
}
}
}