#289·pydoll

[Refactor]: Improve type safety for browser preferences

Author: thalissonvsCreated Oct 27, 2025Updated Nov 4, 2025
Labelsenhancement

Currently, browser_preferences in ChromiumOptions is a generic dict without type safety, making it error-prone and difficult to maintain.

Problems:

No type validation: _browser_preferences: dict accepts any structure Unsafe path access: _set_pref_path(path: list, value) - no type checking on paths or values Silent failures: _get_pref_path() returns None without proper Optional typing Generic exception: WrongPrefsDict doesn't indicate what's wrong No autocomplete: IDE can't suggest available preference keys

Proposed Solution:

  1. Create TypedDict for preferences structure:
python
from typing import TypedDict, NotRequired

class DownloadPreferences(TypedDict, total=False):
    default_directory: str
    prompt_for_download: bool

class ProfilePreferences(TypedDict, total=False):
    password_manager_enabled: bool
    default_content_setting_values: NotRequired[dict[str, int]]

class BrowserPreferences(TypedDict, total=False):
    download: DownloadPreferences
    profile: ProfilePreferences
    intl: NotRequired[dict[str, str]]
    plugins: NotRequired[dict[str, bool]]
    credentials_enable_service: bool
  1. Update method signatures
  2. Add specific exceptions
  3. Add preference path validation