pydoll icon indicating copy to clipboard operation
pydoll copied to clipboard

[Refactor]: Improve type safety for browser preferences

Open thalissonvs opened this issue 2 months ago • 5 comments

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:
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

thalissonvs avatar Oct 27 '25 04:10 thalissonvs

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.

ArthurRodrigues4433 avatar Nov 01 '25 13:11 ArthurRodrigues4433

Hello, please feel free to test. If you need something, just let me know

thalissonvs avatar Nov 01 '25 16:11 thalissonvs

Friend, can we communicate in Portuguese? I'm not very good at English yet.

ArthurRodrigues4433 avatar Nov 01 '25 17:11 ArthurRodrigues4433

Consegui subir a PR só falta revisão e um Feedback!

ArthurRodrigues4433 avatar Nov 04 '25 11:11 ArthurRodrigues4433

Vou dar uma olhada assim que puder, obrigado

thalissonvs avatar Nov 04 '25 14:11 thalissonvs