profile

package
v0.0.0-...-98965d2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package profile reads and mutates Chromium profile data files.

Index

Constants

View Source
const (
	PreferencesFilename = "Preferences"
	LocalStateFilename  = "Local State"
	VariationsFilename  = "Variations"
)

Variables

This section is empty.

Functions

func ApplyLocalState

func ApplyLocalState(profileDir string, patches []Patch) error

func ApplyPreferences

func ApplyPreferences(profileDir string, patches []Patch) error

func ApplyVariations

func ApplyVariations(profileDir string, patches []Patch) error

func EnsureAcceleratorAdded

func EnsureAcceleratorAdded(customAccelerators map[string]any, commandID, accelerator string)

func NestedObject

func NestedObject(root map[string]any, dottedPath string) (map[string]any, error)

func PatchValues

func PatchValues(root map[string]any, values []Value, description string) error

func ReadLocalState

func ReadLocalState(profileDir string) (map[string]any, error)

func ReadPreferences

func ReadPreferences(profileDir string) (map[string]any, error)

func ReadVariations

func ReadVariations(profileDir string) (map[string]any, error)

func SetCookieAllowlist

func SetCookieAllowlist(preferences map[string]any, patterns []string) error

func SetCookiePolicy

func SetCookiePolicy(preferences map[string]any, policy CookiePolicy) error

SetCookiePolicy updates Chromium's default cookie setting, third-party cookie mode, and per-pattern exceptions. A nil exception list is unmanaged. A non-nil list owns exceptions with that setting, including when the list is empty and therefore removes existing exceptions of that setting.

func SetNestedValue

func SetNestedValue(root map[string]any, dottedPath string, value any) error

func WriteLocalState

func WriteLocalState(profileDir string, localState map[string]any) error

func WritePreferences

func WritePreferences(profileDir string, preferences map[string]any) error

func WriteVariations

func WriteVariations(profileDir string, variations map[string]any) error

Types

type Accelerator

type Accelerator struct {
	Path        string `toml:"path"`
	CommandID   string `toml:"command_id"`
	Accelerator string `toml:"accelerator"`
}

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder collects typed preference values and optionally resolves symbolic names to their stored Chromium paths.

func NewBuilder

func NewBuilder(resolve func(string) string, capacity int) Builder

func (*Builder) Add

func (builder *Builder) Add[T any](name string, value T, configured bool)

Add resolves a symbolic preference name and adds a value of any concrete type. Generic methods require Go 1.27.

func (*Builder) AddOptional

func (builder *Builder) AddOptional[T any](name string, value *T)

AddOptional is the pointer-valued counterpart to Add.

func (*Builder) AddPath

func (builder *Builder) AddPath[T any](path string, value T)

AddPath adds a value for an already-resolved declarative preference path.

func (*Builder) Append

func (builder *Builder) Append(values ...Value)

func (*Builder) Values

func (builder *Builder) Values() []Value

type CookiePolicy

type CookiePolicy struct {
	Default     CookieSetting          `toml:"default"`
	ThirdParty  ThirdPartyCookiePolicy `toml:"third_party"`
	Allow       []string               `toml:"allow"`
	Block       []string               `toml:"block"`
	SessionOnly []string               `toml:"session_only"`
}

func (CookiePolicy) HasPolicy

func (config CookiePolicy) HasPolicy() bool

func (CookiePolicy) Validate

func (config CookiePolicy) Validate() error

type CookieSetting

type CookieSetting string
const (
	CookieSettingAllow       CookieSetting = "allow"
	CookieSettingBlock       CookieSetting = "block"
	CookieSettingSessionOnly CookieSetting = "session_only"
)

type Defaults

type Defaults struct {
	Values           []Value       `toml:"values"`
	LocalStateValues []Value       `toml:"local_state_values"`
	VariationValues  []Value       `toml:"variation_values"`
	Accelerators     []Accelerator `toml:"accelerators"`
	Cookies          CookiePolicy  `toml:"cookies"`
}

func (Defaults) HasPreferences

func (config Defaults) HasPreferences() bool

func (Defaults) PatchLocalState

func (config Defaults) PatchLocalState(localState map[string]any) error

func (Defaults) PatchPreferences

func (config Defaults) PatchPreferences(preferences map[string]any) error

func (Defaults) PatchVariations

func (config Defaults) PatchVariations(variations map[string]any) error

type Patch

type Patch func(map[string]any) error

Patch updates one decoded Chromium profile data document.

type ThirdPartyCookiePolicy

type ThirdPartyCookiePolicy string
const (
	ThirdPartyCookiePolicyOff           ThirdPartyCookiePolicy = "off"
	ThirdPartyCookiePolicyBlock         ThirdPartyCookiePolicy = "block"
	ThirdPartyCookiePolicyIncognitoOnly ThirdPartyCookiePolicy = "incognito_only"
)

Chromium 157 treats off and incognito_only alike in incognito profiles Retain both stored enum values for compatibility with other browser builds

type Value

type Value struct {
	Path  string `toml:"path"`
	Value any    `toml:"value"`
}

Jump to

Keyboard shortcuts

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