Skip to content

Conversation

@msynk
Copy link
Member

@msynk msynk commented Nov 2, 2025

closes #11548

Summary by CodeRabbit

Release Notes

  • New Features
    • User agent extraction now supports custom user agent strings. Users can provide any user agent string for analysis, with automatic fallback to the browser's default if none is provided.

@msynk msynk merged commit 7cb4e86 into bitfoundation:develop Nov 2, 2025
3 checks passed
@msynk msynk deleted the 11548-butil-useragent-custom-string-input branch November 2, 2025 09:26
@msynk msynk requested a review from ysmoradi November 2, 2025 09:42
@coderabbitai
Copy link

coderabbitai bot commented Nov 2, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes extend the UserAgent API to accept an optional custom user-agent string parameter. Previously, the API exclusively used the browser's navigator.userAgent. Now, when provided, the custom string overrides the default navigator value. The C#, TypeScript, and demo UI layers are updated to support this new parameter throughout the call chain.

Changes

Cohort / File(s) Summary
C# UserAgent method signature
src/Butil/Bit.Butil/Publics/UserAgent.cs
Extract() method now accepts optional userAgentString parameter and passes it to the JS interop call
TypeScript extract function
src/Butil/Bit.Butil/Scripts/userAgent.ts
extract() function now accepts optional userAgentString parameter; uses provided string or falls back to window.navigator.userAgent
Demo UI integration
src/Butil/Demo/Bit.Butil.Demo.Core/Pages/UserAgentPage.razor
Adds new UI input field for custom user-agent string; updates Extract() call to pass the input value

Sequence Diagram

sequenceDiagram
    participant UI as UserAgentPage.razor
    participant CS as UserAgent.cs
    participant TS as userAgent.ts
    participant Nav as window.navigator

    UI->>CS: Extract(userAgentString?)
    CS->>TS: JS interop: extract(userAgentString?)
    alt userAgentString provided
        TS->>TS: ua = userAgentString
    else userAgentString not provided
        TS->>Nav: get userAgent
        TS->>TS: ua = navigator.userAgent
    end
    TS->>TS: Parse ua & return properties
    TS-->>CS: UserAgentProperties
    CS-->>UI: UserAgentProperties
    UI->>UI: Log results
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • The changes follow a consistent, homogeneous pattern across all three files—adding an optional parameter at each layer
  • Parameter passing is straightforward with no complex logic branching
  • Falls back to existing behavior when the optional parameter is not provided
  • Minor consideration: Verify the fallback logic in TypeScript correctly preserves the original behavior

Poem

🐰 A user-agent string, now bends to our will!
Custom parsing flows down through each tier—
TypeScript, C#, and Razor compile with glee,
Debugging dreams made simple to steer,
No more stuck with just what the browser won't spill! 🎯

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Add custom string input feature to UserAgent api of Butil (#11548)" directly and clearly describes the main change in the changeset. The modifications to the UserAgent API enable accepting an optional custom user-agent string parameter, which is exactly what the title conveys. The title is concise, specific, and avoids vague language, making it immediately clear to a reviewer what the primary objective of this change is.
Linked Issues Check ✅ Passed The code changes comprehensively address the requirements from issue #11548. The changes enable the UserAgent API to accept an optional custom user-agent string parameter across both the C# layer (Extract method now accepts optional string parameter) and the TypeScript layer (extract function accepts optional userAgentString parameter) [#11548]. The implementation properly falls back to window.navigator.userAgent when no custom string is provided, preserving backward compatibility [#11548]. The demo page has been updated to showcase this new capability, supporting the stated goal of enabling debugging and testing scenarios [#11548].
Out of Scope Changes Check ✅ Passed All changes in this pull request are directly scoped to implementing the custom user-agent string input feature for the UserAgent API as specified in issue #11548. The modifications include the C# method signature update, the TypeScript function signature update with fallback logic, and the demo page enhancement to use the new parameter. No unrelated changes, refactoring, or ancillary modifications are present in the changeset.

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/Butil/Bit.Butil/Publics/UserAgent.cs (1)

12-14: Update XML documentation to describe the new parameter.

The XML doc comment should document the new userAgentString parameter.

Apply this diff:

     /// <summary>
     /// Extracts the user agent properties from the browser or web-view.
     /// </summary>
+    /// <param name="userAgentString">Optional custom user agent string to parse. If null, uses the browser's navigator.userAgent.</param>
     [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(UserAgentProperties))]
🧹 Nitpick comments (1)
src/Butil/Demo/Bit.Butil.Demo.Core/Pages/UserAgentPage.razor (1)

27-28: Consider adding a label or placeholder for better UX.

The input field lacks context about what the user should enter. Adding a label or placeholder would improve usability and accessibility.

Apply this diff:

-<input @bind="userAgentString" />
+<input @bind="userAgentString" placeholder="Enter custom user agent string (optional)" />

Or add a label:

+<label for="userAgentInput">Custom User Agent String (optional):</label>
+<input id="userAgentInput" @bind="userAgentString" />
-<input @bind="userAgentString" />
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between 36e67a6 and fe48182.

📒 Files selected for processing (3)
  • src/Butil/Bit.Butil/Publics/UserAgent.cs (1 hunks)
  • src/Butil/Bit.Butil/Scripts/userAgent.ts (2 hunks)
  • src/Butil/Demo/Bit.Butil.Demo.Core/Pages/UserAgentPage.razor (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build and test
🔇 Additional comments (3)
src/Butil/Bit.Butil/Scripts/userAgent.ts (2)

8-10: LGTM! The parameter handling logic is sound.

The optional parameter with fallback chain (userAgentString || nav.userAgent || '') correctly prioritizes custom input while maintaining backward compatibility.

Note: Whitespace-only strings will be treated as truthy and passed through. This is acceptable for a debugging/testing feature, but consider trimming the input in the UI layer if stricter validation is desired.


426-426: ****

src/Butil/Demo/Bit.Butil.Demo.Core/Pages/UserAgentPage.razor (1)

34-40: LGTM! The implementation correctly uses the new parameter.

The private field and Extract method implementation properly integrate with the updated UserAgent API.

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.

The UserAgent api of bit Butil can accept a custom user-agent string too

1 participant