geckordp.profile module

class geckordp.profile.FirefoxProfile(name: str, is_relative: bool, path: Path | str)

Bases: object

An instance which represents the firefox profile.

Warning

Before making changes to a profile, it is recommend to clone the profile at first or creating a new one.

get_config(name)

Get a configuration value by its name.

Parameters:

name ([type]) – The name to retrieve the value from.

Raises:

JSONDecodeError – If value can not be deserialized.

Returns:

not None: The value of the setting, None: Setting not found

Return type:

[type]

list_config() Dict[str, str]

Lists all configurations of the profile.

Returns:

A dict with setting pairs.

Return type:

Dict[str, str]

remove_config(name: str) bool

Removes a setting by its name.

Parameters:

name (str) – The name of the setting to remove.

Returns:

True: if setting found and removed, False: not found

Return type:

bool

set_config(name: str, value)

Sets or updates a configuration value by its name.

Parameters:
  • name (str) – The name of setting.

  • value ([type]) – The value of the setting.

set_required_configs()

Sets all required settings to be able to use geckordp.

class geckordp.profile.ProfileManager(override_firefox_path='', override_profiles_path='')

Bases: object

A manager for firefox profiles. The manager allows to clone, add or remove firefox profiles. Each profile its configuration can be modified with ‘FirefoxProfile’.

Warning

Before making changes to a profile, it is recommend to clone the profile at first or creating a new one.

clone(source_name: str, dest_name: str, ignore_invalid_files=False) FirefoxProfile | None

Clones an existing firefox profile with the specified name.

Parameters:
  • source_name (str) – The name of the profile to clone from.

  • dest_name (str) – The name of the new profile.

Raises:
  • ValueError – If ‘source_name’ and ‘dest_name’ are equal.

  • ValueError – If ‘source_name’ is empty.

  • ValueError – If ‘dest_name’ is empty.

Returns:

not None: instance of firefox profile, None: source doesn’t exists or destination already exists

Return type:

FirefoxProfile | None

create(profile_name: str) FirefoxProfile | None

Creates and initializes a firefox profile with the specified name.

Parameters:

profile_name (str) – The name for the new profile.

Raises:

RuntimeError – If initialization of profile failed.

Returns:

not None: instance of firefox profile, None: profile already exists

Return type:

FirefoxProfile | None

exists(profile_name: str) bool

Check whether a profile exists.

Parameters:

profile_name (str) – The profile name to check.

Raises:

ValueError – If ‘profile_name’ is empty.

Returns:

True: profile exists, False: profile doesn’t exists

Return type:

bool

get_profile_by_name(profile_name: str) FirefoxProfile | None

Get a profile by its name.

Parameters:

profile_name (str) – The name of the profile to retrieve.

Raises:

ValueError – If ‘profile_name’ is empty

Returns:

not None: instance of firefox profile, None: not found

Return type:

FirefoxProfile | None

get_profile_path(profile_name: str) Path | None

Get the profile path by its name.

Parameters:

profile_name (str) – The name of the profile.

Returns:

The profile path.

Return type:

Path | None

list_profiles() List[FirefoxProfile]

List all profiles available by firefox.

Raises:

Returns:

List of firefox profiles.

Return type:

List[FirefoxProfile]

remove(profile_name: str) bool

Removes a firefox profile by its name.

Parameters:

profile_name (str) – The name of the profile to be removed.

Raises:
  • ValueError – If ‘profile_name’ is empty.

  • ValueError – If ‘profile_name’ is ‘default-release’.

Returns:

True: profile found and removed, False: profile not found

Return type:

bool