pydoll icon indicating copy to clipboard operation
pydoll copied to clipboard

Feature/edge browser implementation

Open Harris-H opened this issue 8 months ago • 6 comments

Description

Add Microsoft Edge browser automation support to pydoll library.

Changes

  • Add Edge browser class with Edge-specific configurations
  • Add test suite for Edge browser functionality
  • Update browser initialization to expose Edge support

Testing

All tests passing, including Edge-specific test cases.

This PR addresses issue #41 by adding support for Microsoft Edge browser.

Harris-H avatar Mar 12 '25 11:03 Harris-H

Hi @Harris-H,

First of all, thanks for your contribution! This feature is amazing.

I just left some comments to maintain the Pydoll code style and ensure the separation of concerns.

thalissonvs avatar Mar 12 '25 14:03 thalissonvs

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis ✅

41 - Fully compliant

Compliant requirements:

• Add Microsoft Edge browser support to pydoll • Implement Edge browser class • Add Edge-specific configurations • Add tests for Edge browser functionality • Ensure full test coverage

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
🔀 Multiple PR themes

Sub-PR theme: Refactor base browser classes to support multiple browser types

Relevant files:

  • pydoll/browser/constants.py
  • pydoll/browser/base.py
  • pydoll/browser/managers.py
  • pydoll/browser/options.py

Sub-PR theme: Add Microsoft Edge browser implementation

Relevant files:

  • pydoll/browser/edge.py
  • pydoll/browser/init.py

Sub-PR theme: Add tests for Microsoft Edge browser support

Relevant files:

  • tests/test_edge.py

⚡ Recommended focus areas for review

Missing KDoc

The Edge class is missing KDoc format comments for the class and methods. According to the requirements, domain classes should have KDoc format comments.

class Edge(Browser):
    def __init__(
        self, options: Options | None = None, connection_port: int = 9222
    ):
        if options is None:
            options = EdgeOptions()
        # Initialize base class with options and port
        super().__init__(options, connection_port)

Missing KDoc

The ChromeOptions and EdgeOptions classes are missing KDoc format comments. Domain classes should include KDoc format documentation.

class ChromeOptions(Options):
    def __init__(self):
        super().__init__(browser_type=BrowserType.CHROME)

class EdgeOptions(Options):
    def __init__(self):
        super().__init__(browser_type=BrowserType.EDGE)
Non-English Comments

There are non-English comments in the test file which should be translated to English for consistency.

# 清理代码

qodo-merge-pro[bot] avatar Mar 13 '25 08:03 qodo-merge-pro[bot]

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Security
Fix security risk

[English]

  • The Edge browser implementation uses a fixed user data directory
    (~/.edge_automation) instead of a temporary directory. This creates a potential
    security and privacy risk as user data persists between sessions. Consider using
    a temporary directory for Edge as well, or implementing a proper cleanup
    mechanism for the fixed directory.

    [日本語]

  • Edgeブラウザの実装では、一時ディレクトリの代わりに固定のユーザーデータディレクトリ(~/.edge_automation)を使用しています。これにより、ユーザーデータがセッション間で永続化されるため、セキュリティとプライバシーのリスクが生じる可能性があります。Edgeでも一時ディレクトリを使用するか、固定ディレクトリに適切なクリーンアップメカニズムを実装することを検討してください。
  • pydoll/browser/base.py [574-586]

     def _setup_user_dir(self):
         """Prepares the user data directory if necessary."""
         if '--user-data-dir' not in [arg.split('=')[0] for arg in self.options.arguments]:
    -        # Check if this is an Edge browser
    -        if self.options.browser_type == BrowserType.EDGE:
    -            # For Edge browser, use a fixed user data directory
    -            user_data_dir = os.path.join(os.path.expanduser('~'), '.edge_automation')
    -            os.makedirs(user_data_dir, exist_ok=True)
    -            self.options.arguments.append(f'--user-data-dir={user_data_dir}')
    -        else:
    -            # For other browsers, use a temporary directory
    -            temp_dir = self._temp_directory_manager.create_temp_dir()
    -            self.options.arguments.append(f'--user-data-dir={temp_dir.name}')
    +        # For all browsers, use a temporary directory
    +        temp_dir = self._temp_directory_manager.create_temp_dir()
    +        self.options.arguments.append(f'--user-data-dir={temp_dir.name}')
    
    • [ ] Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: Using a fixed user data directory for Edge browser creates a significant security and privacy risk as sensitive user data persists between sessions. Using temporary directories for all browsers is a more secure approach.

    High
    General
    Remove duplicate import
    Suggestion Impact:The commit removed the duplicate import of Optional from the typing module as suggested

    code diff:

    -from typing import Optional
     from typing import Optional
    

    [English]

  • Remove the duplicate import of Optional from the typing module. This redundancy
    can cause confusion and is unnecessary.

    [日本語]
  • typingモジュールからのOptionalのインポートが重複しています。この冗長性は混乱を招く可能性があり、不要です。
  • pydoll/browser/chrome.py [2-3]

    -from typing import Optional
     from typing import Optional
    

    [Suggestion has been applied]

    Suggestion importance[1-10]: 7

    __

    Why: The duplicate import of Optional from the typing module is unnecessary and can cause confusion. Removing it improves code cleanliness and readability.

    Medium
    Remove trailing whitespace
    Suggestion Impact:The commit includes changes to the Edge class constructor, including the line with super().__init__(). While the implementation is different from the original code, the trailing whitespace issue appears to be addressed in the new implementation.

    code diff:

    +        super().__init__(options, connection_port, BrowserType.EDGE)
             
    

    [English]

  • The Edge class constructor has a trailing comma after the super().init()
    call, followed by an empty line with whitespace. This can lead to inconsistent
    code formatting and potential linting issues. Remove the trailing whitespace to
    maintain clean code.

    [日本語]

  • Edgeクラスのコンストラクタには、super().init()呼び出しの後に末尾のカンマがあり、その後に空白を含む空の行があります。これにより、コードの書式設定が一貫性を欠き、潜在的なリンティングの問題が発生する可能性があります。末尾の空白を削除して、クリーンなコードを維持してください。
  • pydoll/browser/edge.py [11-17]

    
    

    [Suggestion has been applied]

    Suggestion importance[1-10]: 3

    __

    Why: The trailing whitespace after the super().init() call can lead to inconsistent code formatting and potential linting issues. While not critical, removing it improves code cleanliness.

    Low
    • [ ] Update
    • [ ] Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    qodo-merge-pro[bot] avatar Mar 13 '25 08:03 qodo-merge-pro[bot]

    Hi @Harris-H,

    First of all, thanks for your contribution! This feature is amazing.

    I just left some comments to maintain the Pydoll code style and ensure the separation of concerns.

    You're welcome. I have completed the main revisions. There may still be some areas that need to be improved. If you have any questions, we can discuss them again.

    Harris-H avatar Mar 13 '25 11:03 Harris-H

    Thank's! I'll review as soon as possible :) Since it's a breaking change, I'll do some refactor first before merge.

    thalissonvs avatar Mar 14 '25 01:03 thalissonvs

    Hi @Harris-H , how are you? Once you fix the tests, please let me know

    thalissonvs avatar Mar 18 '25 01:03 thalissonvs

    Hi @Harris-H , how are you? Once you fix the tests, please let me know

    Ok, I fixed the code and now the test passes。 @thalissonvs

    Harris-H avatar Mar 18 '25 03:03 Harris-H

    Hi @Harris-H , I just checked the code again, and the tests are still failing. I've created a CONTRIBUTING.md file. If you need any help, please contact me

    thalissonvs avatar Mar 19 '25 23:03 thalissonvs

    Hi @Harris-H , I just checked the code again, and the tests are still failing. I've created a CONTRIBUTING.md file. If you need any help, please contact me

    image Sorry, all tests should pass now. @thalissonvs

    Harris-H avatar Mar 20 '25 03:03 Harris-H

    Hi @Harris-H , the tests are passing, but the ruff ci is still breaking :/

    thalissonvs avatar Mar 21 '25 21:03 thalissonvs

    Codecov Report

    Attention: Patch coverage is 90.54054% with 7 lines in your changes missing coverage. Please review.

    Files with missing lines Patch % Lines
    pydoll/browser/managers.py 87.50% 4 Missing :warning:
    pydoll/browser/options.py 81.81% 2 Missing :warning:
    pydoll/browser/chrome.py 50.00% 1 Missing :warning:

    :loudspeaker: Thoughts on this report? Let us know!

    codecov[bot] avatar Mar 21 '25 21:03 codecov[bot]

    Hi @Harris-H , the tests are passing, but the ruff ci is still breaking :/

    Hello @thalissonvs, the CI check of ruff has been repaired.

    Harris-H avatar Mar 23 '25 11:03 Harris-H

    Nice @Harris-H , thank you so much. I'll update the documentation later :)

    thalissonvs avatar Mar 23 '25 16:03 thalissonvs