Repository navigation
fix(browser): give a tab's identity one owner so viewport presets stop dropping client hints - #23718
Conversation
…p dropping client hints A desktop viewport preset installed a CDP user-agent override with no userAgentMetadata. Chromium then drops navigator.userAgentData and every sec-ch-ua header for that tab: a Chrome UA with no client hints. Identity was decided separately by the session request hook, the Google sign-in switch and the viewport code, and nothing decided per tab who it should claim to be. resolveBrowserTabIdentity now derives it from the process identity mode, whether the URL is a Google auth host, and whether a mobile preset is requested. applyTabIdentity is the one writer: it keeps the WebContents UA on the process or Firefox identity and clears the CDP override whenever that layer already presents the identity. Viewport emulation only records the requested preset; its metrics and touch steps log failures independently, so a rejected step can no longer skip the identity restore.
…f the tab identity A same-document navigation (pushState/replaceState) now never rewrites the WebContents user agent. Chromium reloads a still-loading document when its user agent changes, so an OAuth callback that strips its code with replaceState after a redirect off Google sign-in was requested twice, replaying the one-time code. Measured on Electron 43.7.5: the callback URL hits the server twice with the write, once without. The session request hook now derives the mobile identity from the CDP override the tab actually holds instead of the requested preset. A preset whose write never landed (debugger attach refused while DevTools is open, a failed write, a detach) no longer puts the iPhone user agent and mobile client hints on the wire while the document reports desktop.
…ading the error page did-fail-load fires while the failed URL's error page is still loading, and WebContents.setUserAgent() at that moment makes Chromium reload it. After a redirect onto or off the Google sign-in host (identity moved over CDP only), the restore rewrote the WebContents UA there and replayed the failed request. The restore now goes over CDP; the next navigation rewrites the WebContents UA.
…user agent Two review rounds each found a caller that asked the identity writer to rewrite the WebContents UA at a moment Chromium reloads or cancels the page (a same-document navigation, a failed load). A boolean at every call site left that decision to the callers. The writer now has two entry points: presentTabIdentityAtNavigationStart, the only one that may write the WebContents UA and only for a cross-document navigation, and retargetTabIdentity, which goes over CDP only and serves redirects, failed loads and preset changes. A table test pins the rule for every entry point.
…entity-restore test The mock rejected only maxTouchPoints 0, so the test would stop exercising a failed touch step once the touch payload is fixed.
|
Status: ready for review. Head
|
|
| // Why: identity is not an emulation step. It follows the requested preset whatever the steps | ||
| // above did, so a failed metrics or touch write can never strand a mobile identity on the tab. | ||
| const identityApplied = await this.runViewportEmulationStep(browserTabId, 'identity', () => | ||
| this.retargetTabIdentity(guest, this.resolveTabNavigationUrl(guest)) | ||
| ) |
There was a problem hiding this comment.
Mobile identity survives metrics failure
When a mobile preset's device-metrics command fails, this still applies the iPhone user agent and iOS client hints. The tab then identifies as a phone while retaining a desktop viewport. The call returns false, but the renderer callers ignore that result, so the mismatch persists until another preset change. Keep the mobile identity tied to successful metrics application, or restore a consistent identity on failure.
Knowledge Base Used: Restore Chrome-shaped browser identity
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (23)
💤 Files with no reviewable changes (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughThe browser now resolves process, Google-auth, and mobile tab identities through a shared module. Request headers and navigation handling use those identities, with tracked CDP user-agent overrides. Viewport preset state now records the requested override and updates tab identity alongside device metrics and touch emulation. Tests cover identity selection, navigation changes, preset ownership, and override failures. Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to This change routes browser-tab identity through one resolver shared by request headers, navigation, and viewport presets. Desktop presets now keep Chromium's default client hints, and mobile presets present a matching mobile identity. The review found no outstanding defects, and the change looks ready to merge. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change coordinates what a tab presents to pages with what it sends in requests. The reviewed paths retain per-tab ownership and navigation controls, and no newly introduced security bypass was established. Identity behavior during a failed sign-in redirect remains a limited uncertainty. Retained concerns Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 2 | ❌ 3❌ Failed checks (3 warnings)
✅ Passed checks (2 passed)
Full details: Linked Issues checkExplanation The directly linked issue [ Full details: Out of Scope Changes checkExplanation The PR adds a broad browser-tab identity and client-hint refactor, Google-auth identity handling, CDP override ownership, and related tests. The directly linked issue [ Resolution Remove the identity, client-hint, and Google-auth changes that are not required by the hover fix, or link them to an active coding requirement that directly requires this work. Keep only changes that implement the hover restoration and its regression tests.
✨ Finishing Touches 💡 1📝 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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Identity gets one owner. New
browser-tab-identity.tsderivesprocess/google-auth/mobilefrom(url, mobile preset, process identity); the session request hook and the guest writer both call it, so "desktop preset equals no preset" holds by construction. - Two named entry points replace the per-call-site flags.
presentTabIdentityAtNavigationStartis the onlysetUserAgentwriter (synchronously at cross-documentdid-start-navigation);retargetTabIdentityhandles redirects, failed loads and preset changes over CDP only. - Hint-less overrides are cleared, not restated.
writeTabIdentityOverrideclears the CDP override whenever the WebContents UA already presents the identity, so Chromium's own client hints come back; a mobile preset keeps its metadata-carrying override. - Wire follows the standing override. The request hook reads
mobilefrom what the tab actually holds, not the requested preset, so the wire matches the rendered document even when a preset never applied. - Viewport emulation steps are independent. Metrics/touch/identity each log their own failure and can no longer skip the identity step;
viewportPresetByTabIdrecords the request before CDP runs. - Removed/renamed substrate.
browser-viewport-user-agent.tsdeleted,AuthUserAgentOverride*→CdpUserAgentOverride*,viewportUaOverrideMobileByTabIdfolded into the preset record; tests reworked across eight files.
Verified: all changed/new browser suites pass locally (8 files, 117 tests), including the new browser-manager-tab-identity.test.ts (25) and browser-tab-identity.test.ts (6). I also confirmed the CDP premises against Chromium source: empty userAgent clears the override and restores the process UA plus native hints; an override with no userAgentMetadata drops navigator.userAgentData and sec-ch-ua*; later-issued CDP writes win; and setUserAgent is only reload/cancel-safe inside the cross-document did-start-navigation window.
ℹ️ The hint-less process override outlives its comment
On a server redirect off a Google sign-in host after a direct load, writeTabIdentityOverride cannot rewrite the WebContents UA (it would cancel the redirect) and cannot clear the override (it would expose the stale Firefox UA), so it writes the process UA with no userAgentMetadata. The inline comment says the next cross-document navigation clears it, which is correct — but in-page (same-document) navigations and viewport preset toggles re-write the same hint-less override rather than heal it. A single-page landing document that never starts another cross-document navigation therefore sits on a Chrome user agent with empty navigator.userAgentData and no sec-ch-ua* for its whole lifetime — the exact tell this PR exists to remove. This is still strictly better than main (which left the wire and the document disagreeing permanently), and the only safe heal is a cross-document navigation, so I read this as a follow-up rather than a merge blocker.
Technical details
# Hint-less process override lifetime
## Affected sites
- `src/main/browser/browser-manager-navigation.ts:129-131` — the `{ userAgent: identity.userAgent }` branch (no `userAgentMetadata`) when `presentedByWebContents !== identity.userAgent` and `kind !== 'mobile'`.
- `src/main/browser/browser-manager-navigation.ts:92` — same-document navigation skips the WebContents UA write, then still calls `writeTabIdentityOverride`, re-issuing the hint-less override.
- `src/main/browser/browser-manager-viewport.ts:171-173` — preset apply/clear resolves `identity=process` against the landing URL while the WebContents UA is still Firefox, so it too re-issues the same override.
## Reachable sequence
1. Direct navigation to `accounts.google.com` → `presentTabIdentityAtNavigationStart` sets the WebContents UA to Firefox.
2. The auth flow 302-redirects to the app callback on a non-Google host → `will-redirect` → `retargetTabIdentity` sees `identity.kind='process'`, `presentedByWebContents=Firefox` → hint-less process override.
3. `did-navigate` touches no identity state; only a later cross-document `did-start-navigation` rewrites the WebContents UA and clears the override.
The request hook stays consistent with the document during this state (both present Chrome without hints), so it is a client-hint loss, not a wire/document disagreement.
## Open question for the human
Is a follow-up wanted to make the transient carry synthesized desktop `userAgentMetadata` (as the mobile branch already does), or is the current "no invented desktop hints" decision final? The PR body says inventing desktop brands is "the same spoof shape", so this is recorded as a known limitation, not a requested change.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
Orca's built-in browser has "viewport size" presets (phone, tablet, laptop, desktop). Picking a desktop-sized preset was meant to change only the page size, but the code also rewrote who the browser says it is, in a way that removed part of that identity. Now only a phone or tablet preset changes the browser's identity; a desktop preset and "no preset" look exactly the same to websites.
What Changed
sec-ch-ua*request headers and emptiesnavigator.userAgentDatafor that tab, so the tab claims to be Chrome but sends none of Chrome's client hints. Bot checks such as Cloudflare Turnstile treat that combination as a spoof. Onmainthis path has never actually run: the touch-emulation call before it is rejected by Chromium on every desktop preset, and the failure silently skipped the user-agent step (which is also why leaving a phone preset kept the phone user agent). fix(browser): restore hover after leaving a mobile viewport preset #22846 fixes that touch call, which would switch the broken path on.resolveBrowserTabIdentity(inbrowser-tab-identity.ts) derives it from three inputs only: the process-wide identity mode, whether the URL is a Google sign-in host, and whether a mobile preset is requested. The session request hook and the guest writer both ask it. The guest writer has two entry points.presentTabIdentityAtNavigationStartis the only code that may set the WebContents user agent, and only synchronously at the start of a cross-document navigation, the one moment Chromium applies it to the new page without cancelling a redirect or reloading a loading page.retargetTabIdentityserves redirects, failed loads and preset changes over CDP only. Both clear the CDP user-agent override whenever the WebContents layer already presents the right identity, so no override without client-hint data is left standing. The request hook takes "mobile" from the override the tab actually holds, so the wire always matches what the page reports, even when a preset could not be applied (for example with DevTools open). Viewport emulation now only records the requested preset; its device-metrics and touch steps each log their own failure and can no longer skip the identity step.maindid on every redirect-based exit from sign-in, permanently.Why
Identity was written in three places (the session request hook, the Google sign-in switch, and the viewport code), and nothing decided per tab who the tab should claim to be. Each layer re-derived it, and the viewport layer derived it wrongly: a CDP user-agent override without client-hint data is not "the same identity", it is a different and self-contradictory one. Adding a guard to the desktop branch would have left three writers able to disagree again. With one owner, "desktop preset equals no preset" is true by construction, and the Google sign-in and mobile rules live in one function that every layer shares.
Alternatives considered: sending desktop client-hint data with the override (Orca cannot read Chromium's real brand list, so it would be invented data, the same spoof shape); keeping the desktop override but building it from the session UA (the missing client hints are the problem, not the UA string); and writing the WebContents user agent instead of CDP for presets (that write cancels in-flight navigations and cannot carry mobile client hints).
The desktop override was added to keep Electron and app tokens off the wire when a preset is reset (STA-7147). Measured on Electron 43.7.5: clearing the override restores the process identity exactly, with no Electron/Orca tokens in clean mode and with Chromium's client hints back, because the process identity is fixed before startup (#20767). So the override bought nothing and cost the client hints.
Unblocks #22846 (restoring hover after leaving a phone preset): #22846 makes the touch call succeed, which would have made the hint-dropping desktop override live. This PR should land first, then #22846.
Linked Issue
No separate issue. Prerequisite for #22846 (which fixes #22749).
Visual Proof
Live QA on a separate Mac (M4 Air), in a development build with an isolated profile. Presets were applied through the real Browser menu → Viewport Size. A local echo page prints
navigator.userAgent,navigator.userAgentData, and the headers its own follow-up request actually sent. Three builds:main+ #22846 (before), this PR at7f61218alone, and this PR + #22846 applied locally at87d48e0(never pushed;7f61218only restructures87d48e0without changing behaviour, and the PR-alone build gave identical results at both).main+ #22846sec-ch-uapresentsec-ch-ua*header ABSENT,userAgentData.brandsempty?1,"iOS"sec-ch-uapresent, brands present?1,"iOS",userAgentData.mobiletrueNo build showed an
Electron/orOrcatoken in any user agent, and the request header always matchednavigator.userAgent.Before (
main+ #22846), Laptop L: the client hints are gone.After (this PR), Default and Laptop L present the same identity.
After, Mobile M, then back to Laptop L and Default.
This PR + #22846, back to Laptop L: identity restored and hover back.
Google sign-in page under Laptop L: Firefox user agent. Unchanged from
main: on this pagenavigator.userAgentDatastill reports Chromium's brands next to the Firefox user agent, because the WebContents user agent write keeps Chromium's client-hint data; the requests Google receives carry the Firefox user agent with nosec-ch-ua*. Sign-in entered through a server redirect was verified in standalone Electron probes and unit tests, not in a live Orca session.Cloudflare check under Laptop L. dash.cloudflare.com/login showed no challenge in any build. The only challenge page found uses Cloudflare's always-interactive test key, which shows a checkbox for every browser, so it cannot tell identities apart; nothing was clicked. This check is inconclusive, not a pass.
Testing
browser-manager-tab-identity.test.ts(new): for clean and native mode, on an ordinary host and a Google sign-in host, checks that a desktop preset and no preset present exactly the same identity, that no override without client-hint data stands, that a mobile preset presents the mobile identity with mobile client hints, that switching from mobile to desktop or none restores the process identity, that clean mode never shows Electron/Orca tokens, and that a rejected touch-emulation step (as Chromium rejects it onmain) still restores identity and logs the failure.An entry-point table test checks that only a cross-document navigation start writes the WebContents user agent, not a redirect, a failed load or a preset change; it goes red if the CDP-only path writes it or if the write is deferred past the navigation event. A separate test covers same-document navigations (
replaceStateon a sign-in callback page) and goes red if they are not excluded.Each identity mechanism was ablated at the final head and turned the four identity suites red: restating the process identity as a hint-less override (22 failures), always clearing even over a stale Firefox WebContents user agent (13), having the request hook read the requested preset instead of the override the tab holds (1), and skipping the identity step when touch emulation fails (1). On the first revision, never rewriting the WebContents user agent while an override stands also failed (5); that rule no longer exists as a separate branch.
Reworked existing tests, and why:
browser-manager-viewport-override.test.ts: tests that expected a desktop preset to write{ userAgent: <process UA> }now expect no write and assert what the tab presents; tests that raced a preset's UA write now use a mobile preset, because a desktop preset no longer writes anything to race; leaving an identity now expects a clear ('') instead of a hint-less restatement; override=null with nothing standing now expects no user-agent write, and a new case covers clearing a mobile identity.browser-manager-auth-user-agent.test.ts: leaving the sign-in host with a Firefox override standing now clears it; the next direct navigation now rewrites a stale Firefox WebContents user agent (previously it stayed Firefox for the life of the tab once an override existed).browser-manager-viewport-ownership.test.ts: the deleted mobile-intent map is replaced by the recorded preset; a failed clear now keeps the standing mobile override tracked (so navigation clears it) instead of re-asserting mobile intent; the serialized-toggle case no longer installs a mobile UA that the last request had already cancelled.browser-session-registry.test.tsand the env-gated Cloudflare probe: resolvers return a typed identity (kind) instead of a bare user agent.Standalone Electron 43.7.5 probes confirmed the Chromium behaviour this relies on: an override without client-hint data drops
sec-ch-uaandnavigator.userAgentData; clearing it restores the process identity with its hints and no Electron/Orca tokens; setting the WebContents user agent at a cross-document navigation start sends a GET or a form POST exactly once; setting it during a same-document navigation or after a failed load reloads the page.tc:nodetypecheck and the changed-code quality gate pass.I manually tested these changes locally (live QA on a separate Mac, see Visual Proof)
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Three independent review rounds plus an architecture review. They found and fixed three bugs in earlier revisions of this PR, none of which reached
main: a same-document navigation (replaceStateon a sign-in callback that was still loading) rewrote the WebContents user agent, which reloads the page and replays a one-time sign-in code; the request hook claimed a mobile identity for a preset that never applied (DevTools open); and the failed-load restore reloaded the error page. The architecture review traced all three to one pattern, a per-call-site flag deciding when the WebContents user agent may be written, and replaced it with the two named entry points described above. The final round found nothing.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Known and unchanged from
main: until fix(browser): restore hover after leaving a mobile viewport preset #22846 lands, every page load logs a "touch emulation failed" warning (Chromium rejects the current touch payload; this PR only stops that failure from skipping the identity step). A navigation that neither commits nor fails (a 204, a download, a stop) leaves the navigation-start user agent in place until the next navigation; that is a pre-existing gap and a follow-up.Security: no new surface; fewer CDP writes than before.
Cross-platform: the behaviour is Chromium's and the same on macOS, Linux and Windows.
SSH/remote: the embedded browser runs in the local app; remote workspaces are unaffected.
Mobile: not affected.
Backwards compatibility: no persisted state changes; the viewport preset record was already in memory only.
Performance: fewer CDP commands per preset change and per navigation.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)