Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve DOM Processing #616

Merged
merged 16 commits into from
Feb 11, 2025
Merged

Improve DOM Processing #616

merged 16 commits into from
Feb 11, 2025

Conversation

maticzav
Copy link
Collaborator

@maticzav maticzav commented Feb 7, 2025

This PR improves the DOM processing functionality. Instead of saving DOM in a tree structure, it saves elements to a hash map and keeps the pointers for rewiring in Python.

It's a drop in replacement that changes no interfaces.

Additionally, it improves the calculation of the DOM elements in the JS eval script by ignoring the added indicator elements.

@CLAassistant
Copy link

CLAassistant commented Feb 7, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

codebeaver-ai bot commented Feb 7, 2025

I opened a Pull Request with the following:

🔄 1 test added.
🐛 Found 1 bug
🛠️ 1/8 tests passed

🔄 Test Updates

I've added 1 tests. They all pass ☑️
New Tests:

  • tests/test_views.py

No existing tests required updates.

🐛 Bug Detection

Potential issues found in the following files:

  • browser_use/dom/service.py

The error is raised by the code in Registry.execute_action when it calls the action function. Although the test calls execute_action with a “browser” keyword argument (and so the merged parameters should include browser), the function ends up not actually receiving that argument. In other words, the extra browser parameter is either being dropped or not passed correctly when calling action.function(**validated_params.model_dump(), **extra_args). This causes the underlying async function (test_action_with_browser) to be invoked without its required “browser” parameter, triggering a TypeError. Thus, the registry’s implementation of execute_action is buggy in how it handles and passes extra keyword arguments to the action function.

🛠️ Test Results

1/8 tests passed ⚠️

tests/test_dropdown.py

View error
tests/test_dropdown.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_dropdown.py

tests/test_dropdown_complex.py

View error
tests/test_dropdown_complex.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_dropdown_complex.py

tests/test_dropdown_error.py

View error
tests/test_dropdown_error.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_dropdown_error.py

tests/test_gif_path.py

View error
tests/test_gif_path.py:19: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_gif_path.py

tests/test_models.py

View error
tests/test_models.py:54: in <module>
    ChatOpenAI(
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_models.py

tests/test_react_dropdown.py

View error
tests/test_react_dropdown.py:20: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_react_dropdown.py

tests/test_vision.py

View error
tests/test_vision.py:25: in <module>
    llm = ChatOpenAI(model='gpt-4o')
/usr/local/lib/python3.11/site-packages/langchain_core/load/serializable.py:125: in __init__
    super().__init__(*args, **kwargs)
/usr/local/lib/python3.11/site-packages/langchain_openai/chat_models/base.py:622: in validate_environment
    self.root_client = openai.OpenAI(**client_params, **sync_specific)  # type: ignore[arg-type]
/usr/local/lib/python3.11/site-packages/openai/_client.py:110: in __init__
    raise OpenAIError(
E   openai.OpenAIError: The api_key client option must be set either by passing api_key to the client or by setting the OPENAI_API_KEY environment variable

tests/test_vision.py

☂️ Coverage Improvements

Coverage improvements by file:

  • tests/test_views.py

    New coverage: 99.07%
    Improvement: +99.07%

🎨 Final Touches

  • I ran the hooks included in the pre-commit config.

Settings | Logs | CodeBeaver

@gregpr07 gregpr07 requested a review from MagMueller February 11, 2025 02:58
@MagMueller MagMueller merged commit 87f4d74 into main Feb 11, 2025
3 checks passed
@MagMueller MagMueller deleted the fix/memory branch February 11, 2025 03:11
AryamanParida pushed a commit to AryamanParida/browser-use that referenced this pull request Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants