Skip to content

Scrub User Agent#45

Merged
iamEvanYT merged 8 commits intomainfrom
evan/scrub-user-agent
May 20, 2025
Merged

Scrub User Agent#45
iamEvanYT merged 8 commits intomainfrom
evan/scrub-user-agent

Conversation

@iamEvanYT
Copy link
Member

@iamEvanYT iamEvanYT commented May 11, 2025

tldr

Remove electron's user agent to make websites load better.

Summary by CodeRabbit

  • New Features

    • User agent headers are now automatically transformed on outgoing requests for enhanced privacy and compatibility.
  • Bug Fixes

    • Improved handling of user agent strings to reduce issues with certain websites flagging the app as a bot.
  • Chores

    • Updated internal feature flag to enable user agent transformation by default.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 11, 2025

"""

Walkthrough

The changes introduce a centralized utility function to transform the user agent string, replacing manual scrubbing logic in multiple locations. User agent modification is now consistently handled via this function, and a webRequest interceptor applies the transformation to outgoing requests. The relevant feature flag is enabled by default, and some legacy header logic is removed.

Changes

File(s) Change Summary
src/main/browser/profile-manager.ts Replaced manual user agent scrubbing with the new transformUserAgentHeader utility. Removed unused imports and flag check.
src/main/browser/utility/intercept-rules.ts Added setupUserAgentTransformer to intercept and transform outgoing "User-Agent" headers. Removed legacy Origin header logic. Updated setupInterceptRules to include user agent transformation.
src/main/browser/utility/user-agent.ts Introduced transformUserAgentHeader utility function for user agent string transformation based on feature flags.
src/main/modules/flags.ts Enabled the SCRUBBED_USER_AGENT flag by default and updated its comment.

Sequence Diagram(s)

sequenceDiagram
    participant BrowserSession
    participant InterceptRules
    participant UserAgentUtil

    BrowserSession->>InterceptRules: setupInterceptRules(session)
    InterceptRules->>InterceptRules: setupUserAgentTransformer(session)
    BrowserSession->>InterceptRules: Outgoing HTTP Request
    InterceptRules->>UserAgentUtil: transformUserAgentHeader(userAgent, url)
    UserAgentUtil-->>InterceptRules: Transformed userAgent
    InterceptRules->>BrowserSession: Continue with possibly modified userAgent
Loading

Poem

🐇
A rabbit hops through code anew,
User agents fresh, transformed, and true.
No more scrubbing line by line—
A single function does just fine!
Headers intercepted, flags in place,
This bunny leaves a streamlined trace.
Hooray for change! Now onward, race!

"""

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between c8ce07a and f7fcf4c.

📒 Files selected for processing (1)
  • src/main/browser/utility/user-agent.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/utility/user-agent.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (windows-latest)
  • GitHub Check: build (ubuntu-latest)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @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.

@iamEvanYT iamEvanYT force-pushed the main branch 2 times, most recently from b0e71fc to e03f31b Compare May 14, 2025 14:02
@iamEvanYT iamEvanYT force-pushed the evan/scrub-user-agent branch from 87f56de to 9763c1f Compare May 18, 2025 21:40
@github-actions
Copy link
Contributor

Build is in progress... 🚀

Currently building for this pull request!

@iamEvanYT iamEvanYT force-pushed the evan/scrub-user-agent branch from 9763c1f to 02a5eea Compare May 19, 2025 20:09
@iamEvanYT iamEvanYT marked this pull request as ready for review May 20, 2025 16:16
Copy link
Contributor

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

🧹 Nitpick comments (6)
src/main/modules/flags.ts (1)

17-18: Improve documentation for the SCRUBBED_USER_AGENT flag

The current comment "Transform the user agent" is overly simplified and loses important context. Based on the PR objectives, this flag addresses specific issues with websites flagging the Electron user agent as insecure or blocking access.

Consider enhancing the comment to include more context about why this transformation is needed:

-  // Transform the user agent
+  // Transform the user agent to remove Electron-specific identifiers
+  // which can cause compatibility issues with services like Google and
+  // Cloudflare Turnstile that may flag Electron as insecure
   SCRUBBED_USER_AGENT: true,
src/main/browser/utility/user-agent.ts (3)

4-4: Hardcoded Edge version might require frequent updates

The Edge user agent version is hardcoded, which will need manual updates when new Edge versions are released.

Consider making this configurable or dynamically generated to avoid the need for frequent code changes:

-const EDGE_USER_AGENT = "Edg/136.0.3240.76";
+// Use a configuration file or environment variable for easier updates
+const EDGE_USER_AGENT = process.env.EDGE_USER_AGENT || "Edg/136.0.3240.76";

11-13: Add comments explaining transformation strategy decisions

The transformation strategy uses three boolean flags without explaining why these specific transformations were chosen or what they accomplish.

Add descriptive comments to explain the purpose of each flag:

-  const addEdgeUserAgent = true;
-  const removeElectronUserAgent = true;
-  const removeAppUserAgent = false;
+  // Add Edge browser identifier to improve compatibility with websites that validate browser type
+  const addEdgeUserAgent = true;
+  // Remove Electron identifier which can trigger security warnings on some websites
+  const removeElectronUserAgent = true;
+  // Preserve the app identifier to maintain brand identity in requests
+  const removeAppUserAgent = false;

15-19: Clean up or implement the commented-out URL-specific logic

There's commented-out code for URL-specific transformations that suggests incomplete implementation.

Either implement this feature if needed for specific sites like Google accounts, or remove the commented code to avoid confusion:

-  if (url) {
-    // const hostname = url.hostname.toLowerCase();
-    // if (hostname === "accounts.google.com") {
-    // }
-  }
+  // URL-specific transformations can be added here if needed in the future
+  // Example: if (url?.hostname.toLowerCase() === "accounts.google.com") { ... }
src/main/browser/utility/intercept-rules.ts (2)

15-15: Replace deprecated URL.parse with WHATWG URL API

The URL.parse() method is deprecated in newer Node.js versions. Consider using the WHATWG URL API instead.

-  const url = URL.parse(details.url);
+  const url = new URL(details.url);

121-123: Recommend adding priority comment for user agent transformation

The transformer setup is now listed first in the intercept rules, but there's no explanation for this ordering.

Add a comment explaining the priority of this transformation:

-  // Transform the User-Agent header
+  // Transform the User-Agent header first to ensure all outgoing requests
+  // use the modified user agent, addressing compatibility issues with services
+  // like Google and Cloudflare Turnstile
   setupUserAgentTransformer(session);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 1e6958a and c8ce07a.

📒 Files selected for processing (4)
  • src/main/browser/profile-manager.ts (3 hunks)
  • src/main/browser/utility/intercept-rules.ts (2 hunks)
  • src/main/browser/utility/user-agent.ts (1 hunks)
  • src/main/modules/flags.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/main/browser/profile-manager.ts (1)
src/main/browser/utility/user-agent.ts (1)
  • transformUserAgentHeader (6-36)
src/main/browser/utility/user-agent.ts (1)
src/main/modules/flags.ts (1)
  • FLAGS (16-40)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: build (ubuntu-latest)
  • GitHub Check: build (windows-latest)
🔇 Additional comments (2)
src/main/browser/profile-manager.ts (1)

123-128: Good refactoring of user agent transformation logic

The user agent transformation logic has been properly refactored to use the centralized utility function, improving maintainability and consistency across the application.

src/main/browser/utility/intercept-rules.ts (1)

9-36: Implement dynamic user agent transformation for all requests

The new function effectively intercepts and transforms user agent headers for all outgoing requests, ensuring consistent behavior throughout the application.

@iamEvanYT iamEvanYT merged commit 66c99b2 into main May 20, 2025
7 checks passed
@iamEvanYT iamEvanYT deleted the evan/scrub-user-agent branch May 20, 2025 16:36
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.

1 participant

Comments