mozilla

package
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 9, 2025 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package mozilla provides functionality for managing Mozilla-based browser profiles, such as Firefox and LibreWolf. It reads and parses the `profiles.ini` configuration file used by these applications to store profile information, and provides tools to retrieve and manage browser profiles for different flavors (e.g., Firefox, LibreWolf).

TODO: auto detect vfs lock then switch or not to watch&copy places

Index

Constants

View Source
const (
	RootID    // 1
	MenuID    // 2 Main bookmarks menu
	ToolbarID // 3 Bk tookbar that can be toggled under URL zone
	TagsID    // 4 Hidden menu used for tags, stored as a flat one level menu
	OtherID   // 5 Most bookmarks are automatically stored here
	MobileID  // 6 Mobile bookmarks stored here by default
)

Constants representing the meaning if IDs defined in the table moz_bookmarks.id

View Source
const (
	// Name of the root node
	RootName = `ROOT`

	// Name of the `Tags` node parent to all tag nodes
	TagsBranchName = `TAGS`
)

Names of the root node in the mozilla bookmark tree. See RootFolderNames.

View Source
const (

	//TODO!: create file if it does not exist
	PrefsFile = "user.js"

	// Parses vales in prefs.js under the form:
	// user_pref("my.pref.option", value);
	REFirefoxPrefs = `user_pref\("(?P<option>%s)",\s+"*(?P<value>.*[^"])"*\)\s*;\s*(\n|$)`
)
View Source
const (
	MozBookmarkQueryFile        = "recursive_all_bookmarks.sql"
	MozBookmarkQuery            = "recursive-all-bookmarks"
	MozChangedBookmarkQueryFile = "recursive_modified_bookmarks.sql"
	MozChangedBookmarkQuery     = "recursive-modified-bookmarks"
)
View Source
const (
	PlacesFile = "places.sqlite"
)
View Source
const (
	// This option disables the VFS lock on firefox
	// Sqlite allows file locking of the database using the local file system VFS.
	// Previous versions of FF allowed external processes to access the file.
	//
	// Since firefox v(63) this has changed. When initializing the database FF checks
	// the preference option `storage.multiProcessAccess.enabled` which is not
	// documented officially.
	//
	// Source code:
	//- https://dxr.mozilla.org/mozilla-central/source/storage/TelemetryVFS.cpp#884
	//- https://dxr.mozilla.org/mozilla-central/source/storage/mozStorageService.cpp#377
	//- Change on github: https://github.com/mozilla/gecko-dev/commit/a543f35d4be483b19446304f52e4781d7a4a0a2f
	PrefMultiProcessAccess = "storage.multiProcessAccess.enabled"
)
View Source
const (
	ProfilesFile = "profiles.ini"
)
View Source
const (
	QFolders = `` /* 131-byte string literal not displayed */

)

sql queries

Variables

View Source
var (
	ErrPrefNotFound = errors.New("pref not defined")
	ErrPrefNotBool  = errors.New("pref is not bool")
)
View Source
var (
	ReIniProfiles = regexp.MustCompile(`(?i)profile`)

	ErrProfilesIni      = errors.New("could not parse profiles.ini file")
	ErrNoDefaultProfile = errors.New("no default profile found")
)
View Source
var CopyJobs []PlaceCopyJob
View Source
var (
	//go:embed "recursive_all_bookmarks.sql"
	//go:embed "recursive_modified_bookmarks.sql"
	EmbeddedSQLQueries embed.FS
)
View Source
var (
	ErrMultiProcessAlreadyEnabled = errors.New("multiProcessAccess already enabled")
)
View Source
var RootFolderNames = map[Sqlid]string{
	RootID:    RootName,
	TagsID:    TagsBranchName,
	MenuID:    "menu",
	ToolbarID: "toolbar",
	OtherID:   "other",
	MobileID:  "mobile",
}

Some root folders names in the tree

View Source
var RootFolderTitles = map[Sqlid]string{
	MenuID:    "Bookmarks Menu",
	ToolbarID: "Bookmarks Toolbar",
	OtherID:   "Other Bookmarks",
	MobileID:  "Mobile Bookmarks",
}

Represnets the root folder names as shown on Firefox

Functions

func CheckVFSLock

func CheckVFSLock(bkDir string) error

TODO!:

func FindPref

func FindPref(path string, name string) (string, error)

Finds and returns a prefernce definition. Returns empty string ("") if no pref found

func GetPrefBool

func GetPrefBool(path string, name string) (bool, error)

func HasPref

func HasPref(path string, name string) (bool, error)

Returns true if the `name` preference is found in `prefs.js`

func SetPrefBool

func SetPrefBool(path string, name string, val bool) error

Set a preference in the preference file under `path`

func UnlockPlaces

func UnlockPlaces(bkDir string) error

Types

type BrowserDef

type BrowserDef = browsers.BrowserDef

type MergedPlaceBookmark

type MergedPlaceBookmark struct {
	PlID    Sqlid  `db:"plId"`
	PlURL   string `db:"plUrl"`
	PlDesc  string `db:"plDescription"`
	BkID    Sqlid  `db:"bkId"`
	BkTitle string `db:"bkTitle"`

	//firefox stores timestamps in milliseconds as integer
	//sqlite3 strftime('%s', ...) returns seconds
	//This field stores the timestamp as raw milliseconds
	BkLastModified Sqlid `db:"bkLastModified"`

	IsFolder bool  `db:"isFolder"`
	IsTag    bool  `db:"isTag"`
	IsBk     bool  `db:"isBk"`
	BkParent Sqlid `db:"bkParent"`
}

Type is used for scanning from `merged-places-bookmarks.sql` plId plUrl plDescription bkId bkTitle bkLastModified isFolder isTag isBk bkParent

func (*MergedPlaceBookmark) Datetime

func (pb *MergedPlaceBookmark) Datetime() time.Time

type MozBookmark

type MozBookmark struct {
	PlID           Sqlid `db:"plId"`
	Title          string
	Tags           string
	Folders        string
	ParentID       Sqlid  `db:"parentFolderId"`
	ParentFolder   string `db:"parentFolder"`
	URL            string
	PlDesc         string `db:"plDesc"`
	BkLastModified Sqlid  `db:"lastModified"`
}

Columns of the table moz_bookmarks in this order:

placeId  title  parentFolderId  folders url plDesc lastModified

This is the typed used when scanning from the query located in `recursive-all-bookmarks.sql`

type MozFolder

type MozFolder struct {
	ID     Sqlid
	Parent Sqlid
	Title  string
}

type MozProfileManager

type MozProfileManager struct {
	PathResolver profiles.PathResolver
}

func NewMozProfileManager

func NewMozProfileManager(resolver profiles.PathResolver) *MozProfileManager

func (*MozProfileManager) GetProfileByName

func (pm *MozProfileManager) GetProfileByName(flavour string, name string) (*profiles.Profile, error)

func (*MozProfileManager) GetProfiles

func (pm *MozProfileManager) GetProfiles(flavour string) ([]*profiles.Profile, error)

func (*MozProfileManager) ListFlavours

func (pm *MozProfileManager) ListFlavours() []BrowserDef

type PlaceCopyJob

type PlaceCopyJob struct {
	ID string
}

func NewPlaceCopyJob

func NewPlaceCopyJob() PlaceCopyJob

func (PlaceCopyJob) Clean

func (pc PlaceCopyJob) Clean() error

func (PlaceCopyJob) Path

func (pc PlaceCopyJob) Path() string

type Sqlid

type Sqlid int64

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL