[Refactor]: Improve type safety for browser preferences
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:
- Create TypedDict for preferences structure:
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
- Update method signatures
- Add specific exceptions
- Add preference path validation
Hi! I’m interested in helping to solve this issue. I’m still learning, but I would like to try implementing type-safe browser preferences using TypedDict. I’m open to guidance and feedback while working on it.
Hello, please feel free to test. If you need something, just let me know
Friend, can we communicate in Portuguese? I'm not very good at English yet.
Consegui subir a PR só falta revisão e um Feedback!
Vou dar uma olhada assim que puder, obrigado