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

feat: browser improvements #259

Merged
merged 13 commits into from
Dec 17, 2024
Merged

feat: browser improvements #259

merged 13 commits into from
Dec 17, 2024

Conversation

amhsirak
Copy link
Member

@amhsirak amhsirak commented Dec 14, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced selector handling for improved efficiency and reliability.
    • Introduced random user agent selection for better browser automation stealth.
    • Increased timeout values for element checks to improve robustness.
  • Bug Fixes

    • Improved error handling for script injection failures.
  • Documentation

    • Updated logging functionality for better workflow execution insights.
  • Chores

    • Minor formatting adjustments for better code readability.

Copy link

coderabbitai bot commented Dec 14, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces modifications to two key files: maxun-core/src/interpret.ts and server/src/browser-management/classes/RemoteBrowser.ts. In the Interpreter class, changes focus on improving selector handling, with updates to getSelectors, getState, and run methods to enhance selector collection efficiency, reliability, and error management. The RemoteBrowser class sees improvements in user agent handling, browser initialization, and script injection, with a new method for dynamically selecting user agents and enhanced browser configuration options.

Changes

File Change Summary
maxun-core/src/interpret.ts - Updated getSelectors to use Set for unique selector collection
- Modified getState to use page.waitForSelector for more reliable selector retrieval
- Increased timeout values from 5000 to 10000 milliseconds
- Added default navigation timeout of 100000 milliseconds in run method
server/src/browser-management/classes/RemoteBrowser.ts - Added getUserAgent() method to randomly select user agent strings
- Updated initialize method with enhanced browser launch options
- Modified setupPageEventListeners and initializeNewPage methods
- Improved error handling for script injection

Possibly related PRs

  • feat: rect dom depth information #235: The changes in this PR also modify methods within the Interpreter class in maxun-core/src/interpret.ts, specifically enhancing selector handling and ensuring uniqueness, which aligns with the updates made in the main PR regarding selector management.

Poem

🐰 In the land of code where selectors play,
Unique they gather, no duplicates sway.
User agents frolic, chosen with care,
Browsers now stealthy, a digital affair.
With timeouts extended, workflows take flight! 🚀

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. We would love to hear your feedback on Discord.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e22c019 and ffe87b0.

📒 Files selected for processing (1)
  • server/src/browser-management/classes/RemoteBrowser.ts (7 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@amhsirak amhsirak marked this pull request as draft December 14, 2024 19:33
@amhsirak amhsirak added Type: Enhancement Improvements to existing features Status: Work In Progess This issue/PR is actively being worked on labels Dec 14, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Outside diff range and nitpick comments (2)
maxun-core/src/interpret.ts (2)

195-196: Consider removing commented-out code for clarity.

The code at lines 190-211, including the actionable function, is commented out. If this code is no longer needed, consider removing it to improve code readability and maintainability.


218-227: Specify a timeout for page.waitForSelector to prevent indefinite waits.

Consider specifying a timeout for page.waitForSelector to prevent the function from waiting indefinitely if the selector does not appear.

Apply this diff to add a timeout:

- await page.waitForSelector(selector, { state: 'attached' });
+ await page.waitForSelector(selector, { state: 'attached', timeout: 10000 });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4469325 and e22c019.

📒 Files selected for processing (2)
  • maxun-core/src/interpret.ts (4 hunks)
  • server/src/browser-management/classes/RemoteBrowser.ts (6 hunks)
🔇 Additional comments (3)
maxun-core/src/interpret.ts (1)

782-782: Verify necessity of increasing default navigation timeout to 100000ms.

Setting page.setDefaultNavigationTimeout(100000); increases the navigation timeout to 100 seconds. Ensure that this increase is necessary and does not mask underlying issues with slow page loads.

server/src/browser-management/classes/RemoteBrowser.ts (2)

133-137: Good job adding error handling in injectScript function.

The error handling and logging in the injectScript function within the load event handler will aid in diagnosing script injection issues.


218-241: Verify that the injected script to hide navigator.webdriver works correctly.

Review the injected script to ensure it properly hides the navigator.webdriver property and doesn't introduce errors.

Comment on lines 173 to 179
args: [
"--disable-blink-features=AutomationControlled",
"--disable-web-security",
"--disable-features=IsolateOrigins,site-per-process",
"--disable-site-isolation-trials",
"--disable-extensions"
],
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Review necessity of disabling security features in Chromium launch arguments.

Disabling features like --disable-web-security may expose the browser to security risks. Ensure that disabling these features is necessary and consider alternative approaches.

Comment on lines +151 to +163
private getUserAgent() {
const userAgents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.140 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:117.0) Gecko/20100101 Firefox/117.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.1938.81 Safari/537.36 Edg/116.0.1938.81',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.96 Safari/537.36 OPR/101.0.4843.25',
'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.62 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:118.0) Gecko/20100101 Firefox/118.0',
];

return userAgents[Math.floor(Math.random() * userAgents.length)];
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Verify the accuracy of user agent strings in getUserAgent.

The user agent string 'Mozilla/5.0 (Windows NT 11.0; Win64; x64)...' may not be accurate since Windows typically reports as 'Windows NT 10.0'. Ensure user agent strings are accurate to avoid detection.

Apply this diff to correct the user agent string:

- 'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.62 Safari/537.36',
+ 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.62 Safari/537.36',
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private getUserAgent() {
const userAgents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.140 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:117.0) Gecko/20100101 Firefox/117.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.1938.81 Safari/537.36 Edg/116.0.1938.81',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.96 Safari/537.36 OPR/101.0.4843.25',
'Mozilla/5.0 (Windows NT 11.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.62 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:118.0) Gecko/20100101 Firefox/118.0',
];
return userAgents[Math.floor(Math.random() * userAgents.length)];
}
private getUserAgent() {
const userAgents = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.140 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:117.0) Gecko/20100101 Firefox/117.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.1938.81 Safari/537.36 Edg/116.0.1938.81',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.5845.96 Safari/537.36 OPR/101.0.4843.25',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.5938.62 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:118.0) Gecko/20100101 Firefox/118.0',
];
return userAgents[Math.floor(Math.random() * userAgents.length)];
}

@amhsirak amhsirak marked this pull request as ready for review December 17, 2024 16:23
@amhsirak amhsirak merged commit fa2d609 into develop Dec 17, 2024
1 check was pending
@amhsirak amhsirak removed the Status: Work In Progess This issue/PR is actively being worked on label Dec 20, 2024
@amhsirak amhsirak deleted the webdrive-patch branch January 2, 2025 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement Improvements to existing features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants