Repository navigation
fix(browser): a tab's phone identity follows the viewport actually applied - #23812
Conversation
|
Status: ready for review. Not merged; auto-merge is off. What this PR does. A built-in browser tab now presents an iPhone identity only while a phone viewport is actually applied. That holds in both directions when Chromium rejects the viewport resize, and after a debugger detach. This closes the Greptile P1 raised on #23718. Review loops
Verification
Unexpected behaviour for users: none introduced by this PR. Follow-ups (all predate this PR):
|
|
| if (metricsApplied) { | ||
| this.recordAppliedViewportOverride(browserTabId, webContentsId, override) |
There was a problem hiding this comment.
Detach can restore stale identity
If Chromium accepts a mobile metrics command and the debugger detaches before this awaiting operation resumes, the detach handler clears applied, but this write sets it back to mobile. Detaching has cleared the metrics, so the next navigation can reinstall an iPhone identity on a desktop viewport. The result needs to be guarded against a detach during the command.
|
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 (8)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughViewport preset state now records requested and successfully applied overrides separately. Mobile identity checks use the applied viewport state. Debugger detachment clears the recorded user-agent override and, when a tab is mapped, its applied viewport override. Tests cover failed preset changes, retries, navigation, and debugger detachment. Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to No merge-blocking issue is established for viewport preset identity; the change is mergeable after normal checks. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change is limited to embedded-browser tabs and reduces the chance that a site sees a phone identity with a desktop viewport, or the reverse. The review found no introduced security concern, though behavior under unusual Chromium failures remains difficult to verify. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 — a tab's phone identity now derives from the device-metrics override Chromium actually accepted, not the preset the user asked for.
- Dual viewport record:
viewportPresetByTabIdentries now carryrequested(written before CDP, drives host wheel panning) andapplied(written only after a successful metrics/clear step, drives identity).recordAppliedViewportOverrideis fenced onguestWebContentsId, so a stale or replacement guest cannot write onto the new owner's record. - Identity follows
applied:hasMobileViewportPresetbecomeshasMobileViewportApplied, soresolveGuestTabIdentity(and the page-load reapply) matches the viewport on screen in both directions — a failed phone apply stays desktop, a failed phone clear stays mobile while the phone viewport stands. - Detach handling:
trackDebuggerDetachForUserAgentOverridebecomestrackDebuggerDetachForCdpOverridesand clearsappliedtoo, since a detach clears device metrics along with the UA override.appliedis recorded before the touchawait, which makes the write atomic relative to the detach handler and closes the mid-switch detach case. - Tests: the contradictory
#23718case is replaced by five identity cases (failed apply both directions, detach, mid-apply detach) plus updated ownership-shape/ordering expectations.
I read the complete diff and the surrounding implementation (browser-manager-viewport.ts, browser-manager-navigation.ts, browser-manager-state.ts, browser-manager-registration.ts, browser-guest-wheel-zoom.ts), confirmed the only readers of the changed state are the identity resolver and isViewportPresetActive, and checked the invalidation sites (guest replacement/unregister delete the record). I also ran the two affected test files (41 passing) and ablated the fix by reverting hasMobileViewportApplied to read requested, which fails all five new identity cases — the tests genuinely pin the behavior rather than merely passing.
The known follow-ups (renderer ignores a false return so the menu can still show a failed preset; an identity-write failure after a successful clear; direct-metrics paths like orca browser viewport --mobile) are pre-existing and explicitly out of scope. Approval is conditional on nothing else landing; if commits do land, treat these line references as potentially stale.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
…3789, #23812, #23852) into brennanb2025/codex-home-single-writer #23744 moves every agent's folder pre-trust into the PTY spawn hook (and the structured Codex chat create), removing Codex's launch-prep and resume-prep trust writes. markCodexProjectTrusted now takes the config files to write. Conflicts: - agent-trust-presets.ts: #23744's configFiles signature and nested lane acquisition, with this branch's lane rationale (hook installs read and rewrite across awaits); main's "capture->restore window" wording described the grant snapshot this branch removed. - agent-trust-write-deadline.ts: the Codex writer waits only on managed-home installs' inline grant; the real-home background approval holds no lane. #23744's SSH/SFTP writer is gone, so it is no longer named; its 1.5 s short deadline is kept. - codex-trust-config-concurrent-launch.test.ts: this branch's tests (a launch's write lands while a grant session runs; the renamed sibling-failure case) with #23744's new call signature. Outside the conflicts: codex-launch-during-real-home-grant.test.ts passed launchAgent/workspacePath into launch prep, which #23744 removed; its launch helper now runs launch prep and then applyAgentWorkspaceTrust, as the spawn builder does, so it still proves a launch and its project trust land while the real-home approval hangs.
…the CDP override #23812's detach test called Orca's detach handler without clearing the fake's override, which passed only while the harness ignored the real header UA. Also guard requestIdentity with ?. now that the resolver can return nothing.

What this fixes. In Orca's built-in browser, a tab with a phone viewport preset (for example "Mobile M") could claim to be an iPhone while showing a desktop-sized page, or claim to be desktop Chrome while showing a phone-sized page. This happens only when Chromium rejects the command that resizes the page's emulated screen (the "device metrics" step). #23718 split the preset switch into independent steps so a failed step no longer strands the old identity, but its identity step followed the preset the user asked for, not the one that actually took effect. Greptile flagged this as a P1 on #23718 (comment).
Scope. Only the embedded browser's per-tab viewport presets (the Viewport Size menu, and the page-load reapply of a stored preset). Only when the device-metrics step fails, or the tab's debugger detaches (which clears Chromium's emulation). Normal preset switching, Google sign-in handling, native vs clean identity mode, popups, workers and the network-level user agent are unchanged. The touch-emulation payload is untouched (that is #22846). A post-merge audit of #23718 could not trigger the metrics failure in the running app, so this is hardening of a real code path rather than a fix for a commonly seen bug.
ELI5
When you pick a phone size for a browser tab, Orca does two things: it shrinks the page to a phone screen, and it tells websites "I'm an iPhone". If shrinking failed, Orca still said "I'm an iPhone" on a full-size page, which confuses sites and bot checks. Now Orca only says "I'm an iPhone" while the page really is phone-sized.
What Changed
User-facing: a tab's identity (iPhone vs your normal browser) now always matches the viewport you can actually see. If a phone preset fails to apply, the tab stays a normal desktop browser until the preset applies (the next page load re-sends it). If leaving a phone preset fails, the tab keeps presenting as an iPhone for as long as the phone viewport is still on screen, instead of claiming desktop on a phone-sized page.
Mechanism: the per-tab viewport record in the main process now holds two things, the preset that was requested and the device-metrics override Chromium actually accepted (
requestedandappliedinviewportPresetByTabId).appliedonly moves afterEmulation.setDeviceMetricsOverride/clearDeviceMetricsOverridesucceeds for the same guest, and it is recorded right after that step, before touch emulation runs, so a debugger detach arriving during the touch step cannot be overwritten. It is dropped when the tab's debugger detaches, because a detach clears Chromium's emulation. The identity owner (resolveBrowserTabIdentity, viahasMobileViewportApplied) readsapplied; host-side wheel panning keeps readingrequested, as before. The network request hook already follows the user-agent override Orca actually wrote, so it now follows the applied viewport too, without any change of its own.A side effect of the same rule: when presets are toggled rapidly, each applied viewport now gets its matching identity in turn (a phone viewport briefly presents as a phone before the next switch lands), where before the identity jumped straight to the last request even while an older viewport was still on screen.
Why
This holds the invariant "the identity a tab presents matches the viewport it is showing" by construction, in both directions, instead of adding a guard at the one failure site. Identity is derived from state Orca already has to track (what Chromium accepted), so there is no separate flag to keep in sync, and the record answers the next question too (which exact override is applied, not just "mobile or not").
Alternatives considered: (1) a standalone "mobile identity allowed" boolean set when metrics succeed. It answers only today's question and needs its own reset rules; the applied override carries the same fact plus the size. (2) Rolling back or retrying from the renderer when
setViewportOverridereturns false. The next page load already re-sends the stored preset, which re-applies metrics and then the identity, so retry adds UI state for a failure that could not be triggered live; left as a follow-up below. (3) Skipping the identity step when metrics fail. That breaks the phone to desktop failure case, where the identity must stay mobile because the phone viewport is still on screen.The #23718 test "still presents the requested mobile identity when device metrics fail" asserted the contradictory state (iPhone identity on a desktop viewport). It is replaced by tests that assert the opposite, plus tests for the reverse direction, a debugger detach, and a detach that lands in the middle of a preset switch. The #23718 ownership test for rapid toggles now expects the per-step identity writes described above.
Linked Issue
Follow-up to #23718 (Greptile P1 on that PR). No separate issue.
Visual Proof
Live check on a second Mac: a production build of this branch, driven through the same two calls the Viewport Size menu makes, observed from the main process and an HTTPS echo server. Every step matched the #23718 merge build exactly (same page UA,
navigator.userAgentData, request UA andsec-ch-ua*headers, iframe, dedicated worker and service worker) for none, Laptop L, Mobile M, Mobile M to Laptop L, Laptop L to none and Mobile M to none, in both clean and native identity modes, and for Google sign-in under each preset in clean mode (Firefox, no hints). The app logged 0 device-metrics failures and 0 identity-write failures; the only warnings were the known touch-emulation rejections that #22846 fixes.userAgentDatamobile / iOS with brands, 375 px, DPR 2userAgentDatadesktop / macOS with brands, 1440 pxuserAgentDatadesktop / macOS with brandsMobile M (the page prints its own
navigatorvalues):Mobile M, then Laptop L:
Laptop L:
No preset:
These show normal switching is unchanged. The changed path (device metrics failing) cannot be produced in the running app, so it has no before/after screenshot; the unit tests above carry it.
Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New unit tests in
browser-manager-tab-identity.test.ts(5 cases): a phone preset whose device metrics fail keeps the process identity on the page, in requests, and after the next navigation, and becomes mobile once the preset applies; phone to desktop and phone to no preset with metrics failing keep the mobile identity while the phone viewport stands, including after the next navigation; after a debugger detach the next navigation does not reinstall the mobile identity; a detach during the touch step of a phone switch does not leave a mobile identity to reinstall.Ablation: identity reading the requested preset again fails all 5; removing only the detach handling fails both detach tests; recording
appliedafter the touch step again fails only the mid-switch detach test.All 194 unit test files under
src/main/browserplussrc/main/ipc/browser*pass (1989 tests).pnpm tc:nodepasses; oxlint is clean on the changed files; the branch merges cleanly with fix(browser): restore hover after leaving a mobile viewport preset #22846.Live no-regression check on a second Mac (production build of this branch, hidden window, isolated profile, clean and native identity modes): see Visual Proof. The metrics failure itself cannot be triggered in the running app, so the unit tests carry it.
Review
Follow-ups, not in this PR (all predate it):
setViewportOverride(Viewport Size menu and the page-load reapply), so a failed preset still shows as selected, and host wheel panning follows it, until the next page load re-applies it. The identity is now consistent in that state; only the menu selection is misleading.orca browser viewport --mobilecommand and the phone screencast set device metrics directly, outside presets, so the tab's identity does not follow them (it did not before either).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
Security: no new surface; this only narrows when the mobile user agent is sent. Cross-platform: main-process state only, no platform-specific code. SSH/remote: the embedded browser runs locally; no wire changes. Mobile app: not affected. Backwards compatibility: in-memory state only, nothing persisted. Performance: one extra map write per successful metrics step.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)