Skip to content

fix(browser): give a tab's identity one owner so viewport presets stop dropping client hints - #23718

Merged
brennanb2025 merged 7 commits into
mainfrom
brennanb2025/browser-identity-viewport-ownership
Sep 29, 2026
Merged

brennanb2025 merged 7 commits into
mainfrom
brennanb2025/browser-identity-viewport-ownership

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​660 $\color{#cf222e}{\Huge{\mathbf{−}}}$​209 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​451
Prod 14 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​355 $\color{#cf222e}{\Huge{\mathbf{−}}}$​369 $\color{#cf222e}{\Huge{\mathbf{−}}}$​14

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

  • Before: choosing a desktop preset (or leaving a phone preset) told Chromium to override the user agent string without the matching client-hint data. Chromium then stops sending the sec-ch-ua* request headers and empties navigator.userAgentData for 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. On main this 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.
  • After: a desktop preset and "no preset" present the process identity untouched, with Chromium's own client hints. A phone/tablet preset presents the mobile user agent with matching mobile client hints, as before. Switching back from a phone preset restores the normal identity even when another emulation step fails. Google sign-in pages still get the Firefox identity (clean mode only), and native identity mode still presents Electron's own identity.
  • Mechanism: a tab's identity now has one owner. resolveBrowserTabIdentity (in browser-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. presentTabIdentityAtNavigationStart is 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. retargetTabIdentity serves 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.
  • The one case where clearing is not safe is a server redirect off a Google sign-in page after a direct load of it: the WebContents user agent still says Firefox, and rewriting it mid-redirect cancels the navigation. There the override carries the process user agent for that one document, and the next ordinary navigation restores the WebContents user agent and clears the override. That transient is what main did 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 at 7f61218 alone, and this PR + #22846 applied locally at 87d48e0 (never pushed; 7f61218 only restructures 87d48e0 without changing behaviour, and the PR-alone build gave identical results at both).

Build Default Laptop L (desktop) Mobile M Back to Laptop L / Default
main + #22846 Chrome UA, sec-ch-ua present same UA, every sec-ch-ua* header ABSENT, userAgentData.brands empty iPhone UA, ?1, "iOS" Laptop L loses hints again; Default restores
This PR Chrome UA, sec-ch-ua present, brands present byte-identical to Default iPhone UA, ?1, "iOS", userAgentData.mobile true identical to Default
This PR + #22846 same as this PR same as this PR same as this PR same as this PR, and hover returns

No build showed an Electron/ or Orca token in any user agent, and the request header always matched navigator.userAgent.

Before (main + #22846), Laptop L: the client hints are gone.

main plus 22846 with the Laptop L preset: every sec-ch-ua header absent and userAgentData brands empty

After (this PR), Default and Laptop L present the same identity.

this PR, Default: Chrome user agent with sec-ch-ua and userAgentData brands present

this PR, Laptop L in the Orca window: same user agent and client hints as Default

After, Mobile M, then back to Laptop L and Default.

this PR, Mobile M: iPhone user agent, sec-ch-ua-mobile ?1, platform iOS

this PR, back to Laptop L after mobile: desktop identity and client hints restored

this PR, back to Default after mobile: desktop identity and client hints restored

This PR + #22846, back to Laptop L: identity restored and hover back.

this PR plus 22846, Laptop L after mobile: client hints present, maxTouchPoints 0, hover true

Google sign-in page under Laptop L: Firefox user agent. Unchanged from main: on this page navigator.userAgentData still 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 no sec-ch-ua*. Sign-in entered through a server redirect was verified in standalone Electron probes and unit tests, not in a live Orca session.

accounts.google.com under Laptop L: navigator.userAgent is the Firefox user agent

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.

Cloudflare test-key challenge page showing the interactive checkbox, identical in every build

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 on main) 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 (replaceState on 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.ts and 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-ua and navigator.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:node typecheck 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 (replaceState on 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

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and 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

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

…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.
@brennanb2025
brennanb2025 marked this pull request as ready for review September 29, 2026 01:45
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Status: ready for review. Head 7077011, CI green (all 8 test shards, typecheck, static analysis, both package jobs).

  • Review: three independent review rounds plus an architecture review. Three bugs found in earlier revisions of this PR were fixed (a same-document navigation reloading a loading sign-in callback, headers claiming a mobile identity for a preset that never applied, a failed load reloading its error page); the architecture review then made navigation start the only place the WebContents user agent can be written. The final round found nothing.
  • Live QA on a separate Mac through the real Viewport Size menu: main + fix(browser): restore hover after leaving a mobile viewport preset #22846 drops every sec-ch-ua* header and empties navigator.userAgentData under a desktop preset; with this PR (alone, and with fix(browser): restore hover after leaving a mobile viewport preset #22846 applied locally) the desktop preset is byte-identical to Default with Chromium's client hints, the phone preset presents the iPhone identity with mobile hints, switching back restores it, no Electron/Orca tokens appear, and Google sign-in gets the Firefox user agent. Screenshots are in the description.
  • Cloudflare check: inconclusive, not a pass (no challenge on dash.cloudflare.com; the only challenge page found uses Cloudflare's always-interactive test key).
  • Order: this lands first, then fix(browser): restore hover after leaving a mobile viewport preset #22846. fix(browser): restore hover after leaving a mobile viewport preset #22846 now conflicts in browser-manager-viewport.ts and needs a rebase; its change reduces to the touch payload in the new touch step. Until it lands, each page load logs a "touch emulation failed" warning (behaviour unchanged, now visible).
  • Follow-ups, all pre-existing on main: a navigation that neither commits nor fails (204, download, stop) leaves the navigation-start user agent in place until the next navigation; on accounts.google.com the page's navigator.userAgentData still reports Chromium brands next to the Firefox user agent (the wire is consistent).

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Refactors browser tab identity and viewport preset ownership.

The PR should not merge until a failed mobile metrics command can no longer leave a desktop viewport presenting a mobile identity.

Findings

  1. P1 Mobile identity survives metrics failure ▶

Summary

The PR centralizes tab identity across the session request hook, WebContents, and CDP, and removes desktop-preset user-agent overrides that discard client hints.

  • Mobile identity remains applied when device-metrics emulation fails, leaving the tab with contradictory identity and viewport state.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  P[Requested viewport preset] --> M[CDP device metrics]
  P --> I[Tab identity resolver]
  M --> V[Page viewport]
  I --> C[CDP identity override]
  C --> U[Page user agent and client hints]
  M -. failure does not stop identity .-> I
Loading

Reviews (1) · Last reviewed commit: "test(browser): reject touch emulation re..."

Comment on lines +169 to +173
// 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))
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 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

@coderabbitai

coderabbitai Bot commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: b9288183-a019-4b3e-8d4a-d9c5a6001ded

📥 Commits

Reviewing files that changed from the base of the PR and between 9b11b1d and 7077011.

📒 Files selected for processing (23)
  • src/main/browser/browser-manager-auth-user-agent.test.ts
  • src/main/browser/browser-manager-bindings.ts
  • src/main/browser/browser-manager-guest-cleanup.ts
  • src/main/browser/browser-manager-guest-navigation-policy.ts
  • src/main/browser/browser-manager-guest-policy.ts
  • src/main/browser/browser-manager-navigation.ts
  • src/main/browser/browser-manager-registration.ts
  • src/main/browser/browser-manager-state.ts
  • src/main/browser/browser-manager-tab-identity.test.ts
  • src/main/browser/browser-manager-types.ts
  • src/main/browser/browser-manager-viewport-override.test.ts
  • src/main/browser/browser-manager-viewport-ownership.test.ts
  • src/main/browser/browser-manager-viewport-scroll-state.ts
  • src/main/browser/browser-manager-viewport-test-fixtures.ts
  • src/main/browser/browser-manager-viewport.ts
  • src/main/browser/browser-session-registry.test.ts
  • src/main/browser/browser-session-ua-cloudflare-live.electron.test.ts
  • src/main/browser/browser-session-ua.ts
  • src/main/browser/browser-tab-identity.test.ts
  • src/main/browser/browser-tab-identity.ts
  • src/main/browser/browser-viewport-user-agent.test.ts
  • src/main/browser/browser-viewport-user-agent.ts
  • tests/tools/google-signin-ua-probe.cjs
💤 Files with no reviewable changes (2)
  • src/main/browser/browser-viewport-user-agent.ts
  • src/main/browser/browser-viewport-user-agent.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 4 remain after this review.


📝 Walkthrough

Walkthrough

The 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 70770

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 Review

Security architecture risk: 🔵 Low · up to 70770

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The directly affected exposure is a browser guest and its requests. Requests without a guest ID do not inherit another tab's mobile preset; the reviewed paths do not establish a cross-tab or service-privilege expansion.

Security Findings and Attack Paths

  • inferred — A non-auth redirect can retain a previously confirmed Google-auth identity if its CDP retarget write fails: the request resolver accepts a standing Google-auth override without checking the pending URL. The base redirect path could also leave its Firefox override standing after a failed retarget, so the evidence does not establish this as a newly introduced security condition.

Trust Boundaries and Controls

  • observed — Redirects update the guest's pending URL before retargeting; the request resolver uses that URL for its current- and effective-user-agent Google-auth checks. Guest identity state is cleared on debugger detach and cleanup.

Resilience and Maintainability Implications

  • observed — A failed identity write returns failure and leaves the last confirmed override available to request resolution; it is not treated as a successfully applied new identity.

Hardening Proposals

  • proposed — Validate the wire and page identities across an auth-to-non-auth redirect when a CDP write fails, then define recovery that does not strand a stale sign-in identity or create a header-versus-page mismatch.
🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The directly linked issue [#22749] requires hover effects to continue working after switching from a mobile or tablet preset to a desktop preset or no preset. The reviewed code separates metrics, touc… Implement the hover restoration behavior in this PR, or include the complete change that makes hover work after mobile/tablet-to-desktop/default switches. Add an automated regression test for that sequence.
Out of Scope Changes check ⚠️ Warning 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 [#22749] defines a hover-regressi… 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 …
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 20 functions across 21 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: centralizing tab identity ownership so viewport presets preserve client hints.
Description check ✅ Passed The description is detailed and covers the required explanation, behavior changes, rationale, testing, visual proof, review notes, compatibility considerations, and checklist. It references related is…
Full details: Linked Issues check

Explanation

The directly linked issue [#22749] requires hover effects to continue working after switching from a mobile or tablet preset to a desktop preset or no preset. The reviewed code separates metrics, touch, and identity steps, but it does not establish hover restoration. doSetViewportOverrideImpl still reports touch-emulation failures, and the PR summary states that the hover fix remains in #22846. The added tests cover user-agent identity and emulation command state, not the required post-switch hover behavior.

Full details: Out of Scope Changes check

Explanation

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 [#22749] defines a hover-regression objective. The reviewed implementation and tests target user-agent identity, client hints, Google auth, and override races instead of hover behavior. The summary also identifies a separate future PR for the hover fix. These changes therefore include demonstrated work outside the linked issue's coding scope.

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.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes

  • Identity gets one owner. New browser-tab-identity.ts derives process / google-auth / mobile from (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. presentTabIdentityAtNavigationStart is the only setUserAgent writer (synchronously at cross-document did-start-navigation); retargetTabIdentity handles redirects, failed loads and preset changes over CDP only.
  • Hint-less overrides are cleared, not restated. writeTabIdentityOverride clears 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 mobile from 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; viewportPresetByTabId records the request before CDP runs.
  • Removed/renamed substrate. browser-viewport-user-agent.ts deleted, AuthUserAgentOverride* → CdpUserAgentOverride*, viewportUaOverrideMobileByTabId folded 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.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

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.

[Bug]: Lose hover effects after switching browser viewport to mobile/tablet and back

1 participant