Skip to content

feat(browser): give the embedded browser a faithful Chrome user-agent - #1343

Merged
Astro-Han merged 2 commits into
devfrom
claude/browser-ua
Jun 17, 2026
Merged

feat(browser): give the embedded browser a faithful Chrome user-agent#1343
Astro-Han merged 2 commits into
devfrom
claude/browser-ua

Conversation

@Astro-Han

@Astro-Han Astro-Han commented Jun 17, 2026

Copy link
Copy Markdown
Owner

Summary

Give the embedded browser a faithful Chrome user-agent. Electron's default UA carries an Electron/<ver> token and the app's own product token (opencode/<ver> after index.ts's rewrite, PawWork .../<ver> before it) exactly where a real Chrome UA has nothing — both are obvious "not a normal browser" tells. We strip them and pin the Chrome token to the reduced Chrome/<major>.0.0.0 form real Chrome reports, deriving the major from process.versions.chrome so it tracks the embedded Chromium and never drifts. The clean UA is set on the persist:pawwork-browser partition, so it applies to both manual browsing and CDP-driven automation.

This is the first stealth-fidelity change after a real Xiaohongshu "suspected automation" warning. It is legitimate fingerprint fidelity: the view IS real Chromium (Electron), and we present it as the Chromium it actually is — for users operating their own accounts — rather than leaking Electron/app tokens that look like a bot.

Why this shape (Client Hints left at Chromium defaults — deliberate)

Codex consult + Electron/Chromium source confirmed:

  • Electron does not invent its own UA Client Hints; it delegates to Chromium's embedder_support::GetUserAgentMetadata(). So default navigator.userAgentData brands as Chromium (+ a GREASE brand) and does not leak "Electron" or the app name.
  • session.setUserAgent sets only the UA string + Accept-Language. The only way to set Client Hints for manual browsing would be a permanent CDP debugger attach, which is itself a detectable signal and is explicitly not worth it.

So the chosen identity is faithful, consistent Chromium, not impersonated Google Chrome:

  • A real Chromium build reports UA Chrome/<major>.0.0.0 and CH brand Chromium — exactly what we now produce. Internally consistent, nothing faked.
  • The rejected alternative (add a "Google Chrome" brand via CDP on the automation path only) would make the same profile present as Chromium when browsed manually and Google Chrome when the agent drives — an intra-profile identity flip a real browser never does, i.e. a new tell. Consistency is the better stealth.
  • Verified opencli's automation path does not override UA or touch navigator.userAgentData (only Emulation.setDeviceMetricsOverride + Network.enable), so automation inherits the same consistent identity; its stealth script handles the automation-specific JS tells (webdriver, chrome, plugins, languages).

Honest ceiling: this fixes the fingerprint layer only. It does not make automation "safe" on a mature behavioral risk-control platform (speed/rhythm/trajectory still matter). It removes the loud UA tell that this browser is not a normal one.

Related Issue

None — follow-up from a maintainer report; no tracking issue yet.

Human Review Status

Pending

Review Focus

  • toChromeUserAgent in user-agent.ts: token stripping is robust to both the opencode/ (post-rewrite) and PawWork .../ (pre-rewrite, app name with a space) forms, preserves the OS platform token (macOS vs Windows), and is idempotent.
  • Placement/scope in controller.ts: partition-scoped (app renderer UA untouched), once-guarded, set before the first view's first request.
  • The Client-Hints decision above — is "faithful Chromium, consistent across manual+auto" the identity we want, vs. impersonating Google Chrome?

Risk Notes

  • Scope is the persist:pawwork-browser partition only; app.userAgentFallback (app renderer) is intentionally left as-is.
  • Client Hints are unchanged (Chromium defaults). If a site compares UA string vs CH it sees a consistent real-Chromium browser.
  • No visible UI/copy changed; this is network-level identity.

How To Verify

Verified by me (CI-checkable):

packages/desktop-electron:
typecheck (tsgo -b): clean
test src/main/browser/: 58 pass (incl. user-agent.test.ts 10 pass — Electron/opencode/PawWork tokens stripped, Chrome version pinned, macOS+Windows shapes, idempotent, unparseable-version fallback, and the configurePartitionUserAgent seam applies the cleaned UA to the partition session)

Runtime check (needs the desktop GUI — your machine), using the fingerprint probe I sent separately:

  1. Run dev:desktop, open the embedded browser, load the probe HTML.
  2. Confirm navigator.userAgent = ...Chrome/<major>.0.0.0 Safari/537.36 with no Electron / opencode / PawWork (probe flags these red).
  3. Confirm navigator.userAgentData.brands shows Chromium (+ GREASE), no Electron/app leak.
  4. Compare against an external Chrome — UA string and CH should both read as a coherent Chromium/Chrome browser.

Screenshots or Recordings

N/A — no visible UI change (network-level UA).

Checklist

  • Type label — exactly one of bug, enhancement, task, documentation.
  • Routing labels — at least one of app, ui, platform, harness, ci.
  • Priority label — exactly one of P0, P1, P2, P3.
  • Human Review Status above is set to Pending.
  • I linked the related issue, or stated in Summary why there is no issue.
  • I described the review focus and any meaningful risks.
  • I replaced the example block in How To Verify with the real verification steps and the key result for each.
  • I did not introduce unrelated refactors, dependencies, generated files, or file changes beyond the stated scope.
  • (conditional) I manually checked visible UI or copy changes when needed. Left unticked: no visible UI/copy changed.
  • (conditional) I considered macOS and Windows impact — the UA platform token differs per OS; toChromeUserAgent preserves Electron's frozen per-OS token and is tested for both macOS and Windows shapes.
  • (conditional) docs/release notes/deps/permissions/credentials/deletion/generated content/local files — none touched.
  • I reviewed the final diff for unrelated changes and suspicious dependency changes.
  • I am targeting dev, and my PR title and commit messages use Conventional Commits in English.

Summary by CodeRabbit

  • New Features

    • Browser now automatically identifies itself to web servers using Chrome user agent format instead of Electron
    • Browser initialization updated to apply the correct user agent from the first request onward
  • Tests

    • Added tests validating user agent string normalization, Chrome version extraction, and proper format conversion

Strip Electron's `Electron/<ver>` and the app product token from the embedded
browser's UA and pin Chrome to the reduced `<major>.0.0.0` form, deriving the
major from process.versions.chrome. Set on the persist:pawwork-browser
partition so it covers both manual browsing and CDP automation. Client Hints
are left at Chromium's correct defaults so manual and automation present one
consistent, faithful Chromium identity (app renderer UA untouched).
@Astro-Han Astro-Han added enhancement New feature or request P0 Blocking / highest priority labels Jun 17, 2026
@github-actions github-actions Bot added the platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions label Jun 17, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested priority: P2 (includes user-path files (packages/desktop-electron/src/main/browser/controller.ts, packages/desktop-electron/src/main/browser/user-agent.test.ts, packages/desktop-electron/src/main/browser/user-agent.ts)).

P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.

@coderabbitai

coderabbitai Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

A new user-agent.ts module exports chromeMajorVersion and toChromeUserAgent, which rewrite Electron's default UA into a Chrome-only UA by stripping Electron and app-specific tokens and pinning the Chrome version. A one-time guarded helper in controller.ts applies this rewrite to the shared browser partition session before the first WebContentsView is instantiated. Tests validate all normalization cases.

Changes

Electron Partition User-Agent Normalization

Layer / File(s) Summary
UA normalization module and tests
packages/desktop-electron/src/main/browser/user-agent.ts, packages/desktop-electron/src/main/browser/user-agent.test.ts
Introduces chromeMajorVersion (extracts leading numeric major from a version string) and toChromeUserAgent (strips Electron/app tokens, pins Chrome/ to <major>.0.0.0, normalizes whitespace). Tests cover token stripping, version pinning, idempotence, Windows platform preservation, double-space removal, and unparseable version fallback.
Controller partition UA wiring
packages/desktop-electron/src/main/browser/controller.ts
Adds ensureBrowserPartitionUserAgent, a once-per-process guard that fetches the partition session via session.fromPartition(BROWSER_PARTITION) and sets its UA using toChromeUserAgent. Calls the guard at the top of BrowserViewController construction. Replaces the browserViewWebPreferences import with toChromeUserAgent.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested labels

enhancement, desktop, P2

Poem

🐇 A browser once said "I'm Electron, you see!"
But websites just frowned and turned it away with glee.
Now Chrome is the mask that the partition shall wear,
No Electron tokens left lurking in there.
One guard, one rewrite — the UA is clean!
The web sees plain Chrome where Electron had been. 🎉

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title directly describes the main change: configuring the embedded browser with a Chrome-style user-agent that removes Electron/app tokens.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The pull request description comprehensively covers all required template sections including summary, rationale, related issues, human review status, review focus, risk notes, verification steps, and a complete checklist.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/browser-ua

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to rewrite the default Electron user-agent string into a clean, standard Chrome user-agent for the embedded browser's shared partition. This is achieved by stripping out Electron-specific and application-specific tokens and pinning the Chrome version to the reduced major.0.0.0 format, reducing the risk of anti-automation detection. Unit tests have been added to verify the parsing and rewriting logic. I have no feedback to provide as there are no review comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Astro-Han added a commit that referenced this pull request Jun 17, 2026
…dependency

Two review fixes on the parity doc:

- The embedded browser rejects file://, so "load the file" was not runnable.
  Serve the probe over a local HTTP server and open the same http://127.0.0.1
  URL in both browsers (same origin, apples to apples).
- The parity table records state that assumes #1343 (UA) and #1344
  (permissions) are applied; neither is on dev yet. Say so explicitly and note
  this PR should land after both — on its own it is a forward-looking baseline,
  not current dev behavior.
…ents

Review follow-ups (UA rewrite behavior unchanged):

- Add configurePartitionUserAgent(session, chromeVersion) in the pure
  user-agent.ts (no electron import) as the seam the controller calls on the
  real partition session before the first view is created. This makes the
  wiring testable without an Electron runtime — added a test asserting the
  partition session receives the cleaned Chrome UA (no Electron/app token).
- Trim the long stealth rationale from the production comments in user-agent.ts
  and controller.ts down to the invariant (faithful Chrome UA; configured before
  the first view/request); the full rationale lives in the PR description.
Astro-Han added a commit that referenced this pull request Jun 17, 2026
Codex: the doc claimed #1343/#1344 are "not on dev yet", which goes false the
moment this PR lands in the described order. State the dependency (the baseline
holds only with both changes applied) instead of the transient branch state; the
merge-order instruction stays in the PR body.
@Astro-Han
Astro-Han merged commit 51c33a8 into dev Jun 17, 2026
37 checks passed
@Astro-Han
Astro-Han deleted the claude/browser-ua branch June 17, 2026 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request P0 Blocking / highest priority platform Electron shell, OS integration, packaging, updater, signing, paths, and permissions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant